From f2f662fa22fea8f0fd6c36998a38314bc7d43f04 Mon Sep 17 00:00:00 2001 From: Vladimir Sedmik Date: Fri, 4 Oct 2024 18:36:29 +0200 Subject: [PATCH 1/2] Add conditioning for pool attach --- robottelo/constants/__init__.py | 1 + robottelo/hosts.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index 1b81b2f375e..6ed5e02833d 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -312,6 +312,7 @@ 'current': 'Overall Status: Current', 'invalid': 'Overall Status: Invalid', 'insufficient': 'Overall Status: Insufficient', + 'disabled': 'Overall Status: Disabled', 'unknown': 'Overall Status: Unknown', } diff --git a/robottelo/hosts.py b/robottelo/hosts.py index f5ae9b6d993..3e18e9615ec 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -50,6 +50,7 @@ RHSSO_RESET_PASSWORD, RHSSO_USER_UPDATE, SATELLITE_VERSION, + SM_OVERALL_STATUS, ) from robottelo.exceptions import CLIFactoryError, DownloadFileError, HostPingFailed from robottelo.host_helpers import CapsuleMixins, ContentHostMixins, SatelliteMixins @@ -1503,8 +1504,6 @@ def install_tracer(self): def register_to_cdn(self, pool_ids=None): """Subscribe satellite to CDN""" - if pool_ids is None: - pool_ids = [settings.subscription.rhn_poolid] self.remove_katello_ca() cmd_result = self.register_contenthost( org=None, @@ -1516,11 +1515,16 @@ def register_to_cdn(self, pool_ids=None): raise ContentHostError( f'Error during registration, command output: {cmd_result.stdout}' ) - cmd_result = self.subscription_manager_attach_pool(pool_ids)[0] - if cmd_result.status != 0: - raise ContentHostError( - f'Error during pool attachment, command output: {cmd_result.stdout}' - ) + # Attach a pool only if the Org isn't SCA yet + sub_status = self.subscription_manager_status().stdout + if SM_OVERALL_STATUS['disabled'] not in sub_status: + if pool_ids is None: + pool_ids = [settings.subscription.rhn_poolid] + cmd_result = self.subscription_manager_attach_pool(pool_ids)[0] + if cmd_result.status != 0: + raise ContentHostError( + f'Error during pool attachment, command output: {cmd_result.stdout}' + ) def ping_host(self, host): """Check the provisioned host status by pinging the ip of host From aae46b51864028934e821c6800cc8d48e4e4c90e Mon Sep 17 00:00:00 2001 From: Vladimir Sedmik Date: Mon, 7 Oct 2024 11:25:46 +0200 Subject: [PATCH 2/2] Improve pool validations a bit --- robottelo/hosts.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 3e18e9615ec..69d5d30a9ff 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1518,13 +1518,14 @@ def register_to_cdn(self, pool_ids=None): # Attach a pool only if the Org isn't SCA yet sub_status = self.subscription_manager_status().stdout if SM_OVERALL_STATUS['disabled'] not in sub_status: - if pool_ids is None: + if pool_ids in [None, []]: pool_ids = [settings.subscription.rhn_poolid] - cmd_result = self.subscription_manager_attach_pool(pool_ids)[0] - if cmd_result.status != 0: - raise ContentHostError( - f'Error during pool attachment, command output: {cmd_result.stdout}' - ) + for pid in pool_ids: + int(pid, 16) # raises ValueError if not a HEX number + cmd_result = self.subscription_manager_attach_pool(pool_ids) + for res in cmd_result: + if res.status != 0: + raise ContentHostError(f'Pool attachment failed with output: {res.stdout}') def ping_host(self, host): """Check the provisioned host status by pinging the ip of host