Skip to content

Commit

Permalink
Enabling Robottelo for IPv6 Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Apr 10, 2024
1 parent d37f76c commit 5972a88
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 8 deletions.
4 changes: 4 additions & 0 deletions conf/server.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ SERVER:
SOURCE: "internal"
# The RHEL Base OS Version(x.y) where the Satellite is installed
RHEL_VERSION: '7'
# If the the satellite server is IPv6 server
# IS_IPV6:
# HTTP Proxy url for IPv6 satellite to connect for outer world access
# HTTP_PROXY_IPv6_URL:
# run-on-one - All xdist runners default to the first satellite
# balance - xdist runners will be split between available satellites
# on-demand - any xdist runner without a satellite will have a new one provisioned.
Expand Down
5 changes: 4 additions & 1 deletion pytest_fixtures/component/maintain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def module_stash(request):
@pytest.fixture(scope='module')
def sat_maintain(request, module_target_sat, module_capsule_configured):
if settings.remotedb.server:
yield Satellite(settings.remotedb.server)
sat = Satellite(settings.remotedb.server)
http_proxy = sat.enable_ipv6_http_proxy()
yield sat
sat.disable_ipv6_http_proxy(http_proxy)
else:
module_target_sat.register_to_cdn(pool_ids=settings.subscription.fm_rhn_poolid.split())
hosts = {'satellite': module_target_sat, 'capsule': module_capsule_configured}
Expand Down
7 changes: 6 additions & 1 deletion pytest_fixtures/core/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def _default_sat(align_to_satellite):
"""Returns a Satellite object for settings.server.hostname"""
if settings.server.hostname:
try:
return Satellite.get_host_by_hostname(settings.server.hostname)
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)
except ContentHostError:
return Satellite()
return None
Expand All @@ -24,8 +27,10 @@ def _target_sat_imp(request, _default_sat, satellite_factory):
"""This is the actual working part of the following target_sat fixtures"""
if request.node.get_closest_marker(name='destructive'):
new_sat = satellite_factory()
http_proxy = new_sat.sat.enable_ipv6_http_proxy()
yield new_sat
new_sat.teardown()
new_sat.disable_ipv6_http_proxy(http_proxy)
Broker(hosts=[new_sat]).checkin()
elif 'sanity' in request.config.option.markexpr:
installer_sat = lru_sat_ready_rhel(settings.server.version.rhel_version)
Expand Down
23 changes: 19 additions & 4 deletions pytest_fixtures/core/sat_cap_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def resolve_deploy_args(args_dict):
def _target_satellite_host(request, satellite_factory):
if 'sanity' not in request.config.option.markexpr:
new_sat = satellite_factory()
http_proxy = new_sat.enable_ipv6_http_proxy()
yield new_sat
new_sat.teardown()
new_sat.disable_ipv6_http_proxy(http_proxy)
Broker(hosts=[new_sat]).checkin()
else:
yield
Expand All @@ -48,8 +50,10 @@ def cached_capsule_cdn_register(hostname=None):
def _target_capsule_host(request, capsule_factory):
if 'sanity' not in request.config.option.markexpr and not request.config.option.n_minus:
new_cap = capsule_factory()
new_cap.enable_ipv6_http_proxy()
yield new_cap
new_cap.teardown()
new_cap.disable_ipv6_http_proxy()
Broker(hosts=[new_cap]).checkin()
elif request.config.option.n_minus:
if not settings.capsule.hostname:
Expand Down Expand Up @@ -94,8 +98,10 @@ def factory(retry_limit=3, delay=300, workflow=None, **broker_args):
def large_capsule_host(capsule_factory):
"""A fixture that provides a Capsule based on config settings"""
new_cap = capsule_factory(deploy_flavor=settings.flavors.custom_db)
new_cap.enable_ipv6_http_proxy()
yield new_cap
new_cap.teardown()
new_cap.disable_ipv6_http_proxy()
Broker(hosts=[new_cap]).checkin()


Expand Down Expand Up @@ -244,9 +250,11 @@ def module_lb_capsule(retry_limit=3, delay=300, **broker_args):
)
cap_hosts = wait_for(hosts.checkout, timeout=timeout, delay=delay)

[cap.enable_ipv6_http_proxy() for cap in cap_hosts.out]
yield cap_hosts.out

[cap.teardown() for cap in cap_hosts.out]
[cap.disable_ipv6_http_proxy() for cap in cap_hosts.out]
Broker(hosts=cap_hosts.out).checkin()


Expand All @@ -266,6 +274,7 @@ def parametrized_enrolled_sat(
):
"""Yields a Satellite enrolled into [IDM, AD] as parameter."""
new_sat = satellite_factory()
http_proxy = new_sat.enable_ipv6_http_proxy()
ipa_host = IPAHost(new_sat)
new_sat.register_to_cdn()
if 'IDM' in request.param:
Expand All @@ -277,6 +286,7 @@ def parametrized_enrolled_sat(
yield new_sat
new_sat.unregister()
new_sat.teardown()
new_sat.disable_ipv6_http_proxy(http_proxy)
Broker(hosts=[new_sat]).checkin()


Expand Down Expand Up @@ -321,7 +331,9 @@ def cap_ready_rhel():
'workflow': settings.capsule.deploy_workflows.os,
}
with Broker(**deploy_args, host_class=Capsule) as host:
host.enable_ipv6_http_proxy()
yield host
host.disable_ipv6_http_proxy()


