Skip to content

Commit

Permalink
Update repository tests with supported checksums (SatelliteQE#15547)
Browse files Browse the repository at this point in the history
* Update repository tests with supported checksums

* Add wait for async metadata generate
  • Loading branch information
vsedmik authored and jyejare committed Oct 19, 2024
1 parent 6c34ae9 commit 7b92bd3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@
PULP_EXPORT_DIR = '/var/lib/pulp/exports/'
PULP_IMPORT_DIR = '/var/lib/pulp/imports/'
EXPORT_LIBRARY_NAME = 'Export-Library'
SUPPORTED_REPO_CHECKSUMS = ['sha256', 'sha384', 'sha512']

PUPPET_COMMON_INSTALLER_OPTS = {
'foreman-proxy-puppetca': 'true',
Expand Down
37 changes: 25 additions & 12 deletions tests/foreman/api/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import random
import re
from string import punctuation
import tempfile
Expand All @@ -29,6 +30,7 @@
from robottelo.constants import (
CONTAINER_MANIFEST_LABELS,
LABELLED_REPOS,
SUPPORTED_REPO_CHECKSUMS,
DataFile,
repos as repo_constants,
)
Expand Down Expand Up @@ -57,9 +59,17 @@ def repo_options_custom_product(request, module_org, module_target_sat):


@pytest.fixture
def repo(repo_options, module_target_sat):
def repo(repo_options, target_sat):
"""Create a new repository."""
return module_target_sat.api.Repository(**repo_options).create()
repo = target_sat.api.Repository(**repo_options).create()
target_sat.wait_for_tasks(
search_query='Actions::Katello::Repository::MetadataGenerate'
f' and resource_id = {repo.id}'
' and resource_type = Katello::Repository',
max_tries=6,
search_rate=10,
)
return repo


class TestRepository:
Expand Down Expand Up @@ -265,7 +275,7 @@ def test_positive_create_on_demand_update_to_immediate(self, repo):
**datafactory.parametrized(
{
checksum_type: {'checksum_type': checksum_type, 'download_policy': 'immediate'}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
}
),
indirect=True,
Expand Down Expand Up @@ -536,9 +546,9 @@ def test_negative_create_checksum(self, repo_options, target_sat):
'repo_options',
[
{'checksum_type': checksum_type, 'download_policy': 'on_demand'}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
],
ids=['sha1', 'sha256'],
ids=SUPPORTED_REPO_CHECKSUMS,
indirect=True,
)
def test_negative_create_checksum_with_on_demand_policy(self, repo_options, target_sat):
Expand All @@ -561,25 +571,26 @@ def test_negative_create_checksum_with_on_demand_policy(self, repo_options, targ
**datafactory.parametrized(
{
checksum_type: {'checksum_type': checksum_type, 'download_policy': 'immediate'}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
}
),
indirect=True,
)
def test_negative_update_checksum_with_on_demand_policy(self, repo):
def test_positive_update_checksum_with_on_demand_policy(self, repo):
"""Attempt to update the download policy to on_demand on a repository with checksum type.
:id: 5bfaef4f-de66-42a0-8419-b86d00ffde6f
:parametrized: yes
:expectedresults: A repository is not updated and error is raised.
:expectedresults: The download policy is updated and checksum type is reset.
:CaseImportance: Critical
"""
repo.download_policy = 'on_demand'
with pytest.raises(HTTPError):
repo.update(['download_policy'])
repo = repo.update(['download_policy'])
assert repo.download_policy == 'on_demand', 'Download policy was not updated'
assert not repo.checksum_type, 'Checksum type was not reset to Default'

@pytest.mark.tier1
@pytest.mark.parametrize('name', **datafactory.parametrized(datafactory.valid_data_list()))
Expand All @@ -604,7 +615,7 @@ def test_positive_update_name(self, repo, name):
**datafactory.parametrized(
{
checksum_type: {'checksum_type': checksum_type, 'download_policy': 'immediate'}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
}
),
indirect=True,
Expand All @@ -620,7 +631,9 @@ def test_positive_update_checksum(self, repo_options, repo):
:CaseImportance: Critical
"""
updated_checksum = 'sha256' if repo_options['checksum_type'] == 'sha1' else 'sha1'
updated_checksum = random.choice(
[cs for cs in SUPPORTED_REPO_CHECKSUMS if cs != repo_options['checksum_type']]
)
repo.checksum_type = updated_checksum
repo = repo.update(['checksum_type'])
assert repo.checksum_type == updated_checksum
Expand Down
19 changes: 14 additions & 5 deletions tests/foreman/cli/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
REPO_TYPE,
RPM_TO_UPLOAD,
SRPM_TO_UPLOAD,
SUPPORTED_REPO_CHECKSUMS,
DataFile,
)
from robottelo.constants.repos import (
Expand Down Expand Up @@ -105,7 +106,15 @@ def repo_options(request, module_org, module_product):
@pytest.fixture
def repo(repo_options, target_sat):
"""create a new repository."""
return target_sat.cli_factory.make_repository(repo_options)
repo = target_sat.cli_factory.make_repository(repo_options)
target_sat.wait_for_tasks(
search_query='Actions::Katello::Repository::MetadataGenerate'
f' and resource_id = {repo["id"]}'
' and resource_type = Katello::Repository',
max_tries=6,
search_rate=10,
)
return repo


@pytest.fixture
Expand Down Expand Up @@ -449,7 +458,7 @@ def test_positive_create_publish_via_https(self, repo_options, repo):
'content-type': 'yum',
'download-policy': 'immediate',
}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
]
),
indirect=True,
Expand Down Expand Up @@ -1282,7 +1291,7 @@ def test_positive_update_publish_method(self, repo, module_target_sat):
**parametrized([{'content-type': 'yum', 'download-policy': 'immediate'}]),
indirect=True,
)
@pytest.mark.parametrize('checksum_type', ['sha1', 'sha256'])
@pytest.mark.parametrize('checksum_type', SUPPORTED_REPO_CHECKSUMS)
def test_positive_update_checksum_type(
self, repo_options, repo, checksum_type, module_target_sat
):
Expand Down Expand Up @@ -1312,7 +1321,7 @@ def test_positive_update_checksum_type(
'checksum-type': checksum_type,
'download-policy': 'on_demand',
}
for checksum_type in ('sha1', 'sha256')
for checksum_type in SUPPORTED_REPO_CHECKSUMS
]
),
indirect=True,
Expand Down Expand Up @@ -2097,7 +2106,7 @@ def test_positive_sync_third_party_repo(self, repo_options, module_target_sat):
# 'publish-via-http': 'false',
# 'url': FEDORA_OSTREE_REPO,
# }
# for checksum_type in ('sha1', 'sha256')
# for checksum_type in SUPPORTED_REPO_CHECKSUMS
# ]
# ),
# indirect=True,
Expand Down
11 changes: 6 additions & 5 deletions tests/foreman/ui/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

from datetime import datetime, timedelta
from random import randint, shuffle
from random import choice, randint, shuffle

from navmazing import NavigationTriesExceeded
import pytest
Expand All @@ -28,6 +28,7 @@
REPO_TYPE,
REPOS,
REPOSET,
SUPPORTED_REPO_CHECKSUMS,
DataFile,
)
from robottelo.constants.repos import (
Expand Down Expand Up @@ -414,15 +415,15 @@ def test_positive_end_to_end_custom_yum_crud(session, module_org, module_prod, m
:CaseImportance: High
"""
repo_name = gen_string('alpha')
checksum_type = 'sha256'
checksum_type = choice(SUPPORTED_REPO_CHECKSUMS)
new_repo_name = gen_string('alphanumeric')
new_checksum_type = 'sha1'
new_checksum_type = choice([cs for cs in SUPPORTED_REPO_CHECKSUMS if cs != checksum_type])
gpg_key = module_target_sat.api.GPGKey(
content=DataFile.VALID_GPG_KEY_FILE.read_bytes(),
content=DataFile.VALID_GPG_KEY_FILE.read_text(),
organization=module_org,
).create()
new_gpg_key = module_target_sat.api.GPGKey(
content=DataFile.VALID_GPG_KEY_BETA_FILE.read_bytes(),
content=DataFile.VALID_GPG_KEY_BETA_FILE.read_text(),
organization=module_org,
).create()
with session:
Expand Down

0 comments on commit 7b92bd3

Please sign in to comment.