From: Kyr Shatskyy Date: Wed, 3 Oct 2018 14:29:36 +0000 (+0200) Subject: Add zypper support for teuthology role X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46f2443143499e526763a1536ca2ed71a8db649c;p=ceph-cm-ansible.git Add zypper support for teuthology role Signed-off-by: Kyr Shatskyy --- diff --git a/roles/teuthology/tasks/main.yml b/roles/teuthology/tasks/main.yml index 23c9ccd0..d5cdb28a 100644 --- a/roles/teuthology/tasks/main.yml +++ b/roles/teuthology/tasks/main.yml @@ -1,4 +1,7 @@ --- +- import_tasks: zypper_systems.yml + when: ansible_pkg_mgr == "zypper" + - import_tasks: apt_systems.yml when: ansible_pkg_mgr == "apt" @@ -17,6 +20,14 @@ tags: - config +- name: Ship /etc/init.d/teuthology-worker + template: + src: teuthology-worker.init + dest: /etc/init.d/teuthology-worker + mode: 0755 + tags: + - config + - name: Ship teuthology user's crontab update script template: src: update-crontab.sh diff --git a/roles/teuthology/tasks/setup_log_access.yml b/roles/teuthology/tasks/setup_log_access.yml index c04abe9d..95db9d6e 100644 --- a/roles/teuthology/tasks/setup_log_access.yml +++ b/roles/teuthology/tasks/setup_log_access.yml @@ -7,12 +7,12 @@ - name: Ship nginx config template: src: nginx.conf - dest: /etc/nginx/sites-available/test_logs + dest: "{{ nginx_available }}/test_logs.conf" - name: Enable nginx config file: - src: /etc/nginx/sites-available/test_logs - dest: /etc/nginx/sites-enabled/test_logs + src: "{{ nginx_available }}/test_logs.conf" + dest: "{{ nginx_enabled }}/test_logs.conf" state: link # Ignore errors in case service doesn't exist diff --git a/roles/teuthology/tasks/setup_users.yml b/roles/teuthology/tasks/setup_users.yml index f1642624..e0d3c51e 100644 --- a/roles/teuthology/tasks/setup_users.yml +++ b/roles/teuthology/tasks/setup_users.yml @@ -1,4 +1,12 @@ --- +- name: Create group + group: + name: "{{ item }}" + state: present + with_items: "{{ teuthology_users }}" + tags: + - user + - name: Create users user: name: "{{ item }}" diff --git a/roles/teuthology/tasks/zypper_systems.yml b/roles/teuthology/tasks/zypper_systems.yml new file mode 100644 index 00000000..b71cccf9 --- /dev/null +++ b/roles/teuthology/tasks/zypper_systems.yml @@ -0,0 +1,14 @@ +--- +- name: Include package type specific vars. + include_vars: "zypper_systems.yml" + tags: + - always + +- name: Install packages via zypper + zypper: + name: "{{ item }}" + state: latest + update_cache: yes + with_items: "{{ teuthology_extra_packages }}" + tags: + - packages diff --git a/roles/teuthology/templates/teuthology-worker.init b/roles/teuthology/templates/teuthology-worker.init new file mode 100644 index 00000000..590b4616 --- /dev/null +++ b/roles/teuthology/templates/teuthology-worker.init @@ -0,0 +1,166 @@ +#!/bin/bash +# +# Copyright (c) 2015 Red Hat, Inc. +# +# Author: Loic Dachary +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +### BEGIN INIT INFO +# Provides: teuthology +# Required-Start: $network $remote_fs $syslog beanstalkd nginx +# Required-Stop: $network $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: Start teuthology +### END INIT INFO + +export NWORKERS=20 + +[ -f /etc/default/teuthology ] && source /etc/default/teuthology + +user=${TEUTHOLOGY_USERNAME:-teuthworker} +export HOME=/home/$user +export WORKER_HOME=$HOME/src/teuthology_master +#/usr/share/nginx/html +export WORKER_ARCH=$HOME/archive + +[ -d $WORKER_ARCH ] || sudo -u $user mkdir -p $WORKER_ARCH + +function worker_pidfile() { + echo /var/run/teuthology-worker.$1.pid +} +function worker_logfile() { + echo /var/log/teuthology.${1}.log +} + +function stop_worker() { + wnum=$1 + wpidfile=$(worker_pidfile $wnum) + if [[ -f $wpidfile ]] ; then + wpid=$(cat $wpidfile) + echo Killing worker $wnum with pid=$wpid... + pkill -P $wpid + pkill $wpid + rm -f $wpidfile + fi +} + +function stop_workers() { + for i in $(seq 1 $NWORKERS) ; do + stop_worker $i + done +} + +function start_worker() { + local wlogfile=$1 + local wpidfile=$2 + local worklogs=/tmp/$user-logs + mkdir -p $worklogs && chown $user: $worklogs + su - -c " +cd /home/$user +source openrc.sh +cd $WORKER_HOME +export LC_ALL=C +virtualenv/bin/teuthology-worker --tube openstack -l $worklogs --archive-dir $WORKER_ARCH +" $user > $wlogfile 2>&1 & { + echo $! > $wpidfile + echo "Started worker with pid=$! see log $wlogfile" + } +} + +function rkill() { + local pid=$1 + for i in $(pgrep -P $pid) ; do + rkill $i + done + echo Killing process $pid + kill -9 $pid +} + +function stop_process() { + local pidfile=$1 + [[ -f $pidfile ]] && { + local pid=$(cat $pidfile) + rkill $pid + ps --no-headers $pid 2>&1 > /dev/null || rm $pidfile + } +} + +function start_workers() { + for i in $(seq 1 $NWORKERS) ; do + local wpidfile=$(worker_pidfile $i) + local wlogfile=$(worker_logfile $i) + [[ -f $wpidfile ]] && { + local wpid=$(cat $wpidfile) + ps --no-headers -p $wpid 2>&1 > /dev/null && { + echo Worker $i is already running with process $wpid + continue + } + } + start_worker $wlogfile $wpidfile + done +} +echo $1 +case $1 in + start-workers) + start_workers + ;; + list-workers) + for i in $(ls /var/run | grep teuthology-worker | sort) ; do + WPID=$(cat /var/run/$i) + WORKER=${i##teuthology-worker.} + WORKER=${WORKER%%.pid} + STATUS=$(ps --no-headers -p $WPID 2>&1 > /dev/null && echo running || echo dead) + echo $WORKER PID:$WPID STATUS:$STATUS + done + ;; + stop-workers) + echo Stopping workers + stop_workers + ;; + stop-worker) + stop_worker $2 + ;; + restart-workers) + $0 stop-workers + $1 start-workers + ;; + start) + ( + cd /home/$user + source openrc.sh + cd teuthology + . virtualenv/bin/activate + teuthology-lock --list-targets --owner scheduled_$user@teuthology > /tmp/t + if test -s /tmp/t && ! grep -qq 'targets: {}' /tmp/t ; then + teuthology-lock --unlock -t /tmp/t --owner scheduled_$user@teuthology + fi + start_workers + ) + ;; + stop) + $0 stop-workers + ;; + restart) + $0 stop + $0 start + ;; + *) +esac diff --git a/roles/teuthology/templates/teuthology.yaml b/roles/teuthology/templates/teuthology.yaml index ee12f4c0..0c54010f 100644 --- a/roles/teuthology/templates/teuthology.yaml +++ b/roles/teuthology/templates/teuthology.yaml @@ -4,7 +4,7 @@ results_server: {{ paddles_address }} results_ui_server: {{ pulpito_address }} results_email: {{ teuthology_results_email|default('null') }} results_sending_email: {{ teuthology_results_sending_email|default('null') }} -lab_domain: {{ lab_domain }} +lab_domain: {{ lab_domain|default('teuthology') }} default_machine_type: {{ teuthology_default_machine_type|default('null') }} max_job_time: {{ teuthology_max_job_time|default(129600) }} {{ teuthology_yaml_extra }} diff --git a/roles/teuthology/vars/apt_systems.yml b/roles/teuthology/vars/apt_systems.yml index 878bef13..e8c03cf4 100644 --- a/roles/teuthology/vars/apt_systems.yml +++ b/roles/teuthology/vars/apt_systems.yml @@ -20,3 +20,5 @@ teuthology_extra_packages: - nginx apache_service: apache2 +nginx_available: "/etc/nginx/sites-available" +nginx_enabled: "/etc/nginx/sites-enabled" diff --git a/roles/teuthology/vars/zypper_systems.yml b/roles/teuthology/vars/zypper_systems.yml new file mode 100644 index 00000000..280a260c --- /dev/null +++ b/roles/teuthology/vars/zypper_systems.yml @@ -0,0 +1,22 @@ +--- +teuthology_extra_packages: + - beanstalkd + - git + - gcc + - libev-devel + - libffi48-devel + - libmysqlclient-devel + - libopenssl-devel + - libvirt-devel + - libvirt-python + - libyaml-devel + - lsb-release + - nginx + - python-devel + - python-pip + - python-virtualenv + - qemu-tools + +#apache_service: apache2 +nginx_available: "/etc/nginx" +nginx_enabled: "/etc/nginx/vhosts.d"