From: David Galloway Date: Tue, 27 Mar 2018 18:59:49 +0000 (-0400) Subject: teuthology: Script to keep teuthology user's crontab up to date X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F391%2Fhead;p=ceph-cm-ansible.git teuthology: Script to keep teuthology user's crontab up to date Fixes: https://tracker.ceph.com/issues/23441 Signed-off-by: David Galloway --- diff --git a/roles/teuthology/README.rst b/roles/teuthology/README.rst index e0013530..8d5145f0 100644 --- a/roles/teuthology/README.rst +++ b/roles/teuthology/README.rst @@ -14,9 +14,9 @@ It also does the following: - Clone ``teuthology`` repos into ``~/src/teuthology_master`` under those user accounts - Run ``teuthology``'s ``bootstrap`` script - Manages user accounts and sudo privileges using the ``test_admins`` group_var in the secrets repo +- Includes a script to keep the ``teuthology`` user's crontab up to date with remote version-controlled versions (``--tags="crontab") It currently does NOT do these things: -- Manage crontab entries - Manage ``teuthology-worker`` processes - Run ``teuthology-nuke --stale`` diff --git a/roles/teuthology/defaults/main.yml b/roles/teuthology/defaults/main.yml index 51e6454b..a3fe5706 100644 --- a/roles/teuthology/defaults/main.yml +++ b/roles/teuthology/defaults/main.yml @@ -7,3 +7,5 @@ teuthology_users: teuthology_repo: https://github.com/ceph/teuthology.git teuthology_yaml_extra: "" + +remote_crontab_url: "https://raw.githubusercontent.com/ceph/ceph/master/qa/crontab/teuthology-cronjobs" diff --git a/roles/teuthology/tasks/main.yml b/roles/teuthology/tasks/main.yml index c0747434..23c9ccd0 100644 --- a/roles/teuthology/tasks/main.yml +++ b/roles/teuthology/tasks/main.yml @@ -17,6 +17,16 @@ tags: - config +- name: Ship teuthology user's crontab update script + template: + src: update-crontab.sh + dest: /home/teuthology/bin/update-crontab.sh + mode: 0775 + owner: teuthology + group: teuthology + tags: + - crontab + # Serve logs over HTTP - import_tasks: setup_log_access.yml tags: diff --git a/roles/teuthology/templates/update-crontab.sh b/roles/teuthology/templates/update-crontab.sh new file mode 100755 index 00000000..76356496 --- /dev/null +++ b/roles/teuthology/templates/update-crontab.sh @@ -0,0 +1,49 @@ +#/bin/bash +# +# {{ ansible_managed }} +# +# Script to update teuthology user's crontab for scheduling suite runs + +REMOTE_CRONTAB_URL="{{ remote_crontab_url }}" +TEMP_DIR="$(mktemp -d /tmp/XXXXXXXX)" +CHKCRONTAB_PATH=~/bin/chkcrontab-venv + +# Output remote crontab to temp file +curl -s -o $TEMP_DIR/new $REMOTE_CRONTAB_URL > /dev/null + +# Output existing crontab +crontab -l > $TEMP_DIR/old + +# Check for differences +diff $TEMP_DIR/old $TEMP_DIR/new + +if [ $? -eq 0 ]; then + echo "No changes. Exiting." + exit 0 +fi + +# Install chkcrontab if needed +# https://pypi.python.org/pypi/chkcrontab +if ! [ -x ${CHKCRONTAB_PATH}/bin/chkcrontab ]; then + rm -rf $CHKCRONTAB_PATH + mkdir $CHKCRONTAB_PATH + virtualenv $CHKCRONTAB_PATH + source $CHKCRONTAB_PATH/bin/activate + pip install chkcrontab +else + source $CHKCRONTAB_PATH/bin/activate +fi + +# Perform the actual crontab syntax check +chkcrontab $TEMP_DIR/new + +if [ $? -eq 0 ]; then + # Install crontab + deactivate + crontab $TEMP_DIR/new + rm -rf $TEMP_DIR + echo "Installed new crontab successfully at $(date)" +else + echo "Checking crontab in $TEMP_DIR/new failed" + exit 1 +fi