diff --git a/tests/upgrades/test_repository.py b/tests/upgrades/test_repository.py index 9b4de62f02f..ae8f672ab3f 100644 --- a/tests/upgrades/test_repository.py +++ b/tests/upgrades/test_repository.py @@ -14,6 +14,7 @@ import pytest +from robottelo import constants from robottelo.config import settings from robottelo.constants import ( DEFAULT_ARCHITECTURE, @@ -372,3 +373,150 @@ 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, + ): + """Register host with an activation key that has one custom repository(overriden to enabled) + and one Red Hat 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 to 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. + + """ + 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.register( + org=org, loc=None, activation_keys=activation_key.name, target=target_sat + ) + 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