From 95ec867710e381ea1f3168b3ec945ad883d167b4 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Thu, 28 Mar 2024 22:46:49 +0000 Subject: [PATCH] Test job retries Signed-off-by: Fabricio Aguiar --- .../tests/run_failed_playbook/01-assert.yaml | 119 ++++++++++++++++++ .../01-run-absent-file.yaml | 17 +++ 2 files changed, 136 insertions(+) create mode 100644 tests/kuttl/tests/run_failed_playbook/01-assert.yaml create mode 100644 tests/kuttl/tests/run_failed_playbook/01-run-absent-file.yaml diff --git a/tests/kuttl/tests/run_failed_playbook/01-assert.yaml b/tests/kuttl/tests/run_failed_playbook/01-assert.yaml new file mode 100644 index 00000000..fcfec649 --- /dev/null +++ b/tests/kuttl/tests/run_failed_playbook/01-assert.yaml @@ -0,0 +1,119 @@ +# +# Check for: +# +# - 1 OpenStackAnsibleEE CR +# - 1 failed-play pod +# - 1 failed-play job +# - Correct output from ansible play +# +apiVersion: ansibleee.openstack.org/v1beta1 +kind: OpenStackAnsibleEE +metadata: + name: failed-play +spec: + name: openstackansibleee + play: | + - name: Execution failure + hosts: localhost + tasks: + - name: Copy absent file + ansible.builtin.shell: | + set -euxo pipefail + cp absent failed_op + preserveJobs: true +status: + JobStatus: Failed + conditions: + - message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed. + Check job logs' + reason: Error + severity: Warning + status: "False" + type: Ready + - message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed. + Check job logs' + reason: Error + severity: Warning + status: "False" + type: AnsibleExecutionJobReady +--- +apiVersion: v1 +kind: Pod +metadata: + generateName: failed-play- + labels: + app: openstackansibleee + job-name: failed-play +status: + phase: Failed +--- +apiVersion: batch/v1 +kind: Job +metadata: + labels: + app: openstackansibleee + job-name: failed-play + openstackansibleee_cr: failed-play + osaee: "true" + name: failed-play +spec: + backoffLimit: 6 + completionMode: NonIndexed + completions: 1 + parallelism: 1 + template: + metadata: + labels: + app: openstackansibleee + batch.kubernetes.io/job-name: failed-play + job-name: failed-play + openstackansibleee_cr: failed-play + osaee: "true" + spec: + containers: + - args: + - ansible-runner + - run + - /runner + - -p + - playbook.yaml + - -i + - failed-play + env: + - name: RUNNER_PLAYBOOK + value: |2+ + + - name: Execution failure + hosts: localhost + tasks: + - name: Copy absent file + ansible.builtin.shell: | + set -euxo pipefail + cp absent failed_op + + + - name: RUNNER_EXTRA_VARS + value: |2+ + + aaa: %!s(int=1) + bbb: %!s(int=2) + ccc: %!s(int=3) + + + envFrom: + - configMapRef: + name: openstack-aee-default-env + image: quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest + imagePullPolicy: Always + name: openstackansibleee + dnsPolicy: ClusterFirst + restartPolicy: Never + schedulerName: default-scheduler + terminationGracePeriodSeconds: 30 +status: + conditions: + - message: Job has reached the specified backoff limit + reason: BackoffLimitExceeded + status: "True" + type: Failed + failed: 7 diff --git a/tests/kuttl/tests/run_failed_playbook/01-run-absent-file.yaml b/tests/kuttl/tests/run_failed_playbook/01-run-absent-file.yaml new file mode 100644 index 00000000..c849824e --- /dev/null +++ b/tests/kuttl/tests/run_failed_playbook/01-run-absent-file.yaml @@ -0,0 +1,17 @@ +apiVersion: ansibleee.openstack.org/v1beta1 +kind: OpenStackAnsibleEE +metadata: + name: failed-play +spec: + play: | + - name: Execution failure + hosts: localhost + tasks: + - name: Copy absent file + ansible.builtin.shell: | + set -euxo pipefail + cp absent failed_op + extraVars: + aaa: 1 + ccc: 3 + bbb: 2