Skip to content

Commit

Permalink
test OS restrict repos
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Jan 23, 2025
1 parent 01b794d commit e383b19
Showing 1 changed file with 98 additions and 9 deletions.
107 changes: 98 additions & 9 deletions tests/foreman/api/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,30 +385,119 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel_conten
assert rhel_contenthost.subscribed


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_os_restriction_on_repos():
"""Verify that you can specify OS restrictions on custom repos
@pytest.mark.rhel_ver_match('[7,8,9]')
def test_positive_os_restriction_on_repos(
target_sat,
module_cv,
module_ak,
module_product,
rhel_contenthost,
module_sca_manifest_org,
):
"""Verify that you can specify OS restrictions on custom repos for registered host.
parametrized: (3) newest supported RHEL distro (N), and two prior.
:id: fd40842f-48c3-4505-a670-235d8a5f466b
:setup:
1. Create and sync 3 custom yum repositories
2. Add them to content-view and update
3. Register host and setup method (publish/promote CV and enable repos)
:steps:
1. Register Content Host with RHEL/EPEL 6 and 7 repos synced
2. Set Restriction to OS on repos
1. Check all repos enabled from start (unrestricted)
2. Set Restriction to OS (RHEL10/9/8) on each repo (hammer repository update)
3. Subscription-manager refresh
4. Verify enabled repos
4. Verify available repo(s) for content host using subscription-manager.
:expectedresults: Custom EPEL repos with OS restrictions set are
disabled based on its corresponding RHEL version
:expectedresults:
- One custom repo available for client, with matching OS restriction.
- Two custom repos not available for client, with non-matching OS restrictions.
:customerscenario: true
:BZ: 1526564
:CaseImportance: High
:CaseAutomation: NotAutomated
"""
org = module_sca_manifest_org
# 3 newest supported rhel versions from tail, exclude fips
'''rhel_versions = [
rhel_major_ver
for rhel_major_ver in settings.supportability.content_hosts.rhel.versions
if 'fips' not in str(rhel_major_ver)
][-3 :]'''
rhel_versions = ['7', '8', '9']
# create & sync 3 custom repositories
repo_urls = [settings.repos.yum_9.url, settings.repos.yum_6.url, settings.repos.yum_1.url]
custom_repos = []
for url in repo_urls:
r = target_sat.api.Repository(
url=url,
product=module_product,
).create()
r.sync()
custom_repos.append(r.read())
# add the repos to module CV
module_cv.repository = custom_repos
module_cv.update(['repository'])
module_cv = module_cv.read()
# publish CV, register host and enable repos
setup = target_sat.api_factory.register_host_and_needed_setup(
organization=org,
client=rhel_contenthost,
activation_key=module_ak,
environment='Library',
content_view=module_cv,
enable_repos=True,
)
assert setup['result'] != 'error', f'{setup["message"]}'
# registered host returned by setup
assert (client := setup['client'])
result = client.execute('subscription-manager refresh')
assert result.status == 0, f'{result.stdout}'

# get available repos from sub-man repos list
sub_man_repos = client.subscription_manager_list_repos().stdout
# assert all 3 repos are available at start (unrestricted)
for repo in custom_repos:
assert repo.label in sub_man_repos

# restrict each repo to a different RHEL major version
rhel_majors = [ver for ver in rhel_versions]
matching_repo_id = None
for r in custom_repos:
repo_rhel = rhel_majors[-1]
# restrict repo to OS via hammer, ie 'rhel-9'
formatted = 'rhel-' + str(repo_rhel)
result = target_sat.execute(
f'hammer repository update --os-versions "{formatted}"'
f' --id {r.id} --organization-id {org.id}'
)
assert result.status == 0, f'{result.stdout}'
rhel_majors.remove(repo_rhel)
# save repo_id with matching OS restrict to chost version,
# we expect this repo to remain available and enabled
if repo_rhel == str(client.os_version.major):
matching_repo_id = r.id

result = client.execute('subscription-manager refresh')
assert result.status == 0, f'{result.stdout}'
assert matching_repo_id, 'Expected one repository OS restriction, to match chost RHEL version'

enabled_repo_label = target_sat.api.Repository(id=matching_repo_id).read().label
assert enabled_repo_label in [repo.label for repo in custom_repos]
disabled_repos_labels = [
repo.label for repo in custom_repos if repo.label != enabled_repo_label
]
# enabled repo (1) with matching OS restriction is available from host's sub-man repos
sub_man_repos = client.subscription_manager_list_repos().stdout
assert enabled_repo_label in sub_man_repos
# repos (2) with differing OS, not available from sub-man repos list
for label in disabled_repos_labels:
assert label not in sub_man_repos


def test_positive_async_endpoint_for_manifest_refresh(target_sat, function_sca_manifest_org):
Expand Down

0 comments on commit e383b19

Please sign in to comment.