From ea46351f09ec59ae811559f0012dfb21f02fd8f5 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Fri, 26 Aug 2022 03:46:22 +0200 Subject: [PATCH] copr: try to remove also volumes --- .../backend/templates/resalloc/ibm-cloud-vm.j2 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/roles/copr/backend/templates/resalloc/ibm-cloud-vm.j2 b/roles/copr/backend/templates/resalloc/ibm-cloud-vm.j2 index 0e98db2af3..1fbfb6d43f 100755 --- a/roles/copr/backend/templates/resalloc/ibm-cloud-vm.j2 +++ b/roles/copr/backend/templates/resalloc/ibm-cloud-vm.j2 @@ -250,6 +250,20 @@ def delete_instance_attempt(service, instance_name, opts): assert resp.status_code == 204 log.debug("Delete IP request delivered") + # Query all volumes only after already potentionaly deleting an instance. + # The volumes might have been deleted automatically + volume_ids = [] + volumes = service.list_volumes(limit=999).result["volumes"] + for volume in volumes: + if volume["name"].startswith(instance_name): + volume_ids.append(volume["id"]) + + if volume_ids: + for volume_id in volume_ids: + resp = service.delete_volume(volume_id) + assert resp.status_code == 204 + log.debug("Delete volume request delivered") + def _get_arg_parser(): parser = argparse.ArgumentParser()