Skip to content

Commit 6452867

Browse files
mnietojiclaude
authored andcommitted
[update] Add optional cleanup of OpenStack resources
The update role creates test workloads (ping test VM, ports) on OpenStack during the update procedure but never cleans them up. This leaves ports allocated on the external network, which blocks subsequent test jobs from recreating subnets. Add a cleanup step at the end of the update role that runs the workload_launch.sh script in cleanup mode to delete the test VM and associated ports. The cleanup runs by default and can be disabled with cifmw_update_dont_cleanup for debugging. Based on the work from #3335 by Sofer Athlan-Guyot which was closed by the stale bot before merging. Related-Issue: #OSPRH-20307 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Miguel Angel Nieto Jimenez <mnietoji@redhat.com>
1 parent 4f7c3cd commit 6452867

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

roles/update/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ Role to run update
2323
* `cifmw_update_resources_monitoring_interval`: (Integer) Interval, in seconds, between two resources monitor during update. Default to 10 seconds.
2424
* `cifmw_update_wait_controplane_status_change_sec`: (Integer) Time, in seconds, to wait before checking openstack control plane deployment status. Used when need to wait to allow the control plane's ready condition to transition from its initial state, preventing premature completion while the control plane is still reconciling the operator changes. Defaults to `60`.
2525
* `cifmw_update_openstack_update_kpatch`: (Boolean) Activate `kpatch` during update. Default to false.
26+
* `cifmw_update_cleanup`: (Bool) Cleanup resources created on OpenStack during update testing. Set to `false` to skip cleanup for debugging. Default to `true`.
2627

2728
## Examples

roles/update/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ cifmw_update_openstack_cmd: >-
4848
oc rsh -n {{ cifmw_update_namespace }} openstackclient openstack
4949
5050
## User facing
51+
cifmw_update_cleanup: true
5152
cifmw_update_openstack_update_kpatch: false
5253

5354
cifmw_update_reboot_test: false

roles/update/tasks/cleanup.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
- name: Cleaning the World
18-
ansible.builtin.debug:
19-
msg: "So here update should clean things up!"
17+
- name: Cleanup ping test resources
18+
when:
19+
- cifmw_update_ping_test | bool
20+
block:
21+
- name: Cleaning the ping vm if needed
22+
ansible.builtin.shell: |
23+
set -e
24+
set -o pipefail
25+
cat {{ cifmw_update_workload_launch_script }} | \
26+
podman exec -i lopenstackclient env WKL_MODE=cleanup bash -i 2>&1 \
27+
{{ cifmw_update_timestamper_cmd }} | tee {{ cifmw_update_artifacts_basedir }}/workload_cleanup.log
28+
29+
- name: Get logs from update instance cleanup
30+
ansible.builtin.command:
31+
cmd: >
32+
podman cp lopenstackclient:{{ cifmw_update_artifacts_basedir_suffix }}/.
33+
{{ cifmw_update_artifacts_basedir }}

roles/update/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,9 @@
266266
cmd: >
267267
{{ cifmw_update_artifacts_basedir }}/update_event.sh
268268
Update complete
269+
270+
- name: Cleanup resources used for testing on OpenStack
271+
ansible.builtin.include_tasks: cleanup.yml
272+
when:
273+
- cifmw_update_cleanup | bool
274+
- not (cifmw_update_run_dryrun | bool)

roles/update/templates/workload_launch.sh.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ if [[ "${MODE}" == "workload_traffic" ]]; then
635635
fi
636636

637637
if [[ "${MODE}" == "cleanup" ]]; then
638+
export WORKLOAD_FILE="${HOME}/{{ cifmw_update_artifacts_basedir_suffix }}/workload_suffix"
638639
# obtain SUFFIX value generated during workload_launch
639640
source "${WORKLOAD_FILE}"
640641
prepare_env

0 commit comments

Comments
 (0)