diff --git a/src/pubtools/_marketplacesvm/tasks/delete/command.py b/src/pubtools/_marketplacesvm/tasks/delete/command.py index fbfbb50..df8cfc6 100644 --- a/src/pubtools/_marketplacesvm/tasks/delete/command.py +++ b/src/pubtools/_marketplacesvm/tasks/delete/command.py @@ -135,6 +135,15 @@ def _convert_provider_name(self, provider_name: str) -> List[str]: } return accounts[provider_name] + def _set_ami_invisible(self, push_item: AmiPushItem) -> None: + img_id = push_item.image_id + provider = push_item.marketplace_entity_type + log.debug("Marking AMI %s as invisible on RHSM for the provider %s.", img_id, provider) + try: + self.set_ami_invisible_rhsm(push_item, provider) + except Exception as err: + log.warning("Failed to mark %s invisible on RHSM: %s", img_id, err) + def _delete( self, push_item: VMIPushItem, @@ -143,7 +152,7 @@ def _delete( marketplaces = self._convert_provider_name(push_item.marketplace_entity_type) if push_item.build in self.args.builds: if self.args.dry_run: - self.set_ami_invisible_rhsm(push_item, push_item.marketplace_entity_type) + self._set_ami_invisible(push_item) log.info("Would have deleted: %s in build %s", push_item.image_id, push_item.build) self._SKIPPED = True pi = evolve(push_item, state=State.SKIPPED) @@ -151,7 +160,7 @@ def _delete( # Cycle through potential marketplaces, this only matters in AmiProducts # as the build could exist in either aws-na or aws-emea. for marketplace in marketplaces: - self.set_ami_invisible_rhsm(push_item, push_item.marketplace_entity_type) + self._set_ami_invisible(push_item) log.info( "Deleting %s in account %s", push_item.image_id, diff --git a/tests/logs/delete/test_delete/test_delete.txt b/tests/logs/delete/test_delete/test_delete.txt index 3a34fac..d10110e 100644 --- a/tests/logs/delete/test_delete/test_delete.txt +++ b/tests/logs/delete/test_delete/test_delete.txt @@ -1,4 +1,5 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups @@ -7,6 +8,7 @@ [ INFO] Existing image ami-rhcos1 succesfully updated in rhsm [ INFO] Deleting ami-rhcos1 in account aws-china-storage [ INFO] Delete finished for ami-rhcos1 in account aws-china-storage +[ DEBUG] Marking AMI ami-aws1 as invisible on RHSM for the provider AmiProduct. [ DEBUG] Searching for product sample_product for provider AmiProduct in rhsm [ INFO] sample_product not found in RHSM [ INFO] Deleting ami-aws1 in account aws-na diff --git a/tests/logs/delete/test_delete/test_delete_ami_id_not_found_rhsm.txt b/tests/logs/delete/test_delete/test_delete_ami_id_not_found_rhsm.txt index 2872cdd..273f057 100644 --- a/tests/logs/delete/test_delete/test_delete_ami_id_not_found_rhsm.txt +++ b/tests/logs/delete/test_delete/test_delete_ami_id_not_found_rhsm.txt @@ -1,4 +1,5 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups @@ -7,6 +8,7 @@ [ INFO] Existing image ami-rhcos1 succesfully updated in rhsm [ INFO] Deleting ami-rhcos1 in account aws-china-storage [ INFO] Delete finished for ami-rhcos1 in account aws-china-storage +[ DEBUG] Marking AMI ami-aws1 as invisible on RHSM for the provider AmiProduct. [ WARNING] AMI image: ami-aws1 not found, skipping update in rhsm. [ INFO] Deleting ami-aws1 in account aws-na [ INFO] Delete finished for ami-aws1 in account aws-na diff --git a/tests/logs/delete/test_delete/test_delete_bad_rhsm.txt b/tests/logs/delete/test_delete/test_delete_bad_rhsm.txt index 1ba766e..13c91d3 100644 --- a/tests/logs/delete/test_delete/test_delete_bad_rhsm.txt +++ b/tests/logs/delete/test_delete/test_delete_bad_rhsm.txt @@ -1,8 +1,18 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups [ DEBUG] 5 Products(AWS provider) in rhsm: RHEL_HA(awstest), SAP(awstest), rhcos(ACN), sample_product(fake), sample_product_HOURLY(ACN) [ INFO] Attempting to update the existing image ami-rhcos1 in rhsm [ ERROR] Failed updating image ami-rhcos1 -# Raised: 400 Client Error: None for url: https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis +[ WARNING] Failed to mark ami-rhcos1 invisible on RHSM: 400 Client Error: None for url: https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis +[ INFO] Deleting ami-rhcos1 in account aws-china-storage +[ INFO] Delete finished for ami-rhcos1 in account aws-china-storage +[ DEBUG] Marking AMI ami-aws1 as invisible on RHSM for the provider AmiProduct. +[ DEBUG] Searching for product sample_product for provider AmiProduct in rhsm +[ INFO] sample_product not found in RHSM +[ INFO] Deleting ami-aws1 in account aws-na +[ INFO] Delete finished for ami-aws1 in account aws-na +[ INFO] Collecting results +[ INFO] Delete completed diff --git a/tests/logs/delete/test_delete/test_delete_dry_run.txt b/tests/logs/delete/test_delete/test_delete_dry_run.txt index 4516ce0..0ae2656 100644 --- a/tests/logs/delete/test_delete/test_delete_dry_run.txt +++ b/tests/logs/delete/test_delete/test_delete_dry_run.txt @@ -1,10 +1,12 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups [ DEBUG] 5 Products(AWS provider) in rhsm: RHEL_HA(awstest), SAP(awstest), rhcos(ACN), sample_product(fake), sample_product_HOURLY(ACN) [ INFO] Would have updated image ami-rhcos1 in rhsm [ INFO] Would have deleted: ami-rhcos1 in build rhcos-x86_64-414.92.202405201754-0 +[ DEBUG] Marking AMI ami-aws1 as invisible on RHSM for the provider AmiProduct. [ DEBUG] Searching for product sample_product for provider AmiProduct in rhsm [ INFO] sample_product not found in RHSM [ INFO] Would have deleted: ami-aws1 in build sample_product-1.0.1-1-x86_64 diff --git a/tests/logs/delete/test_delete/test_delete_failed.txt b/tests/logs/delete/test_delete/test_delete_failed.txt index f16598a..943bed9 100644 --- a/tests/logs/delete/test_delete/test_delete_failed.txt +++ b/tests/logs/delete/test_delete/test_delete_failed.txt @@ -1,4 +1,5 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups diff --git a/tests/logs/delete/test_delete/test_delete_failed_one.txt b/tests/logs/delete/test_delete/test_delete_failed_one.txt index ebd3175..c22690b 100644 --- a/tests/logs/delete/test_delete/test_delete_failed_one.txt +++ b/tests/logs/delete/test_delete/test_delete_failed_one.txt @@ -1,4 +1,5 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-aws1 as invisible on RHSM for the provider AmiProduct. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product for provider AmiProduct in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups diff --git a/tests/logs/delete/test_delete/test_delete_skip_build.txt b/tests/logs/delete/test_delete/test_delete_skip_build.txt index 1eb641b..de4f51b 100644 --- a/tests/logs/delete/test_delete/test_delete_skip_build.txt +++ b/tests/logs/delete/test_delete/test_delete_skip_build.txt @@ -1,4 +1,5 @@ [ INFO] Loading items from pub:https://fakepub.com?task-id=12345 +[ DEBUG] Marking AMI ami-rhcos1 as invisible on RHSM for the provider ACN. [ DEBUG] Listing all images from rhsm, https://rhsm.com/v1/internal/cloud_access_providers/amazon/amis [ DEBUG] Searching for product sample_product_HOURLY for provider ACN in rhsm [ DEBUG] Fetching product from https://rhsm.com/v1/internal/cloud_access_providers/amazon/provider_image_groups