Skip to content

Commit

Permalink
Update Platform tests that have hard coded content host versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Griffin-Sullivan committed Mar 19, 2024
1 parent 222a69e commit dd1a20b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
15 changes: 13 additions & 2 deletions pytest_fixtures/core/contenthosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def rhel_contenthost(request):
yield host


@pytest.fixture(scope='module')
def module_rhel_contenthost(request):
"""A module-level fixture that provides a content host object parametrized"""
# Request should be parametrized through pytest_fixtures.fixture_markers
# unpack params dict
with Broker(**host_conf(request), host_class=ContentHost) as host:
yield host


@pytest.fixture(params=[{'rhel_version': '7'}])
def rhel7_contenthost(request):
"""A function-level fixture that provides a rhel7 content host object"""
Expand Down Expand Up @@ -268,8 +277,10 @@ def sat_upgrade_chost():
def custom_host(request):
"""A rhel content host that passes custom host config through request.param"""
deploy_args = request.param
# if 'deploy_rhel_version' is not set, let's default to RHEL 8
deploy_args['deploy_rhel_version'] = deploy_args.get('deploy_rhel_version', '8')
# if 'deploy_rhel_version' is not set, let's default to what's in content_host.yaml
deploy_args['deploy_rhel_version'] = deploy_args.get(
'deploy_rhel_version', settings.content_host.default_rhel_version
)
deploy_args['workflow'] = 'deploy-rhel'
with Broker(**deploy_args, host_class=Satellite) as host:
yield host
8 changes: 6 additions & 2 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def activationkey_add_subscription_to_repo(self, options=None):
f'Failed to add subscription to activation key\n{err.msg}'
) from err

def setup_org_for_a_custom_repo(self, options=None):
def setup_org_for_a_custom_repo(self, options=None, multi_repo=False):
"""Sets up Org for the given custom repo by:
1. Checks if organization and lifecycle environment were given, otherwise
Expand Down Expand Up @@ -640,7 +640,11 @@ def setup_org_for_a_custom_repo(self, options=None):
lce_promoted = cv_info['lifecycle-environments']
# Promote version to next env
try:
if env_id not in [int(lce['id']) for lce in lce_promoted]:
# This conditional will only promote the CV if this is the first pass through
# the function. This means if you loop this function for multiple repos, only
# the first CVV with the first repo will be promoted. To get all of your repos
# promoted each pass, specify multi_repo = True.
if (env_id not in [int(lce['id']) for lce in lce_promoted]) or multi_repo:
self._satellite.cli.ContentView.version_promote(
{
'id': cvv['id'],
Expand Down
50 changes: 28 additions & 22 deletions tests/foreman/destructive/test_capsule_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,34 @@ def content_for_client(module_target_sat, module_org, module_lce, module_cv, mod
:return: Activation key, client lifecycle environment(used by setup_capsules())
"""
module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': settings.repos.RHEL7_OS,
'organization-id': module_org.id,
'content-view-id': module_cv.id,
'lifecycle-environment-id': module_lce.id,
'activationkey-id': module_ak.id,
}
)
rhel_ver = settings.content_host.default_rhel_version
baseos = eval(f'settings.repos.RHEL{rhel_ver}_OS.baseos')
appstream = eval(f'settings.repos.RHEL{rhel_ver}_OS.appstream')
for repo in [baseos, appstream]:
module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': repo,
'organization-id': module_org.id,
'content-view-id': module_cv.id,
'lifecycle-environment-id': module_lce.id,
'activationkey-id': module_ak.id,
},
multi_repo=True,
)
return {'client_ak': module_ak, 'client_lce': module_lce}


@pytest.fixture(scope='module')
def setup_capsules(
module_org,
rhel7_contenthost_module,
module_rhel_contenthost,
module_lb_capsule,
module_target_sat,
content_for_client,
):
"""Install capsules with loadbalancer options"""
extra_cert_var = {'foreman-proxy-cname': rhel7_contenthost_module.hostname}
extra_installer_var = {'certs-cname': rhel7_contenthost_module.hostname}
extra_cert_var = {'foreman-proxy-cname': module_rhel_contenthost.hostname}
extra_installer_var = {'certs-cname': module_rhel_contenthost.hostname}

