diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index 464ba7e41e4..2d1a78292f1 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -706,9 +706,28 @@ REPORT_TEMPLATE_FILE = 'report_template.txt' CONTAINER_REGISTRY_HUB = 'https://mirror.gcr.io' RH_CONTAINER_REGISTRY_HUB = 'https://registry.redhat.io/' +PULP_CONTAINER_REGISTRY_HUB = 'https://ghcr.io' CONTAINER_UPSTREAM_NAME = 'library/busybox' DOCKER_REPO_UPSTREAM_NAME = 'openshift3/logging-elasticsearch' CONTAINER_RH_REGISTRY_UPSTREAM_NAME = 'openshift3/ose-metrics-hawkular-openshift-agent' +BOOTABLE_REPO = { + 'upstream_name': 'pulp/bootc-labeled', + 'manifests_count': 1, + 'bootable': True, + 'flatpak': False, + 'labels_count': 2, + 'annotations_count': 2, +} +FLATPAK_REPO = { + 'upstream_name': 'pulp/oci-net.fishsoup.hello', + 'manifests_count': 2, + 'bootable': False, + 'flatpak': True, + 'labels_count': 10, + 'annotations_count': 0, +} +LABELLED_REPOS = [BOOTABLE_REPO, FLATPAK_REPO] +CONTAINER_MANIFEST_LABELS = {'annotations', 'labels', 'is_bootable', 'is_flatpak'} CONTAINER_CLIENTS = ['docker', 'podman'] CUSTOM_LOCAL_FOLDER = '/var/lib/pulp/imports/myrepo/' CUSTOM_LOCAL_FILE = '/var/lib/pulp/imports/myrepo/test.txt' diff --git a/tests/foreman/api/test_repository.py b/tests/foreman/api/test_repository.py index 5c946a5bc53..4dde7744e40 100644 --- a/tests/foreman/api/test_repository.py +++ b/tests/foreman/api/test_repository.py @@ -26,7 +26,12 @@ from robottelo import constants from robottelo.config import settings -from robottelo.constants import DataFile, repos as repo_constants +from robottelo.constants import ( + CONTAINER_MANIFEST_LABELS, + LABELLED_REPOS, + DataFile, + repos as repo_constants, +) from robottelo.content_info import get_repo_files_by_url from robottelo.logging import logger from robottelo.utils import datafactory @@ -1837,6 +1842,70 @@ def test_positive_synchronize_docker_repo_with_included_tags(self, repo_options, assert repo.include_tags == repo_options['include_tags'] assert repo.content_counts['docker_tag'] == 1 + @pytest.mark.tier2 + @pytest.mark.upgrade + @pytest.mark.parametrize( + 'repo_options', + **datafactory.parametrized( + [ + { + 'content_type': 'docker', + 'docker_upstream_name': item['upstream_name'], + 'name': gen_string('alpha'), + 'url': constants.PULP_CONTAINER_REGISTRY_HUB, + } + for item in LABELLED_REPOS + ] + ), + indirect=True, + ) + def test_positive_synchronize_docker_repo_with_manifest_labels( + self, target_sat, repo_options, repo + ): + """Verify the container manifest labels were indexed properly during the repo sync. + + :id: c865d350-fd19-43fb-b9fd-5ef86cbe3e09 + + :parametrized: yes + + :steps: + 1. Sync container-type repositories with some labels, annotations + and bootable and flatpak flags. + 2. Verify all manifests in each repo contain the expected keys. + 3. Verify the manifests count matches the repository content counts and the expectation. + 4. Verify the values meet the expectations specific for each repo. + + :expectedresults: Container labels were indexed properly. + """ + repo.sync() + repo = repo.read() + dms = target_sat.api.Repository(id=repo.id).docker_manifests()['results'] + assert all( + [CONTAINER_MANIFEST_LABELS.issubset(m.keys()) for m in dms] + ), 'Some expected key is missing in the repository manifests' + expected_values = next( + (i for i in LABELLED_REPOS if i['upstream_name'] == repo.docker_upstream_name), None + ) + assert expected_values, f'{repo.docker_upstream_name} not found in {LABELLED_REPOS}' + assert ( + len(dms) == repo.content_counts['docker_manifest'] + ), 'Manifests count does not match the repository content counts' + assert ( + len(dms) == expected_values['manifests_count'] + ), 'Manifests count does not meet the expectation' + assert all( + [m['is_bootable'] == expected_values['bootable'] for m in dms] + ), 'Unexpected is_bootable flag' + assert all( + [m['is_flatpak'] == expected_values['flatpak'] for m in dms] + ), 'Unexpected is_flatpak flag' + assert all( + [len(m['labels']) == expected_values['labels_count'] for m in dms] + ), 'Unexpected lables count' + assert all( + [len(m['annotations']) == expected_values['annotations_count'] for m in dms] + ), 'Unexpected annotations count' + @pytest.mark.skip( reason="Tests behavior that is no longer present in the same way, needs refactor" ) diff --git a/tests/upgrades/test_repository.py b/tests/upgrades/test_repository.py index ae8f672ab3f..ddb1d85345a 100644 --- a/tests/upgrades/test_repository.py +++ b/tests/upgrades/test_repository.py @@ -17,9 +17,12 @@ from robottelo import constants from robottelo.config import settings from robottelo.constants import ( + CONTAINER_MANIFEST_LABELS, DEFAULT_ARCHITECTURE, FAKE_0_CUSTOM_PACKAGE_NAME, FAKE_4_CUSTOM_PACKAGE_NAME, + LABELLED_REPOS, + PULP_CONTAINER_REGISTRY_HUB, REPOS, ) from robottelo.hosts import ContentHost @@ -375,6 +378,97 @@ def test_post_scenario_sync_large_repo(self, target_sat, pre_upgrade_data): assert res['result'] == 'success' +class TestScenarioContainerRepoSync: + """Scenario to verify that container repositories with labels, annotations and other flags + synced before upgrade are indexed properly after upgrade including labels (as of 6.16). + + Test Steps: + + 1. Before Satellite upgrade. + 2. Synchronize container repositories that contains some labels and other flags. + 3. Upgrade Satellite. + 4. Check the labels and other flags were indexed properly in Katello DB via API. + """ + + @pytest.mark.pre_upgrade + def test_pre_container_repo_sync( + self, + target_sat, + module_org, + module_product, + save_test_data, + ): + """This is a pre-upgrade test to sync container repositories + with some labels, annotations and bootable and flatpak flags. + + :id: 55b82217-7fd0-4b98-bd38-2a08a36f77db + + :steps: + 1. Create bootable container repository with some labels and flags. + 2. Sync the repository and assert sync succeeds. + 3. Create flatpak container repository with some labels and flags. + 4. Sync the repository and assert sync succeeds. + + :expectedresults: Container repositories are synced and ready for upgrade. + """ + repos = dict() + for item in LABELLED_REPOS: + repo = target_sat.api.Repository( + content_type='docker', + docker_upstream_name=item['upstream_name'], + product=module_product, + url=PULP_CONTAINER_REGISTRY_HUB, + ).create() + repo.sync() + repo = repo.read() + assert repo.content_counts['docker_manifest'] > 0 + repos[item['upstream_name']] = repo.id + save_test_data(repos) + + @pytest.mark.post_upgrade(depend_on=test_pre_container_repo_sync) + def test_post_container_repo_sync(self, target_sat, pre_upgrade_data): + """This is a post-upgrade test to verify the container labels + were indexed properly in the post-upgrade task. + + :id: 1e8f2f4a-6232-4671-9d6f-2ada1b70bc59 + + :steps: + 1. Verify all manifests in each repo contain the expected keys. + 2. Verify the manifests count matches the repository content counts and the expectation. + 3. Verify the values meet the expectations specific for each repo. + + :expectedresults: Container labels were indexed properly. + """ + for repo_id in pre_upgrade_data.values(): + repo = target_sat.api.Repository(id=repo_id).read() + dms = target_sat.api.Repository(id=repo_id).docker_manifests()['results'] + assert all( + [CONTAINER_MANIFEST_LABELS.issubset(m.keys()) for m in dms] + ), 'Some expected key is missing in the repository manifests' + expected_values = next( + (i for i in LABELLED_REPOS if i['upstream_name'] == repo.docker_upstream_name), None + ) + assert expected_values, f'{repo.docker_upstream_name} not found in {LABELLED_REPOS}' + assert ( + len(dms) == repo.content_counts['docker_manifest'] + ), 'Manifests count does not match the repository content counts' + assert ( + len(dms) == expected_values['manifests_count'] + ), 'Manifests count does not meet the expectation' + assert all( + [m['is_bootable'] == expected_values['bootable'] for m in dms] + ), 'Unexpected is_bootable flag' + assert all( + [m['is_flatpak'] == expected_values['flatpak'] for m in dms] + ), 'Unexpected is_flatpak flag' + assert all( + [len(m['labels']) == expected_values['labels_count'] for m in dms] + ), 'Unexpected lables count' + assert all( + [len(m['annotations']) == expected_values['annotations_count'] for m in dms] + ), 'Unexpected annotations count' + + class TestSimpleContentAccessOnly: """ The scenario to test simple content access mode before and after an upgrade to a