]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
teuthology: Script to keep teuthology user's crontab up to date 391/head
authorDavid Galloway <dgallowa@redhat.com>
Tue, 27 Mar 2018 18:59:49 +0000 (14:59 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Mon, 2 Apr 2018 20:10:55 +0000 (16:10 -0400)
Fixes: https://tracker.ceph.com/issues/23441
Signed-off-by: David Galloway <dgallowa@redhat.com>
roles/teuthology/README.rst
roles/teuthology/defaults/main.yml
roles/teuthology/tasks/main.yml
roles/teuthology/templates/update-crontab.sh [new file with mode: 0755]

index e0013530fb062e1b67721ffbf52e9e68c5125078..8d5145f0fe2f08f9864958829dc14962d1f604c2 100644 (file)
@@ -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``
index 51e6454bffd58f91b7b5ab80acd1a1dd3531bd76..a3fe5706c8f41fc6daeeeec6e36ffaf403721224 100644 (file)
@@ -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"
index c0747434e8aece4e753e066c7dbb9b8bc04dcff0..23c9ccd0370104fb2d00aa665b7766c216dc3762 100644 (file)
   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 (executable)
index 0000000..7635649
--- /dev/null
@@ -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