Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a contenthost_factory to perform post-deploy actions #16981

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 82 additions & 48 deletions conf/content_host.yaml.template
Original file line number Diff line number Diff line change
@@ -1,80 +1,114 @@
content_host:
default_rhel_version: 7
rhel6:
centos7:
vm:
workflow: deploy-base-rhel
deploy_rhel_version: '6'
deploy_rhel_version: '7'
deploy_scenario: centos
target_cores: 1
target_memory: 1GiB
workflow: deploy-centos
centos8:
vm:
deploy_rhel_version: '8.5'
deploy_scenario: centos
target_cores: 1
target_memory: 1536 MiB
workflow: deploy-centos
default_rhel_version: 8
oracle7:
vm:
deploy_rhel_version: '7.9'
deploy_scenario: oracle
target_cores: 1
target_memory: 1GiB
workflow: deploy-oracle-linux
oracle8:
vm:
deploy_rhel_version: '8.9'
deploy_scenario: oracle
target_cores: 1
target_memory: 1536 MiB
workflow: deploy-oracle-linux
rhel6:
container:
container_host: rhel6:latest
rhel7:
vm:
workflow: deploy-base-rhel
deploy_rhel_version: '7'
target_memory: 1GiB
cores: 1
deploy_rhel_version: '6'
memory: 1GiB
release: '6.10'
target_cores: 1
target_memory: 1GiB
workflow: deploy-rhel
rhel7:
container:
container_host: ubi7:latest
rhel7_fips:
vm:
workflow: deploy-base-rhel-fips
cores: 1
deploy_rhel_version: '7'
memory: 1GiB
release: '7.9'
target_cores: 1
target_memory: 1GiB
workflow: deploy-rhel
rhel7_fips:
vm:
cores: 1
deploy_rhel_version: '7'
memory: 1GiB
release: '7.9'
target_cores: 1
target_memory: 1GiB
workflow: deploy-rhel
post_configs:
- fips
rhel8:
container:
container_host: ubi8:latest
vm:
workflow: deploy-base-rhel
cores: 1
deploy_rhel_version: '8'
target_memory: 1536 MiB
memory: 1536 MiB
release: '8.5'
target_cores: 1
container:
container_host: ubi8:latest
target_memory: 1536 MiB
workflow: deploy-rhel
rhel8_fips:
vm:
workflow: deploy-base-rhel-fips
cores: 1
deploy_rhel_version: '8'
target_memory: 1536 MiB
memory: 1536 MiB
release: '8.5'
target_cores: 1
rhel9:
vm:
workflow: deploy-base-rhel
deploy_rhel_version: '9'
target_memory: 1536 MiB
target_cores: 1
workflow: deploy-rhel
post_configs:
- fips
rhel9:
container:
container_host: ubi9:latest
rhel9_fips:
vm:
workflow: deploy-base-rhel-fips
cores: 1
deploy_rhel_version: '9'
target_memory: 1536 MiB
target_cores: 1
centos7:
vm:
workflow: deploy-centos
deploy_scenario: centos
deploy_rhel_version: '7'
target_memory: 1GiB
memory: 1536 MiB
release: '9.0'
target_cores: 1
centos8:
vm:
workflow: deploy-centos
deploy_scenario: centos
deploy_rhel_version: '8.6'
target_memory: 1536 MiB
target_cores: 1
oracle7:
workflow: deploy-rhel
rhel9_fips:
vm:
workflow: deploy-oracle-linux
deploy_scenario: oracle
deploy_rhel_version: '7.9'
target_memory: 1GiB
cores: 1
deploy_rhel_version: '9'
memory: 1536 MiB
release: '9.0'
target_cores: 1
oracle8:
vm:
workflow: deploy-oracle-linux
deploy_scenario: oracle
deploy_rhel_version: '8.6'
target_memory: 1536 MiB
target_cores: 1
workflow: deploy-rhel
post_configs:
- fips
host_post_configs:
fips:
workflow: enable-fips
target_vm: "{vm.name}"
fapolicyd:
workflow: enable-fapolicyd
target_vm: "{vm.name}"
86 changes: 52 additions & 34 deletions pytest_fixtures/core/contenthosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
All functions in this module will be treated as fixtures that apply the contenthost mark
"""

from contextlib import contextmanager

from broker import Broker
import pytest

Expand Down Expand Up @@ -41,93 +43,115 @@ def host_conf(request):
return conf


def host_post_config(hosts, config_name):
"""A function that runs a specified post config on a list of content hosts."""
broker_args = settings.content_host.host_post_configs.get(config_name).to_dict()
for host in hosts:
for key, val in broker_args.items():
if "{" in val:
broker_args[key] = val.format(host=host)
Broker(**broker_args).execute()


@contextmanager
def contenthost_factory(request, **kwargs):
"""A factory function that checks out and (optionally) configures a content host."""
host_params = host_conf(request)
post_configs = host_params.pop("post_configs", [])
host_class = kwargs.pop("host_class", ContentHost)
with Broker(**host_params, host_class=host_class, **kwargs) as host:
if post_configs:
hosts = host if isinstance(host, list) else [host]
for config_name in post_configs:
host_post_config(hosts, config_name)
yield host


@pytest.fixture
def rhel_contenthost(request):
"""A function-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:
with contenthost_factory(request=request) as host:
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:
with contenthost_factory(request=request) 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"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(scope="class", params=[{'rhel_version': '7'}])
def rhel7_contenthost_class(request):
"""A fixture for use with unittest classes. Provides a rhel7 Content Host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(scope='module', params=[{'rhel_version': '7'}])
def rhel7_contenthost_module(request):
"""A module-level fixture that provides a rhel7 content host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(params=[{'rhel_version': '8'}])
def rhel8_contenthost(request):
"""A fixture that provides a rhel8 content host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(scope='module', params=[{'rhel_version': '8'}])
def rhel8_contenthost_module(request):
"""A module-level fixture that provides a rhel8 content host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(params=[{'rhel_version': 6}])
def rhel6_contenthost(request):
"""A function-level fixture that provides a rhel6 content host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(params=[{'rhel_version': '9'}])
def rhel9_contenthost(request):
"""A fixture that provides a rhel9 content host object"""
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture
def content_hosts(request):
"""A function-level fixture that provides two rhel content hosts object"""
with Broker(**host_conf(request), host_class=ContentHost, _count=2) as hosts:
with contenthost_factory(request=request, _count=2) as hosts:
hosts[0].set_infrastructure_type('physical')
yield hosts


@pytest.fixture(scope='module')
def mod_content_hosts(request):
"""A module-level fixture that provides two rhel content hosts object"""
with Broker(**host_conf(request), host_class=ContentHost, _count=2) as hosts:
with contenthost_factory(request=request, _count=2) as hosts:
hosts[0].set_infrastructure_type('physical')
yield hosts


@pytest.fixture
def registered_hosts(request, target_sat, module_org, module_ak_with_cv):
"""Fixture that registers content hosts to Satellite, based on rh_cloud setup"""
with Broker(**host_conf(request), host_class=ContentHost, _count=2) as hosts:
with contenthost_factory(request=request, _count=2) as hosts:
for vm in hosts:
repo = settings.repos['SATCLIENT_REPO'][f'RHEL{vm.os_version.major}']
vm.register(
Expand Down Expand Up @@ -171,7 +195,7 @@ def cockpit_host(class_target_sat, class_org, rhel_contenthost):
@pytest.fixture
def rex_contenthost(request, module_org, target_sat, module_ak_with_cv):
request.param['no_containers'] = True
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
repo = settings.repos['SATCLIENT_REPO'][f'RHEL{host.os_version.major}']
host.register(
module_org, None, module_ak_with_cv.name, target_sat, repo_data=f'repo={repo}'
Expand All @@ -182,7 +206,7 @@ def rex_contenthost(request, module_org, target_sat, module_ak_with_cv):
@pytest.fixture
def rex_contenthosts(request, module_org, target_sat, module_ak_with_cv):
request.param['no_containers'] = True
with Broker(**host_conf(request), host_class=ContentHost, _count=2) as hosts:
with contenthost_factory(request=request, _count=2) as hosts:
for host in hosts:
repo = settings.repos['SATCLIENT_REPO'][f'RHEL{host.os_version.major}']
host.register(
Expand All @@ -193,8 +217,7 @@ def rex_contenthosts(request, module_org, target_sat, module_ak_with_cv):

@pytest.fixture
def katello_host_tools_tracer_host(rex_contenthost, target_sat):
"""Install katello-host-tools-tracer, create custom
repositories on the host"""
"""Install katello-host-tools-tracer, create custom repositories on the host"""
# create a custom, rhel version-specific OS repo
rhelver = rex_contenthost.os_version.major
if rhelver > 7:
Expand All @@ -215,7 +238,7 @@ def module_container_contenthost(request, module_target_sat, module_org, module_
"distro": "rhel",
"no_containers": True,
}
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
host.register_to_cdn()
for client in constants.CONTAINER_CLIENTS:
assert (
Expand All @@ -239,7 +262,7 @@ def centos_host(request, version):
"distro": "centos",
"no_containers": True,
}
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


Expand All @@ -250,16 +273,14 @@ def oracle_host(request, version):
"distro": "oracle",
"no_containers": True,
}
with Broker(**host_conf(request), host_class=ContentHost) as host:
with contenthost_factory(request=request) as host:
yield host


@pytest.fixture(scope='module', params=[{'rhel_version': 8, 'no_containers': True}])
def external_puppet_server(request):
deploy_args = host_conf(request)
deploy_args['target_cores'] = 2
deploy_args['target_memory'] = '4GiB'
with Broker(**deploy_args, host_class=ContentHost) as host:
request.param.update({'target_cores': 2, 'target_memory': '4GiB'})
with contenthost_factory(request=request) as host:
host.register_to_cdn()
# Install puppet packages
assert (
Expand Down Expand Up @@ -290,21 +311,18 @@ def external_puppet_server(request):


@pytest.fixture(scope="module")
def sat_upgrade_chost():
def sat_upgrade_chost(request): # This leaks! Be sure to clean up manually.
"""A module-level fixture that provides a UBI_8 content host for upgrade scenario testing"""
return Broker(
container_host=settings.content_host.rhel8.container.container_host, host_class=ContentHost
).checkout()
request.param = {"container_host": settings.content_host.ubi8.container.container_host}
return contenthost_factory(request=request)


@pytest.fixture
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 what's in content_host.yaml
deploy_args['deploy_rhel_version'] = deploy_args.get(
request.param['deploy_rhel_version'] = request.param.get(
'deploy_rhel_version', settings.content_host.default_rhel_version
)
deploy_args['workflow'] = 'deploy-rhel'
with Broker(**deploy_args, host_class=Satellite) as host:
request.param['workflow'] = 'deploy-rhel'
with contenthost_factory(request=request, host_class=Satellite) as host:
yield host
Loading