@pytest.fixture(scope='session')
Expand All @@ -339,6 +351,7 @@ 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.download_repofile(
Expand All @@ -364,7 +377,9 @@ def installer_satellite(request):
configure_airgun()
yield sat
if 'sanity' not in request.config.option.markexpr:
sanity_sat = Satellite(sat.hostname)
sanity_sat.unregister()
broker_sat = Satellite.get_host_by_hostname(sanity_sat.hostname)
Broker(hosts=[broker_sat]).checkin()
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)
3 changes: 3 additions & 0 deletions pytest_fixtures/core/xdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def align_to_satellite(request, worker_id, satellite_factory):
# clear any hostname that may have been previously set
settings.set("server.hostname", None)
on_demand_sat = None
http_proxy = None

if worker_id in ['master', 'local']:
worker_pos = 0
Expand All @@ -44,6 +45,7 @@ def align_to_satellite(request, worker_id, satellite_factory):
# get current satellite information
elif settings.server.xdist_behavior == 'on-demand':
on_demand_sat = satellite_factory()
http_proxy = on_demand_sat.enable_ipv6_http_proxy()
if on_demand_sat.hostname:
settings.set("server.hostname", on_demand_sat.hostname)
# if no satellite was received, fallback to balance
Expand All @@ -58,4 +60,5 @@ def align_to_satellite(request, worker_id, satellite_factory):
yield
if on_demand_sat and settings.server.auto_checkin:
on_demand_sat.teardown()
on_demand_sat.disable_ipv6_http_proxy(http_proxy)
Broker(hosts=[on_demand_sat]).checkin()
2 changes: 2 additions & 0 deletions robottelo/config/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
Validator('server.ssh_username', default='root'),
Validator('server.ssh_password', default=None),
Validator('server.verify_ca', default=False),
Validator('server.is_ipv6', is_type_of=bool, default=False),
Validator('server.http_proxy_ipv6_url', is_type_of=str),
],
content_host=[
Validator('content_host.default_rhel_version', must_exist=True),
Expand Down
64 changes: 64 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,17 @@ def enable_capsule_downstream_repos(self):
snap=settings.capsule.version.snap,
)

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}'
)

def disable_ipv6_http_proxy(self):
if settings.server.is_ipv6:
self.execute('subscription-manager remove server.proxy_hostname server.proxy_port')

def capsule_setup(self, sat_host=None, capsule_cert_opts=None, **installer_kwargs):
"""Prepare the host and run the capsule installer"""
self._satellite = sat_host or Satellite()
Expand Down Expand Up @@ -1767,6 +1778,59 @@ def _swap_nailgun(self, new_version):
to_clear = [k for k in sys.modules if 'nailgun' in k]
[sys.modules.pop(k) for k in to_clear]

def enable_ipv6_http_proxy(self):
# Execute procedures for enabling IPv6 HTTP Proxy
if all([settings.server.is_ipv6, settings.server.http_proxy_ipv6_url]):
proxy_name = 'robottelo_ipv6_automation_proxy'
if not self.cli.HttpProxy.exists(search=('name', proxy_name)):
http_proxy = self.api.HTTPProxy(
name=proxy_name, url=settings.server.http_proxy_ipv6_url
).create()
else:
logger.info(
'The IPv6 HTTP Proxy is already enabled. Skipping the IPv6 HTTP Proxy setup.'
)
http_proxy = self.api.HTTPProxy().search(query={'search': f'name={proxy_name}'})
if http_proxy:
http_proxy = http_proxy[0]
# Setting HTTP Proxy as default in the settings
self.cli.Settings.set(
{
'name': 'content_default_http_proxy',
'value': proxy_name,
}
)
self.cli.Settings.set(
{
'name': 'http_proxy',
'value': settings.server.http_proxy_ipv6_url,
}
)
return http_proxy
logger.warning(
'The IPv6 HTTP Proxy setting is not enabled. Skipping the IPv6 HTTP Proxy setup.'
)
return None

def disable_ipv6_http_proxy(self, http_proxy):
"""
Execute procedures for disabling IPv6 HTTP Proxy
"""
if http_proxy:
http_proxy.delete()
self.cli.Settings.set(
{
'name': 'content_default_http_proxy',
'value': '',
}
)
self.cli.Settings.set(
{
'name': 'http_proxy',
'value': '',
}
)

@property
def api(self):
"""Import all nailgun entities and wrap them under self.api"""
Expand Down
10 changes: 8 additions & 2 deletions tests/foreman/installer/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,10 @@ def sat_default_install(module_sat_ready_rhels):
f'foreman-initial-admin-password {settings.server.admin_password}',
]
install_satellite(module_sat_ready_rhels[0], installer_args)
return module_sat_ready_rhels[0]
sat = module_sat_ready_rhels[0]
http_proxy = sat.enable_ipv6_http_proxy()
yield
sat.disable_ipv6_http_proxy(http_proxy)


@pytest.fixture(scope='module')
Expand All @@ -1394,7 +1397,10 @@ def sat_non_default_install(module_sat_ready_rhels):
'foreman-proxy-content-pulpcore-hide-guarded-distributions false',
]
install_satellite(module_sat_ready_rhels[1], installer_args, enable_fapolicyd=True)
return module_sat_ready_rhels[1]
sat = module_sat_ready_rhels[1]
http_proxy = sat.enable_ipv6_http_proxy()
yield sat
sat.disable_ipv6_http_proxy(http_proxy)


@pytest.mark.e2e
Expand Down

0 comments on commit 5972a88

Please sign in to comment.