diff --git a/ci_framework/playbooks/99-logs.yml b/ci_framework/playbooks/99-logs.yml index e97b30b698..647c71bb70 100644 --- a/ci_framework/playbooks/99-logs.yml +++ b/ci_framework/playbooks/99-logs.yml @@ -32,10 +32,6 @@ ansible.builtin.import_role: name: artifacts - - name: Run os_must_gather - ansible.builtin.import_role: - name: os_must_gather - - name: Ensure ansible.log is at the expected location register: ansible_log_state ansible.builtin.stat: diff --git a/ci_framework/roles/artifacts/README.md b/ci_framework/roles/artifacts/README.md index 4b7510af58..17fb15a34b 100644 --- a/ci_framework/roles/artifacts/README.md +++ b/ci_framework/roles/artifacts/README.md @@ -10,6 +10,7 @@ None - writes happen only in the user home. * `cifmw_artifacts_crc_host`: (String) Hostname of the CRC instance. Defaults to `api.crc.testing`. * `cifmw_artifacts_crc_user`: (String) Username to connect to the CRC instance. Defaults to `core`. * `cifmw_artifacts_crc_sshkey`: (String) Path to the private SSH key to connect to CRC. Defaults to `~/.crc/machines/crc/id_ecdsa`. +* `cifmw_artifacts_gather_logs`: (Boolean) Force gathering of logs, even in the case of successful test run. Defaults to `false` ## Examples Usually we'll import the role as-is at the very start of the playbook, and diff --git a/ci_framework/roles/artifacts/defaults/main.yml b/ci_framework/roles/artifacts/defaults/main.yml index 4d5e89bea7..3c7d2641ae 100644 --- a/ci_framework/roles/artifacts/defaults/main.yml +++ b/ci_framework/roles/artifacts/defaults/main.yml @@ -21,3 +21,4 @@ cifmw_artifacts_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-fra cifmw_artifacts_crc_host: "api.crc.testing" cifmw_artifacts_crc_user: "core" cifmw_artifacts_crc_sshkey: "~/.crc/machines/crc/id_ecdsa" +cifmw_artifacts_gather_logs: "false" diff --git a/ci_framework/roles/artifacts/tasks/main.yml b/ci_framework/roles/artifacts/tasks/main.yml index 9da61eeacb..9c0e06ad93 100644 --- a/ci_framework/roles/artifacts/tasks/main.yml +++ b/ci_framework/roles/artifacts/tasks/main.yml @@ -14,6 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +- name: Verify if "success" flag exists after successful tests execution + register: cifmw_success_flag + ansible.builtin.stat: + path: "{{ ansible_user_dir }}/cifmw-success" + - name: Ensure we have at least minimal ansible facts tags: - always @@ -44,8 +49,15 @@ - always ansible.builtin.import_tasks: cleanup.yml -- name: Gather CRC logs - ansible.builtin.import_tasks: crc.yml - -- name: Gather EDPM logs - ansible.builtin.import_tasks: edpm.yml +- name: Gather logs when forced or tests failed + when: cifmw_artifacts_gather_logs | bool or not cifmw_success_flag.stat.exists + block: + - name: Run os_must_gather + ansible.builtin.import_role: + name: os_must_gather + rescue: + - name: Get CRC logs if os_must_gather failed + ansible.builtin.import_tasks: crc.yml + always: + - name: Get EDPM logs + ansible.builtin.import_tasks: edpm.yml diff --git a/deploy-edpm.yml b/deploy-edpm.yml index fffb82c09e..e2cad0c5bd 100644 --- a/deploy-edpm.yml +++ b/deploy-edpm.yml @@ -6,6 +6,14 @@ # openstack-k8s-operators/install_yaml repository in order to leverage its # own methods. +- name: Remove status flag + hosts: "{{ cifmw_target_host | default('localhost') }}" + tasks: + - name: Delete success flag if exists + ansible.builtin.file: + path: "{{ ansible_user_dir }}/cifmw-success" + state: absent + - name: Bootstrap step ansible.builtin.import_playbook: ci_framework/playbooks/01-bootstrap.yml @@ -31,6 +39,14 @@ ansible.builtin.import_playbook: ci_framework/playbooks/08-run-tests.yml when: cifmw_run_tests | default('false') | bool +- name: Inject status flag + hosts: "{{ cifmw_target_host | default('localhost') }}" + tasks: + - name: Inject success flag + ansible.builtin.file: + path: "{{ ansible_user_dir }}/cifmw-success" + state: touch + - name: Run log related tasks ansible.builtin.import_playbook: ci_framework/playbooks/99-logs.yml when: not zuul_log_collection | default ('false') | bool