Skip to content

Commit

Permalink
Repair setup for swidtag testing
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Mar 22, 2024
1 parent 1bfd367 commit dea50d9
Showing 1 changed file with 85 additions and 34 deletions.
119 changes: 85 additions & 34 deletions tests/foreman/api/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,6 @@ def _set_prerequisites_for_swid_repos(vm):
f'curl --insecure --remote-name {settings.repos.swid_tools_repo}', vm
)
_run_remote_command_on_content_host('mv *swid*.repo /etc/yum.repos.d', vm)
_run_remote_command_on_content_host(r'subscription-manager repos --enable \*', vm)
_run_remote_command_on_content_host('yum install -y swid-tools', vm)
_run_remote_command_on_content_host('yum install -y dnf-plugin-swidtags', vm)

Expand All @@ -1368,14 +1367,13 @@ def _validate_swid_tags_installed(vm, module_name):
@pytest.mark.tier3
@pytest.mark.upgrade
@pytest.mark.pit_client
@pytest.mark.parametrize(
'function_repos_collection_with_manifest',
[{'YumRepository': {'url': settings.repos.swid_tag.url, 'distro': 'rhel8'}}],
indirect=True,
)
@pytest.mark.no_containers
def test_errata_installation_with_swidtags(
function_repos_collection_with_manifest, rhel8_contenthost, target_sat
module_sca_manifest_org,
module_lce,
module_cv,
rhel8_contenthost,
target_sat,
):
"""Verify errata installation with swid_tags and swid tags get updated after
module stream update.
Expand All @@ -1384,15 +1382,18 @@ def test_errata_installation_with_swidtags(
:steps:
1. create product and repository having swid tags
2. create content view and published it with repository
3. create activation key and register content host
4. create rhel8, swid repos on content host
5. install swid-tools, dnf-plugin-swidtags packages on content host
6. install older module stream and generate errata, swid tag
7. assert errata count, swid tags are generated
8. install errata vis updating module stream
9. assert errata count and swid tag after module update
1. promote empty content view and create activation key
2. create product and repository having swid tags
3. create rhel8, swid repos on content host
4. create custom repo with applicable module stream packages
5. associate repositories and cv / ak to contenthost, sync all content
6. publish & promote content view version with all content
7. register host using cv's activation key
8. install swid-tools, dnf-plugin-swidtags packages on content host
9. install older module stream and generate errata, swid tag
10. assert errata count, swid tags are generated
11. install errata via updating module stream
12. assert errata count and swid tag changed after module update
:expectedresults: swid tags should get updated after errata installation via
module stream update
Expand All @@ -1406,22 +1407,68 @@ def test_errata_installation_with_swidtags(
"""
module_name = 'kangaroo'
version = '20180704111719'
# setup base_rhel8 and sat_tools repos
rhel8_contenthost.create_custom_repos(
**{
'baseos': settings.repos.rhel8_os.baseos,
'appstream': settings.repos.rhel8_os.appstream,
}
# new cv version for ak
cv_publish_promote(
target_sat,
module_sca_manifest_org,
module_cv,
module_lce,
)
function_repos_collection_with_manifest.setup_virtual_machine(rhel8_contenthost)

# install older module stream
_ak = target_sat.api.ActivationKey(
organization=module_sca_manifest_org,
environment=module_lce,
content_view=module_cv,
).create()
# needed repos for module stream, swid tags, prereqs
_repos = {
'base_os': settings.repos.rhel8_os.baseos,
'sat_tools': settings.repos.rhel8_os.appstream,
'swid_tags': settings.repos.swid_tag.url,
}
# associate repos with host, org, lce, and sync
rhel8_contenthost.create_custom_repos(**_repos)
for _key in _repos:
target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': _repos[_key],
'name': _key,
'organization-id': module_sca_manifest_org.id,
'lifecycle-environment-id': module_lce.id,
'activationkey-id': _ak.id,
},
)
# promote new version with all repos/content
cv_publish_promote(
target_sat,
module_sca_manifest_org,
module_cv,
module_lce,
)
# register host with ak, succeeds
result = rhel8_contenthost.register(
activation_keys=_ak.name,
target=target_sat,
org=module_sca_manifest_org,
loc=None,
)
assert result.status == 0, f'Failed to register the host {target_sat.hostname},\n{result}'
rhel8_contenthost.add_rex_key(satellite=target_sat)
assert (
rhel8_contenthost.subscribed
), f'Failed to subscribe the host {target_sat.hostname}, to content.'
rhel8_contenthost.install_katello_ca(target_sat)
result = rhel8_contenthost.execute(r'subscription-manager repos --enable \*')
assert result.status == 0, f'Failed to enable repositories with subscription-manager,\n{result}'

# install outdated module stream package
_set_prerequisites_for_swid_repos(rhel8_contenthost)
_run_remote_command_on_content_host(
f'dnf -y module install {module_name}:0:{version}', rhel8_contenthost
)
target_sat.cli.Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
result = rhel8_contenthost.execute(f'dnf -y module install {module_name}:0:{version}')
assert (
result.status == 0
), f'Failed to install module stream package: {module_name}:0:{version}.\n{result.stdout}'
# recalculate errata after install of old module stream
rhel8_contenthost.execute('subscription-manager repos')

# validate swid tags Installed
before_errata_apply_result = _run_remote_command_on_content_host(
f"swidq -i -n {module_name} | grep 'File' | grep -o 'rpm-.*.swidtag'",
Expand All @@ -1432,18 +1479,22 @@ def test_errata_installation_with_swidtags(
assert (applicable_errata_count := rhel8_contenthost.applicable_errata_count) == 1

# apply modular errata
_run_remote_command_on_content_host(f'dnf -y module update {module_name}', rhel8_contenthost)
_run_remote_command_on_content_host('dnf -y upload-profile', rhel8_contenthost)
target_sat.cli.Host.errata_recalculate({'host-id': rhel8_contenthost.nailgun_host.id})
result = rhel8_contenthost.execute(f'dnf -y module update {module_name}')
assert (
result.status == 0
), f'Failed to updated module stream package: {module_name}.\n{result.stdout}'
assert rhel8_contenthost.execute('dnf -y upload-profile').status == 0

# recalculate and check errata after modular update
rhel8_contenthost.execute('subscription-manager repos')
applicable_errata_count -= 1
assert rhel8_contenthost.applicable_errata_count == applicable_errata_count
# swidtags were updated based on package version
after_errata_apply_result = _run_remote_command_on_content_host(
f"swidq -i -n {module_name} | grep 'File'| grep -o 'rpm-.*.swidtag'",
f"swidq -i -n {module_name} | grep 'File' | grep -o 'rpm-.*.swidtag'",
rhel8_contenthost,
return_result=True,
)
# swidtags get updated based on package version
assert before_errata_apply_result != after_errata_apply_result


Expand Down

0 comments on commit dea50d9

Please sign in to comment.