Commit c8e57049 by Fred Smith

Merge pull request #1977 from edx/derf/locust_role

Locust role - initial commit
parents 2babf51f 6c916fa8
- name: Deploy Locust
hosts: all
sudo: True
gather_facts: True
roles:
- locust
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Defaults for role locust
#
#
# vars are namespace with the module name.
#
locust_service_name: "locust"
locust_home: "{{ COMMON_APP_DIR }}/{{ locust_service_name }}"
locust_user: "locust"
locust_code_dir: "{{ locust_home }}/load-tests"
locust_requirements_base: "{{ locust_code_dir }}/locust"
locust_requirements:
- "requirements.txt"
locust_run_dir: "{{ locust_code_dir }}/{{ LOCUST_LOADTEST_DIR }}"
LOCUST_GIT_IDENTITY: !!null
LOCUST_LOADTEST_REPO: 'load-tests'
LOCUST_LOADTEST_REPO_VERSION: 'master'
LOCUST_LOADTEST_DIR: 'locust/lms'
LOCUST_MASTER: !!null
LOCUST_TARGET_HOST: 'http://localhost/'
LOCUST_SERVICE_CONFIG: ''
LOCUST_REPOS:
- PROTOCOL: "ssh"
DOMAIN: "{{ COMMON_GIT_MIRROR }}"
PATH: "{{ COMMON_GIT_PATH }}"
REPO: "{{ LOCUST_LOADTEST_REPO }}"
VERSION: "{{ LOCUST_LOADTEST_REPO_VERSION }}"
DESTINATION: "{{ locust_code_dir }}"
SSH_KEY: "{{ LOCUST_GIT_IDENTITY }}"
#
# OS packages
#
locust_debian_pkgs: []
locust_redhat_pkgs: []
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Role includes for role locust
#
dependencies:
- role: edx_service
edx_service_name: "{{ locust_service_name }}"
edx_service_config: "{{ LOCUST_SERVICE_CONFIG }}"
edx_service_repos: "{{ LOCUST_REPOS }}"
edx_service_user: "{{ locust_user }}"
edx_service_home: "{{ locust_home }}"
edx_service_packages:
debian: "{{ locust_debian_pkgs }}"
redhat: "{{ locust_redhat_pkgs }}"
- supervisor
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role locust
#
# Overview:
# - Expects a load-tests repo that declares locust.io as a requirement
# - Installs load-tests repo using standard edx service roles
# - configures locust with defaults in supervisor
#
# Dependencies:
# - edx-service role
# - load tests repo with locust tests in it.
#
# Example play:
#
# # To run: ansible-playbook locust.yml -i "locustmaster.m.sandbox.edx.org," -e "LOCUST_LOADTEST_DIR='locust/lms'" -e "LOCUST_TARGET_HOST='https://courses-loadtest.edx.org'" -e "@/Users/derf/workspace/sandbox-secure/ansible/vars/developer-sandbox.yml"
# - name: Deploy Locust
# hosts: all
# sudo: True
# gather_facts: True
# roles:
# - locust
- name: install application requirements
pip: >
requirements="{{ locust_requirements_base }}/{{ item }}"
virtualenv="{{ locust_home }}/venvs/{{ locust_service_name }}"
state=present
sudo_user: "{{ locust_user }}"
with_items: locust_requirements
- name: write supervisord config
template: >
src=edx/app/supervisor/conf.d.available/locust.conf.j2
dest="{{ supervisor_available_dir }}/{{ locust_service_name }}.conf"
owner={{ supervisor_user }} group={{ common_web_user }} mode=0644
- name: enable supervisor script
file: >
src={{ supervisor_available_dir }}/{{ locust_service_name }}.conf
dest={{ supervisor_cfg_dir }}/{{ locust_service_name }}.conf
state=link
force=yes
when: not disable_edx_services
- name: update supervisor configuration
shell: "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update"
when: not disable_edx_services
- name: restart the applicaton
supervisorctl_local: >
state=restarted
supervisorctl_path={{ supervisor_ctl }}
config={{ supervisor_cfg }}
name={{ locust_service_name }}
when: not disable_edx_services
sudo_user: "{{ supervisor_service_user }}"
#
# {{ ansible_managed }}
#
[program:{{ locust_service_name }}]
{% set locust_venv_bin = locust_home + "/venvs/" + locust_service_name + "/bin" %}
{% set executable = locust_venv_bin + '/locust' %}
{% if LOCUST_MASTER %}
{% set locust_extra_args = '--slave --master-host ' + LOCUST_MASTER %}
{% else %}
{% set locust_extra_args = '' %}
{% endif %}
command={{ executable }} --host {{ LOCUST_TARGET_HOST }} {{ locust_extra_args }}
user={{ common_web_user }}
directory={{ locust_run_dir }}
stdout_logfile={{ supervisor_log_dir }}/%(program_name)-stdout.log
stderr_logfile={{ supervisor_log_dir }}/%(program_name)-stderr.log
killasgroup=true
stopasgroup=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment