Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgrade scenario test for docker manifest indexing #15263

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
71 changes: 70 additions & 1 deletion tests/foreman/api/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand Down
94 changes: 94 additions & 0 deletions tests/upgrades/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down