for capsule in module_lb_capsule:
capsule.register_to_cdn()
Expand Down Expand Up @@ -92,20 +97,20 @@ def setup_capsules(
@pytest.fixture(scope='module')
def setup_haproxy(
module_org,
rhel7_contenthost_module,
module_rhel_contenthost,
content_for_client,
module_target_sat,
setup_capsules,
):
"""Install and configure haproxy and setup logging"""
haproxy = rhel7_contenthost_module
haproxy = module_rhel_contenthost
# Using same AK for haproxy just for packages
haproxy_ak = content_for_client['client_ak']
haproxy.execute('firewall-cmd --add-service RH-Satellite-6-capsule')
haproxy.execute('firewall-cmd --runtime-to-permanent')
haproxy.install_katello_ca(module_target_sat)
haproxy.register_contenthost(module_org.label, haproxy_ak.name)
result = haproxy.execute('yum install haproxy policycoreutils-python -y')
result = haproxy.execute('yum install haproxy policycoreutils-python-utils -y')
assert result.status == 0
haproxy.execute('rm -f /etc/haproxy/haproxy.cfg')
haproxy.session.sftp_write(
Expand Down Expand Up @@ -171,8 +176,9 @@ def loadbalancer_setup(

@pytest.mark.e2e
@pytest.mark.tier1
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
def test_loadbalancer_install_package(
loadbalancer_setup, setup_capsules, rhel7_contenthost, module_org, module_location, request
loadbalancer_setup, setup_capsules, rhel_contenthost, module_org, module_location, request
):
r"""Install packages on a content host regardless of the registered capsule being available
Expand All @@ -193,7 +199,7 @@ def test_loadbalancer_install_package(
"""

# Register content host
result = rhel7_contenthost.register(
result = rhel_contenthost.register(
org=module_org,
loc=module_location,
activation_keys=loadbalancer_setup['content_for_client']['client_ak'].name,
Expand All @@ -203,15 +209,15 @@ def test_loadbalancer_install_package(
assert result.status == 0, f'Failed to register host: {result.stderr}'

# Try package installation
result = rhel7_contenthost.execute('yum install -y tree')
result = rhel_contenthost.execute('yum install -y tree')
assert result.status == 0

hosts = loadbalancer_setup['module_target_sat'].cli.Host.list(
{'organization-id': loadbalancer_setup['module_org'].id}
)
assert rhel7_contenthost.hostname in [host['name'] for host in hosts]
assert rhel_contenthost.hostname in [host['name'] for host in hosts]

result = rhel7_contenthost.execute('rpm -qa | grep katello-ca-consumer')
result = rhel_contenthost.execute('rpm -qa | grep katello-ca-consumer')

# Find which capsule the host is registered to since it's RoundRobin
# The following also asserts the above result
Expand All @@ -225,14 +231,14 @@ def test_loadbalancer_install_package(
)

# Remove the packages from the client
result = rhel7_contenthost.execute('yum remove -y tree')
result = rhel_contenthost.execute('yum remove -y tree')
assert result.status == 0

# Power off the capsule that the client is registered to
registered_to_capsule.power_control(state=VmState.STOPPED, ensure=True)

# Try package installation again
result = rhel7_contenthost.execute('yum install -y tree')
result = rhel_contenthost.execute('yum install -y tree')
assert result.status == 0


Expand Down
15 changes: 12 additions & 3 deletions tests/foreman/maintain/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ def test_positive_repositories_validate(sat_maintain):
@pytest.mark.parametrize(
'custom_host',
[
{'deploy_rhel_version': '8', 'deploy_flavor': 'satqe-ssd.disk.xxxl'},
{'deploy_rhel_version': '8', 'deploy_flavor': 'satqe-ssd.standard.std'},
{
'deploy_rhel_version': settings.server.version.rhel_version,
'deploy_flavor': 'satqe-ssd.disk.xxxl',
},
{
'deploy_rhel_version': settings.server.version.rhel_version,
'deploy_flavor': 'satqe-ssd.standard.std',
},
],
ids=['default', 'medium'],
indirect=True,
Expand All @@ -118,6 +124,7 @@ def test_negative_pre_upgrade_tuning_profile_check(request, custom_host):
:expectedresults: Pre-upgrade check fails.
"""
profile = request.node.callspec.id
rhel_major = settings.server.version.rhel_version[0]
sat_version = ".".join(settings.server.version.release.split('.')[0:2])
# Register to CDN for RHEL8 repos, download and enable last y stream's ohsnap repos,
# and enable the satellite module and install it on the host
Expand All @@ -126,7 +133,9 @@ def test_negative_pre_upgrade_tuning_profile_check(request, custom_host):
SATELLITE_VERSION if sat_version == 'stream' else sat_version
)
custom_host.download_repofile(product='satellite', release=last_y_stream)
custom_host.execute('dnf -y module enable satellite:el8 && dnf -y install satellite')
custom_host.execute(
f'dnf -y module enable satellite:el{rhel_major} && dnf -y install satellite'
)
# Install with development tuning profile to get around installer checks
custom_host.execute(
'satellite-installer --scenario satellite --tuning development',
Expand Down

0 comments on commit dd1a20b

Please sign in to comment.