Commit 4c69ad56 by Troy Sankey Committed by GitHub

Merge pull request #3726 from edx/pwnage101/update-locust-role

sync the locust role with edx-load-tests
parents 2cda75a6 42457e57
......@@ -17,21 +17,13 @@
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_requirements:
- "requirements.txt"
locust_run_dir: "{{ locust_code_dir }}/{{ LOCUST_LOADTEST_DIR }}"
locust_code_dir: "{{ locust_home }}/edx-load-tests"
locust_requirements_base: "{{ locust_code_dir }}/requirements"
LOCUST_GIT_IDENTITY: !!null
LOCUST_LOADTEST_REPO: 'load-tests'
LOCUST_LOADTEST_REPO: 'edx-load-tests'
LOCUST_LOADTEST_REPO_VERSION: 'master'
LOCUST_LOADTEST_DIR: 'locust/lms'
LOCUST_MASTER: !!null
LOCUST_TARGET_HOST: 'http://localhost/'
LOCUST_SERVICE_CONFIG: ''
......
......@@ -12,7 +12,6 @@
#
dependencies:
- common
- supervisor
- role: edx_service
edx_service_name: "{{ locust_service_name }}"
edx_service_config: "{{ LOCUST_SERVICE_CONFIG }}"
......
......@@ -10,73 +10,75 @@
#
#
# 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
# - Expects an edx-load-tests repo that declares locust.io as a requirement
# - Installs edx-load-tests repo using standard edx service roles
# - Makes the locust user suitable for running an interactive shell
# - Adds a MOTD message for self-help resources related to loadtesting
#
# Dependencies:
# - edx-service role
# - load tests repo with locust tests in it.
#
#
# Example play:
#
# # To run: ansible-playbook locust.yml -i "locustmaster.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"
# # To run: ansible-playbook locust.yml -i "locustdriver.sandbox.edx.org," -e "@/Users/derf/workspace/sandbox-secure/ansible/vars/developer-sandbox.yml"
# - name: Deploy Locust
# hosts: all
# sudo: True
# become: True
# gather_facts: True
# roles:
# - locust
- name: Install system packages
apt:
pkg: "{{ item }}"
state: "present"
update_cache: true
cache_valid_time: 3600
with_items: "{{ locust_debian_pkgs }}"
- name: Install application requirements
- name: Install base requirements used by all load tests
pip:
requirements: "{{ locust_requirements_base }}/{{ item }}"
requirements: "{{ locust_requirements_base }}/base.txt"
virtualenv: "{{ locust_home }}/venvs/{{ locust_service_name }}"
state: present
become_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:
name: "{{ locust_service_name }}"
state: restarted
supervisorctl_path: "{{ supervisor_ctl }}"
config: "{{ supervisor_cfg }}"
when: not disable_edx_services
become_user: "{{ supervisor_service_user }}"
# Specifically, we are concerned about allowing as many open connections as
# possible, to simulate more locust clients.
- name: Increase file descriptor limit of the system (Session Logout and Login would be required)
lineinfile:
dest: "{{ ulimit_conf_file }}"
line: "{{ item.domain }} {{ item.type }} {{ item.item }} {{ item.value }}"
with_items: "{{ ulimit_config }}"
- name: Configure locust user with an interactive shell
user:
name: "{{ locust_user }}"
shell: /bin/bash
# This is a hack because we're not using .bash_aliases for its stated purpose.
# As of this writing, the script will activate a preinstalled virtualenv and
# change to the edx-load-tests directory.
- name: Hack .bash_aliases to make it more convenient to start loadtests
template:
src: locust_home/bash_aliases.j2
dest: "{{ locust_home }}/.bash_aliases"
owner: "{{ locust_user }}"
group: root
mode: '644'
- name: Setup a loadtest-specific MOTD
template:
src: etc/motd.tail.locust.j2
dest: /etc/motd.tail.locust
owner: root
group: root
mode: '644'
# the directory /etc/update-motd.d is a xenial-ism only
when: ansible_distribution_release == 'xenial'
- name: Add motd.tail.locust to update-motd.d
copy:
dest: "/etc/update-motd.d/76-motd-tail-locust"
content: "#!/bin/sh\necho\ncat /etc/motd.tail.locust\n"
force: true
owner: root
group: root
mode: "0755"
# the directory /etc/update-motd.d is a xenial-ism only
when: ansible_distribution_release == 'xenial'
#
# {{ 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
*******************************************************************
* Message regarding loadtests *
* *
* Start your loadtesting journey by switching to the locust user: *
* *
* sudo su locust *
* *
* Please consult the loadtest environment queue before running *
* load tests against our shared loadtest environment: *
* https://openedx.atlassian.net/wiki/x/B4M3AQ *
* *
* For troubleshooting or other help, see our documentation: *
* https://openedx.atlassian.net/wiki/x/-QEsAQ *
*******************************************************************
cd {{ locust_code_dir }}
source {{ locust_home }}/venvs/{{ locust_service_name }}/bin/activate
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