From 82c6dec4fa36022f8a834864db90a24911b7906c Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 16 Jul 2019 14:56:04 +1000 Subject: [PATCH] Disable cloud launcher cron job during CI This takes a similar approach to the extant ansible_cron_install_cron variable to disable the cron job for the cloud launcher when running under CI. If you happen to have your CI jobs when the cron job decides to fire, you end up with a harmless but confusing failed run of the cloud launcher (that has tried to contact real clouds) in the ARA results. Use the "disbaled" flag to ensure the cron job doesn't run. Using "disabled" means we can still check that the job was installed via testinfra however. Convert ansible_cron_install_cron to a similar method using disable, document the variable in the README and add a test for the run_all.sh script in crontab too. Change-Id: If4911a5fa4116130c39b5a9717d610867ada7eb1 --- playbooks/roles/ansible-cron/README.rst | 7 +++++++ playbooks/roles/ansible-cron/defaults/main.yaml | 2 +- playbooks/roles/ansible-cron/tasks/main.yaml | 2 +- playbooks/roles/cloud-launcher-cron/README.rst | 7 +++++++ playbooks/roles/cloud-launcher-cron/defaults/main.yaml | 1 + playbooks/roles/cloud-launcher-cron/tasks/main.yaml | 1 + playbooks/zuul/run-base.yaml | 3 ++- .../zuul/templates/host_vars/bridge.openstack.org.yaml.j2 | 4 +++- testinfra/test_bridge.py | 6 ++++++ 9 files changed, 29 insertions(+), 4 deletions(-) diff --git a/playbooks/roles/ansible-cron/README.rst b/playbooks/roles/ansible-cron/README.rst index bd8563dc32..75bf33379d 100644 --- a/playbooks/roles/ansible-cron/README.rst +++ b/playbooks/roles/ansible-cron/README.rst @@ -19,3 +19,10 @@ bridge.o.o and all hosts. .. zuul:rolevar:: weekday :default: * + + .. zuul:rolevar:: ansible_cron_disable_job + :default: false + + Disabled installed cron job. This is only useful for CI jobs + testing bridge.o.o so that the test host does not randomly run + the script during CI tests that fall during the interval. diff --git a/playbooks/roles/ansible-cron/defaults/main.yaml b/playbooks/roles/ansible-cron/defaults/main.yaml index 4d21c72b6c..b29615f20a 100644 --- a/playbooks/roles/ansible-cron/defaults/main.yaml +++ b/playbooks/roles/ansible-cron/defaults/main.yaml @@ -5,4 +5,4 @@ update_cron_interval: month: '*' weekday: '*' # Flag that can be set in tests to ensure cron is not run -ansible_cron_install_cron: true +ansible_cron_disable_job: false diff --git a/playbooks/roles/ansible-cron/tasks/main.yaml b/playbooks/roles/ansible-cron/tasks/main.yaml index 9e1735c49b..7cddd9f547 100644 --- a/playbooks/roles/ansible-cron/tasks/main.yaml +++ b/playbooks/roles/ansible-cron/tasks/main.yaml @@ -13,6 +13,7 @@ cron: name: run_all.sh state: present + disabled: "{{ ansible_cron_disable_job }}" # Note /var/run is ephemeral; so after a reboot we need to # ensure the lockfile dir is there before we run... job: 'mkdir -p /var/run/ansible; flock -n /var/run/ansible/run_all.lock bash /opt/system-config/run_all.sh -c >> /var/log/ansible/run_all_cron.log 2>&1' @@ -21,7 +22,6 @@ day: "{{ update_cron_interval.day }}" month: "{{ update_cron_interval.month }}" weekday: "{{ update_cron_interval.weekday }}" - when: ansible_cron_install_cron - name: Setup log rotation include_role: diff --git a/playbooks/roles/cloud-launcher-cron/README.rst b/playbooks/roles/cloud-launcher-cron/README.rst index 488efed0e6..9e1fe67919 100644 --- a/playbooks/roles/cloud-launcher-cron/README.rst +++ b/playbooks/roles/cloud-launcher-cron/README.rst @@ -24,3 +24,10 @@ with. .. zuul:rolevar:: weekday :default: * + + .. zuul:rolevar:: cloud_launcher_disable_job + :default: false + + Prevent installation of cron job. This is only useful for CI + jobs testing bridge.o.o so that the test host does not randomly + run the script during CI tests that fall during the interval. diff --git a/playbooks/roles/cloud-launcher-cron/defaults/main.yaml b/playbooks/roles/cloud-launcher-cron/defaults/main.yaml index 344859ba46..a07fb19855 100644 --- a/playbooks/roles/cloud-launcher-cron/defaults/main.yaml +++ b/playbooks/roles/cloud-launcher-cron/defaults/main.yaml @@ -4,3 +4,4 @@ cloud_launcher_cron_interval: day: '*' month: '*' weekday: '*' +cloud_launcher_disable_job: false \ No newline at end of file diff --git a/playbooks/roles/cloud-launcher-cron/tasks/main.yaml b/playbooks/roles/cloud-launcher-cron/tasks/main.yaml index a0edcc0544..fe2e885393 100644 --- a/playbooks/roles/cloud-launcher-cron/tasks/main.yaml +++ b/playbooks/roles/cloud-launcher-cron/tasks/main.yaml @@ -7,6 +7,7 @@ cron: name: run_cloud_launcher.sh state: present + disabled: "{{ cloud_launcher_disable_job }}" job: '/usr/bin/flock -n /var/run/ansible/run_cloud_launcher.lock /bin/bash /opt/system-config/run_cloud_launcher.sh -c >> /var/log/ansible/run_cloud_launcher_cron.log 2>&1' minute: "{{ cloud_launcher_cron_interval.minute }}" hour: "{{ cloud_launcher_cron_interval.hour }}" diff --git a/playbooks/zuul/run-base.yaml b/playbooks/zuul/run-base.yaml index 5964e93f8d..214eed680c 100644 --- a/playbooks/zuul/run-base.yaml +++ b/playbooks/zuul/run-base.yaml @@ -1,7 +1,8 @@ - import_playbook: ../bridge.yaml vars: root_rsa_key: "{{ lookup('file', zuul.executor.work_root + '/' + zuul.build + '_id_rsa') }}" - ansible_cron_install_cron: false + ansible_cron_disable_job: true + cloud_launcher_disable_job: true - hosts: bridge.openstack.org become: true diff --git a/playbooks/zuul/templates/host_vars/bridge.openstack.org.yaml.j2 b/playbooks/zuul/templates/host_vars/bridge.openstack.org.yaml.j2 index b14ce0022e..20d7e28c5d 100644 --- a/playbooks/zuul/templates/host_vars/bridge.openstack.org.yaml.j2 +++ b/playbooks/zuul/templates/host_vars/bridge.openstack.org.yaml.j2 @@ -65,4 +65,6 @@ clouds: openstackzuul_fortnebula_password: password openstackzuul_fortnebula_project_name: project gitea_kube_key: Z2l0ZWFfazhzX2tleQ== -ansible_cron_install_cron: false + +ansible_cron_disable_job: true +cloud_launcher_disable_job: true diff --git a/testinfra/test_bridge.py b/testinfra/test_bridge.py index b36a6247bd..0a8d4c7484 100644 --- a/testinfra/test_bridge.py +++ b/testinfra/test_bridge.py @@ -45,6 +45,12 @@ def test_openstacksdk_config(host): assert f.mode == 0o640 +def test_ansible_run_all_cron(host): + with host.sudo(): + crontab = host.check_output('crontab -l') + assert 'run_all.sh' in crontab + + def test_cloud_launcher_cron(host): with host.sudo(): crontab = host.check_output('crontab -l')