From 2ee0fee942d5be75dd1ddb4ea0bfa7c36b6ad797 Mon Sep 17 00:00:00 2001 From: jyejare Date: Tue, 14 May 2024 17:53:08 +0530 Subject: [PATCH] Sanity Testing fixes for Ipv6 --- pytest_fixtures/core/broker.py | 7 +++---- pytest_fixtures/core/sat_cap_factory.py | 7 ++----- robottelo/hosts.py | 20 ++++++++++++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pytest_fixtures/core/broker.py b/pytest_fixtures/core/broker.py index 0fc4a43e569..fd1c386a34a 100644 --- a/pytest_fixtures/core/broker.py +++ b/pytest_fixtures/core/broker.py @@ -13,10 +13,7 @@ def _default_sat(align_to_satellite): """Returns a Satellite object for settings.server.hostname""" if settings.server.hostname: try: - sat = Satellite.get_host_by_hostname(settings.server.hostname) - http_proxy = sat.enable_ipv6_http_proxy() - yield sat - sat.disable_ipv6_http_proxy(http_proxy) + return Satellite.get_host_by_hostname(settings.server.hostname) except ContentHostError: return Satellite() return None @@ -37,7 +34,9 @@ def _target_sat_imp(request, _default_sat, satellite_factory): settings.set('server.hostname', installer_sat.hostname) yield installer_sat else: + _default_sat.enable_ipv6_http_proxy() yield _default_sat + _default_sat.disable_ipv6_http_proxy() @pytest.fixture diff --git a/pytest_fixtures/core/sat_cap_factory.py b/pytest_fixtures/core/sat_cap_factory.py index c803da6221a..6ee72bcb412 100644 --- a/pytest_fixtures/core/sat_cap_factory.py +++ b/pytest_fixtures/core/sat_cap_factory.py @@ -365,9 +365,8 @@ def installer_satellite(request): else: sat = lru_sat_ready_rhel(getattr(request, 'param', None)) sat.setup_firewall() - http_proxy = sat.enable_ipv6_http_proxy() # # Register for RHEL8 repos, get Ohsnap repofile, and enable and download satellite - sat.register_to_cdn() + sat.register_to_cdn(enable_proxy=True) sat.download_repofile( product='satellite', release=settings.server.version.release, @@ -386,6 +385,7 @@ def installer_satellite(request): ).get_command(), timeout='30m', ) + sat.enable_ipv6_http_proxy() if 'sanity' in request.config.option.markexpr: configure_nailgun() configure_airgun() @@ -393,7 +393,4 @@ def installer_satellite(request): if 'sanity' not in request.config.option.markexpr: sat = Satellite.get_host_by_hostname(sat.hostname) sat.unregister() - sat.disable_ipv6_http_proxy(http_proxy) Broker(hosts=[sat]).checkin() - else: - sat.disable_ipv6_http_proxy(http_proxy) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index cacd04b7a50..cf0ec40611c 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -813,6 +813,7 @@ def register_contenthost( auto_attach=False, serverurl=None, baseurl=None, + enable_proxy=False, ): """Registers content host on foreman server either by specifying organization name and activation key name or by specifying organization @@ -869,6 +870,12 @@ def register_contenthost( cmd += f' --serverurl {serverurl}' if baseurl: cmd += f' --baseurl {baseurl}' + + # Enabling proxy for Ipv6 + if enable_proxy and all([settings.server.is_ipv6, settings.server.http_proxy_ipv6_url]): + url = urlparse(settings.server.http_proxy_ipv6_url) + self.enable_server_proxy(url.hostname, url.port) + return self.execute(cmd) def unregister(self): @@ -915,6 +922,12 @@ def put_ssh_key(self, source_key_path, destination_key_name): if result.status != 0: raise CLIFactoryError(f'Failed to chmod ssh key file:\n{result.stderr}') + def enable_server_proxy(self, hostname, port=None): + cmd = f"subscription-manager config --server.proxy_hostname={hostname}" + if port: + cmd += f' --server.proxy_port={port}' + self.execute(cmd) + def add_authorized_key(self, pub_key): """Inject a public key into the authorized keys file @@ -1459,7 +1472,7 @@ def install_tracer(self): raise ContentHostError('There was an error installing katello-host-tools-tracer') self.execute('katello-tracer-upload') - def register_to_cdn(self, pool_ids=None): + 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] @@ -1469,6 +1482,7 @@ def register_to_cdn(self, pool_ids=None): lce=None, username=settings.subscription.rhn_username, password=settings.subscription.rhn_password, + enable_proxy=enable_proxy, ) if cmd_result.status != 0: raise ContentHostError( @@ -1626,9 +1640,7 @@ def enable_capsule_downstream_repos(self): def enable_ipv6_http_proxy(self): if all([settings.server.is_ipv6, settings.server.http_proxy_ipv6_url]): url = urlparse(settings.server.http_proxy_ipv6_url) - self.execute( - f'subscription-manager config --server.proxy_hostname={url.hostname} --server.proxy_port={url.port}' - ) + self.enable_server_proxy(url.hostname, url.port) def disable_ipv6_http_proxy(self): if settings.server.is_ipv6: