From 334a12f1a7dddb634c488df8a43cdc2f7b821205 Mon Sep 17 00:00:00 2001 From: vsedmik <46570670+vsedmik@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:26:24 +0100 Subject: [PATCH] Add conditioning for pool attach (#16575) * Add conditioning for pool attach * Improve pool validations a bit --- robottelo/constants/__init__.py | 1 + robottelo/hosts.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index 43571611a30..179d8b5e5da 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -317,6 +317,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 c6caf2eda4a..f7e30b718af 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -47,6 +47,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 @@ -1438,8 +1439,6 @@ def install_tracer(self): def register_to_cdn(self, pool_ids=None, enable_proxy=False): """Subscribe satellite to CDN""" - if pool_ids is None: - pool_ids = [settings.subscription.rhn_poolid] self.reset_rhsm() cmd_result = self.register_contenthost( org=None, @@ -1452,11 +1451,17 @@ def register_to_cdn(self, pool_ids=None, enable_proxy=False): 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 in [None, []]: + pool_ids = [settings.subscription.rhn_poolid] + 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