feat: install and launch locust

This commit is contained in:
Aravinth Manivannan 2023-08-17 05:06:08 +05:30
parent 1b2a653ea9
commit 83a1421314
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 201 additions and 0 deletions

View file

@ -8,11 +8,74 @@ define ping
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/ping.yml
endef
define configure_base
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/playbook.yml
endef
define configure_locust
. ./venv/bin/activate && \
ansible-playbook -i $(INVENTORY) -f 10 ./ansible/locust/main.yml
endef
define test_base
. ./venv/bin/activate && \
cd tests/ && \
pwd && \
py.test --hosts='ansible://all' \
-n 10 \
--verbose \
--ansible-inventory="../${INVENTORY}" \
test_basic.py
endef
define test_locust
. ./venv/bin/activate && \
cd tests/locust/ && \
py.test --hosts='ansible://mcaptcha_dos*' \
-n 10 \
--verbose \
--ansible-inventory="../../${INVENTORY}" \
base.py
endef
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.base
# ```
conf.base: ## Get all VMs to base level configuration
$(call configure_base)
lint: ## Lint source code
terraform fmt
. ./venv/bin/activate && \
ansible-lint --write $(find ansible -type f)
. ./venv/bin/activate && black tests/
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.base
# ```
conf.dos: ## Configure all DoS VMs
$(call configure_base)
$(call configure_locust)
# ```bash
# INVENTORY=./terraform/dos/hosts.ini make conf.ping
# ```
conf.ping: ## Ping all DoS VMs
$(call ping)
test: ## Run all tests
$(call test_base)
$(call test_locust)
test.base: ## Test base configuration on all VMs
$(call test_base)
help: ## Prints help for targets with comments
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-].+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

View file

@ -0,0 +1,23 @@
---
version: "3"
services:
master:
image: realaravinth/mcaptcha-dos-locust-protected:latest
container_name: master.locust.thrasher.dos.mcaptcha.org
environment:
- MCAPTCHA_CAPTCHA_SITEKEY=dPGVlwxjyPQJS5OEp86gzNJsxbrMlXwQ
- MCAPTCHA_CAPTCHA_HOST=http://localhost:7000
- HOST=http://localhost:5000
ports:
- 8089:8089
volumes:
- ./data/:/src/data
command: --master -H http://localhost:8089
worker:
image: realaravinth/mcaptcha-dos-locust-protected:latest
network_mode: host
environment:
- MCAPTCHA_CAPTCHA_SITEKEY=dPGVlwxjyPQJS5OEp86gzNJsxbrMlXwQ
- MCAPTCHA_CAPTCHA_HOST=http://localhost:7000
- HOST=http://localhost:5000
command: --worker --master-host localhost

42
ansible/locust/main.yml Normal file
View file

@ -0,0 +1,42 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
- name: Configure Locust instances
hosts: [mcaptcha_dos]
remote_user: atm
pre_tasks:
- name: Ensure all VMs are reachable
ansible.builtin.ping:
roles:
- docker-compose
tasks:
- name: Allow port 8089 for locust
become: true
community.general.ufw:
state: enabled
rule: allow
proto: tcp
port: "8089"
- name: Create projects dir
become: true
ansible.builtin.file:
path: /etc/locust
state: directory
mode: "0755"
- name: Copy docker-compose.yml file
become: true
ansible.builtin.copy:
src: ./artifacts/docker-compose.yml
dest: /etc/locust/
- name: Start locust services
become: true
community.docker.docker_compose:
project_src: /etc/locust/
scale:
worker: 4

View file

@ -0,0 +1,7 @@
---
- name: Install docker-compose
become: true
ansible.builtin.apt:
update_cache: true
pkg:
- docker-compose

View file

@ -221,3 +221,69 @@ yt-dlp==2023.7.6
zipp==3.16.2
zope.event==5.0
zope.interface==6.0
ansible==8.1.0
ansible-compat==4.1.6
ansible-core==2.15.1
ansible-lint==6.17.2
astroid==2.15.6
attrs==23.1.0
black==23.7.0
bracex==2.3.post1
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.2.0
click==8.1.6
contextvars==2.4
cryptography==41.0.2
dill==0.3.7
distro==1.8.0
execnet==2.0.2
filelock==3.12.2
gitdb==4.0.10
GitPython==3.1.32
idna==3.4
immutables==0.19
iniconfig==2.0.0
isort==5.12.0
Jinja2==3.1.2
jmespath==1.0.1
jsonschema==4.19.0
jsonschema-specifications==2023.7.1
lazy-object-proxy==1.9.0
lint==1.2.1
looseversion==1.3.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mccabe==0.7.0
mdurl==0.1.2
msgpack==1.0.5
mypy-extensions==1.0.0
packaging==23.1
pathspec==0.11.2
platformdirs==3.10.0
pluggy==1.2.0
psutil==5.9.5
pycparser==2.21
pycryptodomex==3.18.0
Pygments==2.16.1
pylint==2.17.5
pytest==7.4.0
pytest-testinfra==8.1.0
pytest-xdist==3.3.1
PyYAML==6.0
pyzmq==25.0.2
referencing==0.30.2
requests==2.31.0
resolvelib==1.0.1
rich==13.5.2
rpds-py==0.9.2
ruamel.yaml==0.17.32
ruamel.yaml.clib==0.2.7
salt==3006.1
smmap==5.0.0
subprocess-tee==0.4.1
tomlkit==0.12.1
urllib3==2.0.3
wcmatch==8.4.1
wrapt==1.15.0
yamllint==1.32.0