Skip to content

Commit

Permalink
Adding post upgrade test to upgrade scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeHiggins2 committed Mar 22, 2024
1 parent a6d8ff3 commit 29316d8
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 81 deletions.
149 changes: 149 additions & 0 deletions tests/upgrades/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""
import pytest

from robottelo import constants
from robottelo.config import settings
from robottelo.constants import (
DEFAULT_ARCHITECTURE,
Expand Down Expand Up @@ -371,3 +372,151 @@ def test_post_scenario_sync_large_repo(self, target_sat, pre_upgrade_data):
repo = target_sat.api.Repository(id=rh_repo_id).read()
res = repo.sync(timeout=4000)
assert res['result'] == 'success'


class TestSimpleContentAccessOnly:
"""
The scenario to test simple content access mode before and after an upgrade to a
satellite with simple content access mode only.
"""

@pytest.mark.rhel_ver_list([7, 8, 9])
@pytest.mark.no_containers
@pytest.mark.pre_upgrade
def test_pre_simple_content_access_only(
self,
target_sat,
save_test_data,
rhel_contenthost,
upgrade_entitlement_manifest_org,
upgrade_entitlement_manifest,
):
"""Register host with an activation key that has one custom repository(overriden to enabled)
and one red rat repository enabled but no subscriptions attached. Assert that only
the red hat repository is enabled on the host and that the host is in entitlement mode.
:id: preupgrade-d6661342-a348-4dd5-9ddf-3fd630b1e286
:steps:
1. Before satellite upgrade
2. Create new organization and location
3. Upload a manifest in it
4. Create a ak with repos and no subscriptions added in it
5. Create a content host
6. Register the content host
7. Confirm content host only has red hat repo enabled
8. Confirm content host is in entitlement mode
:expectedresults:
1. Content host is registered in entitlement mode and has only the red hat repository
enabled on host.
"""
_, manifester = upgrade_entitlement_manifest
org = upgrade_entitlement_manifest_org
rhel_contenthost._skip_context_checkin = True
lce = target_sat.api.LifecycleEnvironment(organization=org).create()
product = target_sat.api.Product(organization=org).create()
custom_repo = target_sat.api.Repository(
content_type='yum', product=product, url=settings.repos.module_stream_1.url
).create()
custom_repo.sync()
if rhel_contenthost.os_version.major > 7:
rh_repo_id = target_sat.api_factory.enable_sync_redhat_repo(
constants.REPOS[f'rhel{rhel_contenthost.os_version.major}_bos'], org.id
)
else:
rh_repo_id = target_sat.api_factory.enable_sync_redhat_repo(
constants.REPOS[f'rhel{rhel_contenthost.os_version.major}'], org.id
)
rh_repo = target_sat.api.Repository(id=rh_repo_id).read()
assert rh_repo.content_counts['rpm'] >= 1
repo_list = [custom_repo, rh_repo]
content_view = target_sat.publish_content_view(org, repo_list)
content_view.version[-1].promote(data={'environment_ids': lce.id})
subscription = target_sat.api.Subscription(organization=org.id).search(
query={'search': f'name="{constants.DEFAULT_SUBSCRIPTION_NAME}"'}
)
assert len(subscription)
activation_key = target_sat.api.ActivationKey(
content_view=content_view,
organization=org,
environment=lce,
).create()
all_content = activation_key.product_content(data={'content_access_mode_all': '1'})[
'results'
]
for content in all_content:
if content['name'] == custom_repo.name:
custom_content_label = content['label']
if content['repositories'][0]['id'] == rh_repo_id:
rh_content_label = content['label']
activation_key.content_override(
data={'content_overrides': [{'content_label': custom_content_label, 'value': '1'}]}
)
rhel_contenthost.install_katello_ca(target_sat)
rhel_contenthost.register_contenthost(org=org.name, activation_key=activation_key.name)
enabled = rhel_contenthost.execute("subscription-manager repos --list-enabled")
assert rh_content_label in enabled.stdout
assert custom_content_label not in enabled.stdout
sca_access = target_sat.execute(
f'echo "Organization.find({org.id}).simple_content_access?" | foreman-rake console'
)
assert 'false' in sca_access.stdout
sca_mode = target_sat.execute(
f'echo "Organization.find({org.id}).content_access_mode" | foreman-rake console'
)
assert 'entitlement' in sca_mode.stdout
sca_list = target_sat.execute(
f'echo "Organization.find({org.id}).content_access_mode_list" | foreman-rake console'
)
assert 'entitlement' in sca_list.stdout
assert rhel_contenthost.subscribed
save_test_data(
{
'rhel_client': rhel_contenthost.hostname,
'org_id': org.id,
'rh_content_label': rh_content_label,
'custom_content_label': custom_content_label,
}
)

@pytest.mark.parametrize('pre_upgrade_data', ['rhel7', 'rhel8', 'rhel9'], indirect=True)
@pytest.mark.post_upgrade(depend_on=test_pre_simple_content_access_only)
def test_post_simple_content_access_only(self, target_sat, pre_upgrade_data):
"""Check that both the custom repository and the red hat repository are enabled
and that the host is in simple content access mode.
:id: postupgrade-6b418042-7bd7-40a6-9307-149614cc2672
:steps:
1. After satellite upgrade
2. Confirm host has both custom and red hat repository enabled
3. Confirm host is in simple content access mode
:expectedresults:
1. Content host is now in simple content access mode and custom repository
is enabled on host.
"""
client_hostname = pre_upgrade_data.get('rhel_client')
org_id = pre_upgrade_data.get('org_id')
rh_content_label = pre_upgrade_data.get('rh_content_label')
custom_content_label = pre_upgrade_data.get('custom_content_label')
rhel_client = ContentHost.get_host_by_hostname(client_hostname)
enabled = rhel_client.execute("subscription-manager repos --list-enabled")
assert rh_content_label in enabled.stdout
assert custom_content_label in enabled.stdout
sca_access = target_sat.execute(
f'echo "Organization.find({org_id}).simple_content_access?" | foreman-rake console'
)
assert 'True' in sca_access.stdout
sca_mode = target_sat.execute(
f'echo "Organization.find({org_id}).content_access_mode" | foreman-rake console'
)
assert 'entitlement' not in sca_mode.stdout
assert 'org_environment' in sca_mode.stdout
sca_list = target_sat.execute(
f'echo "Organization.find({org_id}).content_access_mode_list" | foreman-rake console'
)
assert 'entitlement' not in sca_list.stdout
assert 'org_environment' in sca_mode.stdout
81 changes: 0 additions & 81 deletions tests/upgrades/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,84 +175,3 @@ def test_post_subscription_scenario_auto_attach(self, request, target_sat, pre_u
manifester = Manifester(manifest_category=settings.manifest.entitlement)
request.addfinalizer(manifester.delete_subscription_allocation)
manifester.allocation_uuid = pre_upgrade_data.allocation_uuid

@pytest.mark.rhel_ver_list([7, 8, 9])
@pytest.mark.no_containers
@pytest.mark.pre_upgrade
def test_pre_sca_only(
self,
target_sat,
save_test_data,
rhel_contenthost,
upgrade_entitlement_manifest_org,
upgrade_entitlement_manifest,
):
""" """
_, manifester = upgrade_entitlement_manifest
org = upgrade_entitlement_manifest_org
rhel_contenthost._skip_context_checkin = True
lce = target_sat.api.LifecycleEnvironment(organization=org).create()
product = target_sat.api.Product(organization=org).create()
custom_repo = target_sat.api.Repository(
content_type='yum', product=product, url=settings.repos.module_stream_1.url
).create()
custom_repo.sync()
if rhel_contenthost.os_version.major > 7:
rh_repo_id = target_sat.api_factory.enable_sync_redhat_repo(
constants.REPOS[f'rhel{rhel_contenthost.os_version.major}_bos'], org.id
)
else:
rh_repo_id = target_sat.api_factory.enable_sync_redhat_repo(
constants.REPOS[f'rhel{rhel_contenthost.os_version.major}'], org.id
)
rh_repo = target_sat.api.Repository(id=rh_repo_id).read()
assert rh_repo.content_counts['rpm'] >= 1
repo_list = [custom_repo, rh_repo]
content_view = target_sat.publish_content_view(org, repo_list)
content_view.version[-1].promote(data={'environment_ids': lce.id})
subscription = target_sat.api.Subscription(organization=org.id).search(
query={'search': f'name="{constants.DEFAULT_SUBSCRIPTION_NAME}"'}
)
assert len(subscription)
activation_key = target_sat.api.ActivationKey(
content_view=content_view,
organization=org,
environment=lce,
).create()
all_content = activation_key.product_content(data={'content_access_mode_all': '1'})[
'results'
]
for content in all_content:
if content['name'] == custom_repo.name:
custom_content_label = content['label']
if content['repositories'][0]['id'] == rh_repo_id:
rh_content_label = content['label']
activation_key.content_override(
data={'content_overrides': [{'content_label': custom_content_label, 'value': '1'}]}
)
rhel_contenthost.install_katello_ca(target_sat)
rhel_contenthost.register_contenthost(org=org.name, activation_key=activation_key.name)
enabled = rhel_contenthost.execute("subscription-manager repos --list-enabled")
assert rh_content_label in enabled.stdout
sca_access = target_sat.execute(
f'echo "Organization.find({org.id}).simple_content_access?" | foreman-rake console'
)
assert 'false' in sca_access.stdout
sca_mode = target_sat.execute(
f'echo "Organization.find({org.id}).content_access_mode" | foreman-rake console'
)
assert 'entitlement' in sca_mode.stdout
sca_list = target_sat.execute(
f'echo "Organization.find({org.id}).content_access_mode_list" | foreman-rake console'
)
assert 'entitlement' in sca_list.stdout
assert rhel_contenthost.subscribed
save_test_data(
{
'rhel_client': rhel_contenthost.hostname,
'org_id': org.id,
'activation_key': activation_key.name,
'rh_repo': rh_repo.name,
'custom_repo': custom_repo.name,
}
)

0 comments on commit 29316d8

Please sign in to comment.