Skip to content

Commit

Permalink
Make "default_sat" fixture usage more cooperative
Browse files Browse the repository at this point in the history
In this change, I replace all current usage of the default_sat fixture
with a new target_sat fixture. This new fixture can provide the original
default_sat object as well as dynamically provision new Satellite
instances when needed. This is initially used to replace all uses of the
destructive_sat fixture to also use the new target_sat. It achieves this
by looking for the destructive marker; when attached to a downstream
test, all fixtures in the chain will then use the destructive target_sat
instance.
Other satellite types (like fips) could be similarly controlled in this
way.
  • Loading branch information
JacobCallahan authored and mshriver committed May 19, 2022
1 parent 39a67f0 commit 9e047de
Show file tree
Hide file tree
Showing 126 changed files with 1,372 additions and 1,358 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ jobs:
- name: Collect Tests with xdist
run: |
pytest --collect-only --disable-pytest-warnings -n 2 tests/foreman/ tests/robottelo/
pytest --collect-only --disable-pytest-warnings -n 2 -m pre_upgrade tests/upgrades/
pytest --collect-only --disable-pytest-warnings -n 2 -m post_upgrade tests/upgrades/
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 tests/foreman/ tests/robottelo/
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 -m pre_upgrade tests/upgrades/
pytest --collect-only --setup-plan --disable-pytest-warnings -n 2 -m post_upgrade tests/upgrades/
- name: Make Docs
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ tests/foreman/pytest.ini
/settings.local.yaml
/settings*.local.yaml
/conf/*.yaml
/conf/*.conf
!/conf/supportability.yaml

# I don't know where those 2 files come from
Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


@pytest.fixture(scope='session')
def default_domain(default_sat, default_smart_proxy):
domain_name = default_sat.hostname.partition('.')[-1]
def default_domain(session_target_sat, default_smart_proxy):
domain_name = session_target_sat.hostname.partition('.')[-1]
dom = entities.Domain().search(query={'search': f'name={domain_name}'})[0]
dom.dns = default_smart_proxy
dom.update(['dns'])
Expand Down
8 changes: 4 additions & 4 deletions pytest_fixtures/component/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@


@pytest.fixture(scope="session")
def tailoring_file_path(default_sat):
def tailoring_file_path(session_target_sat):
"""Return Tailoring file path."""
local = get_data_file(OSCAP_TAILORING_FILE)
default_sat.put(
session_target_sat.put(
local_path=get_data_file(OSCAP_TAILORING_FILE),
remote_path=f'/tmp/{OSCAP_TAILORING_FILE}',
)
return {'local': local, 'satellite': f'/tmp/{OSCAP_TAILORING_FILE}'}


@pytest.fixture(scope="session")
def oscap_content_path(default_sat):
def oscap_content_path(session_target_sat):
"""Download scap content from satellite and return local path of it."""
local_file = robottelo_tmp_dir.joinpath(PurePath(settings.oscap.content_path).name)
default_sat.get(remote_path=settings.oscap.content_path, local_path=local_file)
session_target_sat.get(remote_path=settings.oscap.content_path, local_path=local_file)
return local_file


Expand Down
24 changes: 12 additions & 12 deletions pytest_fixtures/component/provision_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def azurerm_settings():


@pytest.fixture(scope='module')
def module_azurerm_cr(azurerm_settings, module_org, module_location, default_sat):
def module_azurerm_cr(azurerm_settings, module_org, module_location, module_target_sat):
"""Create AzureRM Compute Resource"""
azure_cr = default_sat.api.AzureRMComputeResource(
azure_cr = module_target_sat.api.AzureRMComputeResource(
name=gen_string('alpha'),
provider='AzureRm',
tenant=azurerm_settings['tenant'],
Expand Down Expand Up @@ -64,11 +64,11 @@ def module_azurerm_cr_puppet(
def module_azurerm_finishimg(
default_architecture,
default_os,
default_sat,
module_target_sat,
module_azurerm_cr,
):
"""Creates Finish Template image on AzureRM Compute Resource"""
finish_image = default_sat.api.Image(
finish_image = module_target_sat.api.Image(
architecture=default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand Down Expand Up @@ -103,10 +103,10 @@ def module_azurerm_byos_finishimg(
default_architecture,
default_os,
module_azurerm_cr,
default_sat,
module_target_sat,
):
"""Creates BYOS Finish Template image on AzureRM Compute Resource"""
finish_image = default_sat.api.Image(
finish_image = module_target_sat.api.Image(
architecture=default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand Down Expand Up @@ -140,11 +140,11 @@ def module_azurerm_byos_finishimg_puppet(
def module_azurerm_cloudimg(
default_architecture,
default_os,
default_sat,
module_target_sat,
module_azurerm_cr,
):
"""Creates cloudinit image on AzureRM Compute Resource"""
finish_image = default_sat.api.Image(
finish_image = module_target_sat.api.Image(
architecture=default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand Down Expand Up @@ -180,11 +180,11 @@ def module_azurerm_cloudimg_puppet(
def module_azurerm_gallery_finishimg(
default_architecture,
default_os,
default_sat,
module_target_sat,
module_azurerm_cr,
):
"""Creates Shared Gallery Finish Template image on AzureRM Compute Resource"""
finish_image = default_sat.api.Image(
finish_image = module_target_sat.api.Image(
architecture=default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand Down Expand Up @@ -218,11 +218,11 @@ def module_azurerm_gallery_finishimg_puppet(
def module_azurerm_custom_finishimg(
default_architecture,
default_os,
default_sat,
module_target_sat,
module_azurerm_cr,
):
"""Creates Custom Finish Template image on AzureRM Compute Resource"""
finish_image = default_sat.api.Image(
finish_image = module_target_sat.api.Image(
architecture=default_architecture,
compute_resource=module_azurerm_cr,
name=gen_string('alpha'),
Expand Down
6 changes: 3 additions & 3 deletions pytest_fixtures/component/provision_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@


@pytest.fixture(scope='session')
def gce_cert(default_sat):
def gce_cert(session_target_sat):
_, gce_cert_file = mkstemp(suffix='.json')
cert = json.loads(settings.gce.cert)
cert['local_path'] = gce_cert_file
with open(gce_cert_file, 'w') as f:
json.dump(cert, f)
default_sat.put(gce_cert_file, settings.gce.cert_path)
if default_sat.execute(f'[ -f {settings.gce.cert_path} ]').status != 0:
session_target_sat.put(gce_cert_file, settings.gce.cert_path)
if session_target_sat.execute(f'[ -f {settings.gce.cert_path} ]').status != 0:
raise GCECertNotFoundError(
f"The GCE certificate in path {settings.gce.cert_path} is not found in satellite."
)
Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def module_puppet_classes(


@pytest.fixture(scope='session', params=[True, False], ids=["puppet_enabled", "puppet_disabled"])
def parametrized_puppet_sat(request, default_sat, session_puppet_enabled_sat):
def parametrized_puppet_sat(request, session_target_sat, session_puppet_enabled_sat):
if request.param:
sat = session_puppet_enabled_sat
else:
sat = default_sat
sat = session_target_sat
return {'sat': sat, 'enabled': request.param}


Expand Down
20 changes: 10 additions & 10 deletions pytest_fixtures/component/satellite_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,37 +251,37 @@ def enroll_configure_rhsso_external_auth():


@pytest.fixture(scope='session')
def enable_external_auth_rhsso(enroll_configure_rhsso_external_auth, default_sat):
def enable_external_auth_rhsso(enroll_configure_rhsso_external_auth, session_target_sat):
"""register the satellite with RH-SSO Server for single sign-on"""
client_id = get_rhsso_client_id()
create_mapper(GROUP_MEMBERSHIP_MAPPER, client_id)
audience_mapper = copy.deepcopy(AUDIENCE_MAPPER)
audience_mapper['config']['included.client.audience'] = audience_mapper['config'][
'included.client.audience'
].format(rhsso_host=default_sat)
].format(rhsso_host=session_target_sat)
create_mapper(audience_mapper, client_id)
set_the_redirect_uri()


@pytest.mark.external_auth
@pytest.fixture(scope='session')
def enroll_idm_and_configure_external_auth(default_sat):
def enroll_idm_and_configure_external_auth(session_target_sat):
"""Enroll the Satellite6 Server to an IDM Server."""
ipa_host = ContentHost(settings.ipa.hostname)
default_sat.execute(
session_target_sat.execute(
'yum -y --disableplugin=foreman-protector install ipa-client ipa-admintools'
)
ipa_host.execute(f'echo {settings.ipa.password} | kinit admin')
output = default_sat.execute(f'ipa host-find {default_sat.hostname}')
output = session_target_sat.execute(f'ipa host-find {session_target_sat.hostname}')
if output.status != 0:
result = ipa_host.execute(f'ipa host-add --random {default_sat.hostname}')
result = ipa_host.execute(f'ipa host-add --random {session_target_sat.hostname}')
for line in result.stdout.splitlines():
if 'Random password' in line:
_, password = line.split(': ', 2)
break
ipa_host.execute(f'ipa service-add HTTP/{default_sat.hostname}')
ipa_host.execute(f'ipa service-add HTTP/{session_target_sat.hostname}')
_, domain = settings.ipa.hostname.split('.', 1)
result = default_sat.execute(
result = session_target_sat.execute(
f"ipa-client-install --password '{password}' "
f'--domain {domain} '
f'--server {settings.ipa.hostname} '
Expand Down Expand Up @@ -312,15 +312,15 @@ def configure_realm():


@pytest.fixture()
def rhsso_setting_setup(destructive_sat, request):
def rhsso_setting_setup(target_sat, request):
"""Update the RHSSO setting and revert it in cleanup"""
update_rhsso_settings_in_satellite()
yield
update_rhsso_settings_in_satellite(revert=True)


@pytest.fixture()
def rhsso_setting_setup_with_timeout(destructive_sat, rhsso_setting_setup, request):
def rhsso_setting_setup_with_timeout(target_sat, rhsso_setting_setup, request):
"""Update the RHSSO setting with timeout setting and revert it in cleanup"""
setting_entity = entities.Setting().search(query={'search': 'name=idle_timeout'})[0]
setting_entity.value = 1
Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/smartproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def import_puppet_classes(default_smart_proxy):


@pytest.fixture(scope='module')
def module_fake_proxy(request, default_sat):
def module_fake_proxy(request, module_target_sat):
"""Create a Proxy and register the cleanup function"""
args = {'name': gen_string(str_type='alpha')}
newport = get_available_capsule_port()
try:
with default_url_on_new_port(9090, newport) as url:
args['url'] = url
proxy = default_sat.api.SmartProxy(**args).create()
proxy = module_target_sat.api.SmartProxy(**args).create()
yield proxy
capsule_cleanup(proxy.id)
except CapsuleTunnelError as err:
Expand Down
26 changes: 14 additions & 12 deletions pytest_fixtures/component/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@


@pytest.fixture(scope='session')
def clean_rhsm(default_sat):
def clean_rhsm(session_target_sat):
"""removes pre-existing candlepin certs and resets RHSM."""
default_sat.remove_katello_ca()
session_target_sat.remove_katello_ca()


@pytest.fixture(scope='module')
def subscribe_satellite(clean_rhsm, default_sat):
def subscribe_satellite(clean_rhsm, module_target_sat):
"""subscribe satellite to cdn"""
from robottelo.config import settings

if default_sat.os_version.major < 8:
release_version = f'{default_sat.os_version.major}Server'
if module_target_sat.os_version.major < 8:
release_version = f'{module_target_sat.os_version.major}Server'
else:
release_version = f'{default_sat.os_version.major}'
default_sat.register_contenthost(
release_version = f'{module_target_sat.os_version.major}'
module_target_sat.register_contenthost(
org=None,
lce=None,
username=settings.subscription.rhn_username,
password=settings.subscription.rhn_password,
releasever=release_version,
)
result = default_sat.subscription_manager_attach_pool([settings.subscription.rhn_poolid])[0]
result = module_target_sat.subscription_manager_attach_pool([settings.subscription.rhn_poolid])[
0
]
if 'Successfully attached a subscription' in result.stdout:
default_sat.enable_repo(
f'rhel-{default_sat.os_version.major}-server-extras-rpms', force=True
module_target_sat.enable_repo(
f'rhel-{module_target_sat.os_version.major}-server-extras-rpms', force=True
)
yield
else:
pytest.fail('Failed to attach system to pool. Aborting Test!.')
default_sat.unregister()
default_sat.remove_katello_ca()
module_target_sat.unregister()
module_target_sat.remove_katello_ca()
6 changes: 4 additions & 2 deletions pytest_fixtures/component/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ def module_gt_manifest_org():


@pytest.fixture(scope='module')
def smart_proxy_location(module_org, default_sat):
def smart_proxy_location(module_org, module_target_sat):
location = entities.Location(organization=[module_org]).create()
smart_proxy = (
entities.SmartProxy().search(query={'search': f'name={default_sat.hostname}'})[0].read()
entities.SmartProxy()
.search(query={'search': f'name={module_target_sat.hostname}'})[0]
.read()
)
smart_proxy.location.append(entities.Location(id=location.id))
smart_proxy.update(['location'])
Expand Down
24 changes: 13 additions & 11 deletions pytest_fixtures/component/templatesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.fixture()
def create_import_export_local_dir(default_sat):
def create_import_export_local_dir(target_sat):
"""Creates a local directory inside root_dir on satellite from where the templates will
be imported from or exported to.
Expand All @@ -20,7 +20,7 @@ def create_import_export_local_dir(default_sat):
root_dir = FOREMAN_TEMPLATE_ROOT_DIR
dir_path = f'{root_dir}/{dir_name}'
# Creating the directory and set the write context
result = default_sat.execute(
result = target_sat.execute(
f'mkdir -p {dir_path} && '
f'chown foreman -R {root_dir} && '
f'restorecon -R -v {root_dir} && '
Expand All @@ -33,25 +33,27 @@ def create_import_export_local_dir(default_sat):
f"Failed to create local dir or set SELinux context. Error output: {result.stderr}"
)
# Copying the file to new directory to be modified by tests
default_sat.execute(f'cp example_template.erb {dir_path}')
target_sat.execute(f'cp example_template.erb {dir_path}')
yield dir_name, dir_path
default_sat.execute(f'rm -rf {dir_path}')
target_sat.execute(f'rm -rf {dir_path}')


@pytest.fixture(scope='session')
def git_port(default_sat):
def git_port(session_target_sat):
"""Allow port for git service"""
default_sat.execute(f'semanage port -a -t http_port_t -p tcp {settings.git.http_port}')
default_sat.execute(f'semanage port -a -t ssh_port_t -p tcp {settings.git.ssh_port}')
session_target_sat.execute(f'semanage port -a -t http_port_t -p tcp {settings.git.http_port}')
session_target_sat.execute(f'semanage port -a -t ssh_port_t -p tcp {settings.git.ssh_port}')


@pytest.fixture(scope='session')
def git_pub_key(default_sat, git_port):
def git_pub_key(session_target_sat, git_port):
"""Copy ssh public key to git service"""
git = settings.git
key_path = '/usr/share/foreman/.ssh'
default_sat.execute(f'sudo -u foreman ssh-keygen -q -t rsa -f {key_path}/id_rsa -N "" <<<y')
key = default_sat.execute(f'cat {key_path}/id_rsa.pub').stdout.strip()
session_target_sat.execute(
f'sudo -u foreman ssh-keygen -q -t rsa -f {key_path}/id_rsa -N "" <<<y'
)
key = session_target_sat.execute(f'cat {key_path}/id_rsa.pub').stdout.strip()
title = gen_string('alpha')
auth = (git.username, git.password)
url = f'http://{git.hostname}:{git.http_port}'
Expand All @@ -63,7 +65,7 @@ def git_pub_key(default_sat, git_port):
res.raise_for_status()
id = res.json()['id']
# add ssh key to known host
default_sat.execute(
session_target_sat.execute(
f'ssh-keyscan -t rsa -p {git.ssh_port} {git.hostname} > {key_path}/known_hosts'
)
yield
Expand Down
Loading

0 comments on commit 9e047de

Please sign in to comment.