Skip to content

Commit

Permalink
Add repo sync test for docker manifest indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Jun 3, 2024
1 parent d13b042 commit 09f2f27
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 55 deletions.
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': repo['upstream_name'],
'name': gen_string('alpha'),
'url': constants.PULP_CONTAINER_REGISTRY_HUB,
}
for repo 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
97 changes: 43 additions & 54 deletions tests/upgrades/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

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,7 +378,7 @@ def test_post_scenario_sync_large_repo(self, target_sat, pre_upgrade_data):


class TestScenarioContainerRepoSync:
"""Scenario to verify that container repositories with labels, annotations and othe flages
"""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:
Expand Down Expand Up @@ -407,29 +410,19 @@ def test_pre_container_repo_sync(
:expectedresults: Container repositories are synced and ready for upgrade.
"""
# Create and sync bootable container repository with some labels and flags.
bootable_repo = target_sat.api.Repository(
content_type='docker',
docker_upstream_name='pulp/bootc-labeled',
product=module_product,
url='https://ghcr.io',
).create()
bootable_repo.sync()
bootable_repo = bootable_repo.read()
assert bootable_repo.content_counts['docker_manifest'] > 0

# Create and sync flatpak container repository with some labels and flags.
flatpak_repo = target_sat.api.Repository(
content_type='docker',
docker_upstream_name='pulp/oci-net.fishsoup.hello',
product=module_product,
url='https://ghcr.io',
).create()
flatpak_repo.sync()
flatpak_repo = flatpak_repo.read()
assert flatpak_repo.content_counts['docker_manifest'] > 0

save_test_data({'boot_repo_id': bootable_repo.id, 'flatpak_repo_id': flatpak_repo.id})
repos = dict()
for model in LABELLED_REPOS:
repo = target_sat.api.Repository(
content_type='docker',
docker_upstream_name=model['upstream_name'],
product=module_product,
url=PULP_CONTAINER_REGISTRY_HUB,
).create()
repo.sync()
repo = repo.read()
assert repo.content_counts['docker_manifest'] > 0
repos[model['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):
Expand All @@ -439,41 +432,37 @@ def test_post_container_repo_sync(self, target_sat, pre_upgrade_data):
:id: 1e8f2f4a-6232-4671-9d6f-2ada1b70bc59
:steps:
1. Verify the manifests count matches the repository content counts
and ensure all manifests in each repo contain the expected keys.
2. Verify the vaules meet the expectations specific for each repo.
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.
"""
# Verify the manifests count matches the repository content counts
# and ensure all manifests in each repo contain the expected keys.
expected_keys = {'annotations', 'labels', 'is_bootable', 'is_flatpak'}
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)
== target_sat.api.Repository(id=repo_id).read().content_counts['docker_manifest']
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(
[expected_keys.issubset(m.keys()) for m in dms]
), 'Some expected key is missing in the repository manifests'

# Verify the vaules meet the expectations specific for the bootable repo.
dms = target_sat.api.Repository(id=pre_upgrade_data.boot_repo_id).docker_manifests()[
'results'
]
assert len(dms) == 1, 'Expected 1 manifest in the repo'
assert dms[0]['is_bootable'], 'Expected is_bootable flag set to True'
assert not dms[0]['is_flatpak'], 'Expected is_flatpak flag set to False'
assert len(dms[0]['labels']) == 2, 'Expected 2 labels for this manifest'
assert len(dms[0]['annotations']) == 2, 'Expected 2 annotations for this manifest'

# Verify the vaules meet the expectations specific for the flatpak repo.
dms = target_sat.api.Repository(id=pre_upgrade_data.flatpak_repo_id).docker_manifests()[
'results'
]
assert len(dms) == 2, 'Expected 2 manifests in the repo'
assert all([not m['is_bootable'] for m in dms]), 'Expected is_bootable flags set to False'
assert all([m['is_flatpak'] for m in dms]), 'Expected is_flatpak flags set to True'
assert all([len(m['labels']) == 10 for m in dms]), 'Expected 10 labels in the manifests'
assert all([len(m['annotations']) == 0 for m in dms]), 'No annotations expected'
[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'

0 comments on commit 09f2f27

Please sign in to comment.