From 1a9c40d4696d89afc7ef71ca4bbbd55cd4c63890 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Thu, 9 May 2024 13:30:43 +0200 Subject: [PATCH] Enable tempest cleanup with record_resources in jobs This enables tempest cleanup with record_resources in the tempest-all job to create a list of all the resources created during the tempest run. Then the list will be used to run 'tempest cleanup' to clean only the resources in the list. Also, enable the dry cleanup with record_resources in tempest-extra-tests job. Change-Id: Ia64a1c09d4b5e9815ff5926161d550b56433ec64 --- roles/tempest-cleanup/README.rst | 9 +++++++++ roles/tempest-cleanup/defaults/main.yaml | 1 + roles/tempest-cleanup/tasks/dry_run.yaml | 14 ++++++++++++-- roles/tempest-cleanup/tasks/main.yaml | 16 +++++++++++++++- zuul.d/integrated-gate.yaml | 15 +++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/roles/tempest-cleanup/README.rst b/roles/tempest-cleanup/README.rst index d43319c33d..255ca2d4d4 100644 --- a/roles/tempest-cleanup/README.rst +++ b/roles/tempest-cleanup/README.rst @@ -47,6 +47,15 @@ saved_state.json file. only resources with names that match the prefix. This option can be used together with dry_run. +.. zuul:rolevar:: run_tempest_cleanup_resource_list + :default: false + + When true, tempest cleanup will be called with '--resource-list' to delete + only resources listed in ./resource_list.json that is created if + record_resources config option in the default section of tempest.conf file + is enabled (set to True). The resource_list.json contains all resources + created by Tempest during a Tempest run. + Role usage ---------- diff --git a/roles/tempest-cleanup/defaults/main.yaml b/roles/tempest-cleanup/defaults/main.yaml index 8060b295cd..1ec2f8c93f 100644 --- a/roles/tempest-cleanup/defaults/main.yaml +++ b/roles/tempest-cleanup/defaults/main.yaml @@ -3,3 +3,4 @@ init_saved_state: false dry_run: false run_tempest_fail_if_leaked_resources: false run_tempest_cleanup_prefix: false +run_tempest_cleanup_resource_list: false diff --git a/roles/tempest-cleanup/tasks/dry_run.yaml b/roles/tempest-cleanup/tasks/dry_run.yaml index 07e1b634cd..8ae51839d7 100644 --- a/roles/tempest-cleanup/tasks/dry_run.yaml +++ b/roles/tempest-cleanup/tasks/dry_run.yaml @@ -5,7 +5,9 @@ command: tox -evenv-tempest -- tempest cleanup --dry-run --debug args: chdir: "{{ devstack_base_dir }}/tempest" - when: not run_tempest_cleanup_prefix + when: + - not run_tempest_cleanup_prefix + - run_tempest_cleanup_resource_list is not defined or not run_tempest_cleanup_resource_list - name: Run tempest cleanup dry-run with tempest prefix become: yes @@ -13,4 +15,12 @@ command: tox -evenv-tempest -- tempest cleanup --dry-run --debug --prefix tempest args: chdir: "{{ devstack_base_dir }}/tempest" - when: run_tempest_cleanup_prefix \ No newline at end of file + when: run_tempest_cleanup_prefix + +- name: Run tempest cleanup with tempest resource list + become: yes + become_user: tempest + command: tox -evenv-tempest -- tempest cleanup --dry-run --debug --resource-list + args: + chdir: "{{ devstack_base_dir }}/tempest" + when: run_tempest_cleanup_resource_list diff --git a/roles/tempest-cleanup/tasks/main.yaml b/roles/tempest-cleanup/tasks/main.yaml index 7ef4928042..1e1c1a7469 100644 --- a/roles/tempest-cleanup/tasks/main.yaml +++ b/roles/tempest-cleanup/tasks/main.yaml @@ -27,7 +27,9 @@ command: tox -evenv-tempest -- tempest cleanup --debug args: chdir: "{{ devstack_base_dir }}/tempest" - when: not run_tempest_cleanup_prefix + when: + - not run_tempest_cleanup_prefix + - run_tempest_cleanup_resource_list is not defined or not run_tempest_cleanup_resource_list - name: Run tempest cleanup with tempest prefix become: yes @@ -37,6 +39,18 @@ chdir: "{{ devstack_base_dir }}/tempest" when: run_tempest_cleanup_prefix + - name: Cat resource_list.json + command: cat "{{ devstack_base_dir }}/tempest/resource_list.json" + when: run_tempest_cleanup_resource_list + + - name: Run tempest cleanup with tempest resource list + become: yes + become_user: tempest + command: tox -evenv-tempest -- tempest cleanup --debug --resource-list + args: + chdir: "{{ devstack_base_dir }}/tempest" + when: run_tempest_cleanup_resource_list + - when: - run_tempest_fail_if_leaked_resources - not init_saved_state diff --git a/zuul.d/integrated-gate.yaml b/zuul.d/integrated-gate.yaml index 596acb17a9..acd65d82b7 100644 --- a/zuul.d/integrated-gate.yaml +++ b/zuul.d/integrated-gate.yaml @@ -17,6 +17,13 @@ # TODO(gmann): Enable File injection tests once nova bug is fixed # https://bugs.launchpad.net/nova/+bug/1882421 # ENABLE_FILE_INJECTION: true + run_tempest_cleanup: true + run_tempest_cleanup_resource_list: true + devstack_local_conf: + test-config: + $TEMPEST_CONFIG: + DEFAULT: + record_resources: true - job: name: tempest-ipv6-only @@ -37,6 +44,14 @@ tools/tempest-extra-tests-list.txt. vars: tox_envlist: extra-tests + run_tempest_cleanup: true + run_tempest_cleanup_resource_list: true + run_tempest_dry_cleanup: true + devstack_local_conf: + test-config: + $TEMPEST_CONFIG: + DEFAULT: + record_resources: true - job: name: tempest-full-py3