diff --git a/conf/upgrade.yaml.template b/conf/upgrade.yaml.template index 1b971ba1b30..b8113843e5f 100644 --- a/conf/upgrade.yaml.template +++ b/conf/upgrade.yaml.template @@ -5,6 +5,10 @@ UPGRADE: TO_VERSION: "6.9" # Satellite, Capsule hosts RHEL operating system version. OS: "rhel7" + # The workflow Broker should use to checkout a to-be-upgraded Satellite + SATELLITE_DEPLOY_WORKFLOW: deploy-satellite-upgrade + # The job template Broker should use to upgrade a Satellite + SATELLITE_UPGRADE_JOB_TEMPLATE: satellite-upgrade # Capsule's activation key will only be available when we spawn the VM using upgrade template. CAPSULE_AK: RHEL6: diff --git a/robottelo/utils/shared_resource.py b/robottelo/utils/shared_resource.py index 0ad0bd92e46..017bdaead6d 100644 --- a/robottelo/utils/shared_resource.py +++ b/robottelo/utils/shared_resource.py @@ -29,6 +29,10 @@ from broker.helpers import FileLock +class SharedResourceError(Exception): + """An exception class for SharedResource errors.""" + + class SharedResource: """A class representing a shared resource. @@ -43,19 +47,21 @@ class SharedResource: is_recovering (bool): Whether the current instance is recovering from an error or not. """ - def __init__(self, resource_name, action, *action_args, **action_kwargs): + def __init__(self, resource_name, action, *action_args, action_validator=None, **action_kwargs): """Initializes a new instance of the SharedResource class. Args: resource_name (str): The name of the shared resource. action (function): The function to be executed when the resource is ready. action_args (tuple): The arguments to be passed to the action function. + action_validator (function): The function to validate the action results. action_kwargs (dict): The keyword arguments to be passed to the action function. """ self.resource_file = Path(f"/tmp/{resource_name}.shared") self.lock_file = FileLock(self.resource_file) self.id = str(uuid4().fields[-1]) self.action = action + self.action_validator = action_validator self.action_is_recoverable = action_kwargs.pop("action_is_recoverable", False) self.action_args = action_args self.action_kwargs = action_kwargs @@ -151,6 +157,14 @@ def register(self): curr_data["statuses"][self.id] = "pending" self.resource_file.write_text(json.dumps(curr_data, indent=4)) + def unregister(self): + """Unregisters the current process as a watcher.""" + with self.lock_file: + curr_data = json.loads(self.resource_file.read_text()) + curr_data["watchers"].remove(self.id) + del curr_data["statuses"][self.id] + self.resource_file.write_text(json.dumps(curr_data, indent=4)) + def ready(self): """Marks the current process as ready to perform the action.""" self._update_status("ready") @@ -163,10 +177,16 @@ def done(self): def act(self): """Attempt to perform the action.""" try: - self.action(*self.action_args, **self.action_kwargs) + result = self.action(*self.action_args, **self.action_kwargs) except Exception as err: self._update_main_status("error") - raise err + raise SharedResourceError("Main worker failed during action") from err + # If the action_validator is a callable, use it to validate the result + if callable(self.action_validator): + if not self.action_validator(result): + raise SharedResourceError( + f"Action validation failed for {self.action} with {result=}" + ) def wait(self): """Top-level wait function, separating behavior between main and non-main watchers.""" @@ -189,11 +209,16 @@ def __exit__(self, exc_type, exc_value, traceback): raise exc_value if exc_type is None: self.done() + self.unregister() if self.is_main: self._wait_for_status("done") self.resource_file.unlink() else: self._update_status("error") if self.is_main: - self._update_main_status("error") + if self._check_all_status("error"): + # All have failed, delete the file + self.resource_file.unlink() + else: + self._update_main_status("error") raise exc_value diff --git a/tests/robottelo/test_shared_resource.py b/tests/robottelo/test_shared_resource.py index ff2146cd80a..d0745bc1fce 100644 --- a/tests/robottelo/test_shared_resource.py +++ b/tests/robottelo/test_shared_resource.py @@ -11,6 +11,7 @@ def upgrade_action(*args, **kwargs): print(f"Upgrading satellite with {args=} and {kwargs=}") time.sleep(1) print("Satellite upgraded!") + return True def run_resource(resource_name): @@ -24,7 +25,14 @@ def run_resource(resource_name): def test_shared_resource(): """Test the SharedResource class.""" - with SharedResource("test_resource", upgrade_action, 1, 2, 3, foo="bar") as resource: + + def action_validator(result): + return result is True + + shared_args = (1, 2, 3) + with SharedResource( + "test_resource", upgrade_action, *shared_args, action_validator=action_validator, foo="bar" + ) as resource: assert Path("/tmp/test_resource.shared").exists() assert resource.is_main assert not resource.is_recovering diff --git a/tests/upgrades/conftest.py b/tests/upgrades/conftest.py index d75929cb7b4..d58ed2d2dde 100644 --- a/tests/upgrades/conftest.py +++ b/tests/upgrades/conftest.py @@ -87,10 +87,14 @@ def test_capsule_post_upgrade_skipped(pre_upgrade_data): import os from box import Box +from broker import Broker import pytest +from robottelo.config import settings +from robottelo.hosts import Satellite from robottelo.logging import logger from robottelo.utils.decorators.func_locker import lock_function +from robottelo.utils.shared_resource import SharedResource pre_upgrade_failed_tests = [] @@ -334,17 +338,17 @@ def __initiate(config): global POST_UPGRADE global PRE_UPGRADE_TESTS_FILE_PATH PRE_UPGRADE_TESTS_FILE_PATH = getattr(config.option, PRE_UPGRADE_TESTS_FILE_OPTION) - if not [ - upgrade_mark - for upgrade_mark in (PRE_UPGRADE_MARK, POST_UPGRADE_MARK) - if upgrade_mark in config.option.markexpr - ]: - # Raise only if the `tests/upgrades` directory is selected - if 'upgrades' in config.args[0]: - pytest.fail( - f'For upgrade scenarios either {PRE_UPGRADE_MARK} or {POST_UPGRADE_MARK} mark ' - 'must be provided' - ) + # if not [ + # upgrade_mark + # for upgrade_mark in (PRE_UPGRADE_MARK, POST_UPGRADE_MARK) + # if upgrade_mark in config.option.markexpr + # ]: + # # Raise only if the `tests/upgrades` directory is selected + # if 'upgrades' in config.args[0]: + # pytest.fail( + # f'For upgrade scenarios either {PRE_UPGRADE_MARK} or {POST_UPGRADE_MARK} mark ' + # 'must be provided' + # ) if PRE_UPGRADE_MARK in config.option.markexpr: pre_upgrade_failed_tests = [] PRE_UPGRADE = True @@ -418,8 +422,6 @@ def pytest_collection_modifyitems(items, config): class DependentTestFailed(Exception): """Raise when the dependent test fails""" - pass - @pytest.fixture(autouse=True) def post_upgrade_dependant_fail(request): @@ -428,3 +430,56 @@ def post_upgrade_dependant_fail(request): if fail: reason = fail.kwargs.get('reason') raise DependentTestFailed(reason) + + +def shared_checkout(shared_name): + Satellite(hostname="blank")._swap_nailgun(f"{settings.UPGRADE.FROM_VERSION}.z") + bx_inst = Broker( + workflow=settings.UPGRADE.SATELLITE_DEPLOY_WORKFLOW, + deploy_sat_version=settings.UPGRADE.FROM_VERSION, + host_class=Satellite, + upgrade_group=f"{shared_name}_shared_checkout", + ) + with SharedResource( + resource_name=f"{shared_name}_sat_checkout", + action=bx_inst.checkout, + action_validator=lambda result: isinstance(result, Satellite), + ) as sat_checkout: + sat_checkout.ready() + sat_instance = bx_inst.from_inventory( + filter=f'@inv._broker_args.upgrade_group == "{shared_name}_shared_checkout"' + )[0] + sat_instance.setup() + return sat_instance + + +def shared_checkin(sat_instance): + sat_instance.teardown() + with SharedResource( + resource_name=sat_instance.hostname + "_checkin", + action=Broker(hosts=[sat_instance]).checkin, + ) as sat_checkin: + sat_checkin.ready() + + +@pytest.fixture(scope='session') +def upgrade_action(): + def _upgrade_action(target_sat): + Broker( + job_template=settings.UPGRADE.SATELLITE_UPGRADE_JOB_TEMPLATE, + target_vm=target_sat.name, + sat_version=settings.UPGRADE.TO_VERSION, + tower_inventory=target_sat.tower_inventory, + ).execute() + + return _upgrade_action + + +@pytest.fixture +def content_upgrade_shared_satellite(): + sat_instance = shared_checkout("content_upgrade") + with SharedResource( + "content_upgrade_tests", shared_checkin, sat_instance=sat_instance + ) as test_duration: + yield sat_instance + test_duration.ready() diff --git a/tests/upgrades/test_contentview.py b/tests/upgrades/test_contentview.py index 9b7fa90bb56..6f1d09cd1f5 100644 --- a/tests/upgrades/test_contentview.py +++ b/tests/upgrades/test_contentview.py @@ -11,105 +11,209 @@ :CaseImportance: High """ +from box import Box from fauxfactory import gen_alpha import pytest from robottelo.config import settings from robottelo.constants import RPM_TO_UPLOAD, DataFile - - -class TestContentView: - """The test class contains the pre-upgrade and post-upgrade scenario to test the behavior of - content view before and after the upgrade. +from robottelo.utils.shared_resource import SharedResource + +# class TestContentView: +# """The test class contains the pre-upgrade and post-upgrade scenario to test the behavior of +# content view before and after the upgrade. +# """ + +# @pytest.mark.pre_upgrade +# def test_cv_preupgrade_scenario(self, request, target_sat, save_test_data): +# """Pre-upgrade scenario that creates content-view with various repositories. + +# :id: preupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 + +# :steps: +# 1. Create custom repositories of yum and file type. +# 2. Create content-view. +# 3. Add yum and file repositories in the content view. +# 4. Publish the content-view. + +# :expectedresults: Content-view created with various repositories. +# """ +# test_name = request.node.name + gen_alpha() +# org = target_sat.api.Organization(name=f'{test_name}_org').create() +# product = target_sat.api.Product(organization=org, name=f'{test_name}_prod').create() +# yum_repository = target_sat.api.Repository( +# product=product, name=f'{test_name}_yum_repo', url=settings.repos.yum_1.url +# ).create() +# target_sat.api.Repository.sync(yum_repository) +# file_repository = target_sat.api.Repository( +# product=product, name=f'{test_name}_file_repo', content_type='file' +# ).create() +# remote_file_path = f'/tmp/{RPM_TO_UPLOAD}' +# target_sat.put(DataFile.RPM_TO_UPLOAD, remote_file_path) +# file_repository.upload_content(files={'content': DataFile.RPM_TO_UPLOAD.read_bytes()}) +# assert 'content' in file_repository.files()['results'][0]['name'] +# cv = target_sat.publish_content_view(org, [yum_repository, file_repository]) +# assert len(cv.read_json()['versions']) == 1 +# save_test_data({'test_name': test_name, 'cv_name': cv.name}) + +# @pytest.mark.post_upgrade(depend_on=test_cv_preupgrade_scenario) +# def test_cv_postupgrade_scenario(self, request, target_sat, pre_upgrade_data): +# """After upgrade, the existing content-view(created before upgrade) should be updated. + +# :id: postupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 + +# :steps: +# 1. Check yum and file repository which was added in CV before upgrade. +# 2. Check the content view which was was created before upgrade. +# 3. Remove yum repository from existing CV. +# 4. Create new yum repository in existing CV. +# 5. Publish content-view + +# :expectedresults: After upgrade, +# 1. All the repositories should be intact. +# 2. Content view created before upgrade should be intact. +# 3. The new repository should be added/updated to the CV. + +# """ +# pre_test_name = pre_upgrade_data.get('test_name') +# cv_name = pre_upgrade_data.get('cv_name') +# org = target_sat.api.Organization().search(query={'search': f'name="{pre_test_name}_org"'})[ +# 0 +# ] +# request.addfinalizer(org.delete) +# product = target_sat.api.Product(organization=org.id).search( +# query={'search': f'name="{pre_test_name}_prod"'} +# )[0] +# request.addfinalizer(product.delete) +# cv = target_sat.api.ContentView(organization=org.id).search( +# query={'search': f'name="{cv_name}"'} +# )[0] +# yum_repo = target_sat.api.Repository(organization=org.id).search( +# query={'search': f'name="{pre_test_name}_yum_repo"'} +# )[0] +# request.addfinalizer(yum_repo.delete) +# file_repo = target_sat.api.Repository(organization=org.id).search( +# query={'search': f'name="{pre_test_name}_file_repo"'} +# )[0] +# request.addfinalizer(file_repo.delete) +# request.addfinalizer(cv.delete) +# cv.repository = [] +# cv.update(['repository']) +# assert len(cv.read_json()['repositories']) == 0 + +# yum_repository2 = target_sat.api.Repository( +# product=product, name=f'{pre_test_name}_yum_repos2', url=settings.repos.yum_2.url +# ).create() +# yum_repository2.sync() +# cv.repository = [yum_repository2] +# cv.update(['repository']) +# assert cv.read_json()['repositories'][0]['name'] == yum_repository2.name + +# cv.publish() +# assert len(cv.read_json()['versions']) == 2 +# content_view_json = cv.read_json()['environments'][0] +# cv.delete_from_environment(content_view_json['id']) +# assert len(cv.read_json()['environments']) == 0 + + +@pytest.fixture +def cv_upgrade_setup(content_upgrade_shared_satellite, upgrade_action): + """Pre-upgrade scenario that creates content-view with various repositories. + + :id: preupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 + + :steps: + 1. Create custom repositories of yum and file type. + 2. Create content-view. + 3. Add yum and file repositories in the content view. + 4. Publish the content-view. + + :expectedresults: Content-view created with various repositories. """ - - @pytest.mark.pre_upgrade - def test_cv_preupgrade_scenario(self, request, target_sat, save_test_data): - """Pre-upgrade scenario that creates content-view with various repositories. - - :id: preupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 - - :steps: - 1. Create custom repositories of yum and file type. - 2. Create content-view. - 3. Add yum and file repositories in the content view. - 4. Publish the content-view. - - :expectedresults: Content-view created with various repositories. - """ - test_name = request.node.name + gen_alpha() + target_sat = content_upgrade_shared_satellite + with SharedResource(target_sat.hostname, upgrade_action, target_sat=target_sat) as sat_upgrade: + test_data = Box( + { + 'target_sat': target_sat, + 'cv': None, + 'org': None, + 'product': None, + 'yum_repo': None, + 'file_repo': None, + } + ) + test_name = f'cv_upgrade_{gen_alpha()}' # unique name for the test org = target_sat.api.Organization(name=f'{test_name}_org').create() + test_data.org = org product = target_sat.api.Product(organization=org, name=f'{test_name}_prod').create() + test_data.product = product yum_repository = target_sat.api.Repository( product=product, name=f'{test_name}_yum_repo', url=settings.repos.yum_1.url ).create() + test_data.yum_repo = yum_repository target_sat.api.Repository.sync(yum_repository) file_repository = target_sat.api.Repository( product=product, name=f'{test_name}_file_repo', content_type='file' ).create() + test_data.file_repo = file_repository remote_file_path = f'/tmp/{RPM_TO_UPLOAD}' target_sat.put(DataFile.RPM_TO_UPLOAD, remote_file_path) file_repository.upload_content(files={'content': DataFile.RPM_TO_UPLOAD.read_bytes()}) assert 'content' in file_repository.files()['results'][0]['name'] cv = target_sat.publish_content_view(org, [yum_repository, file_repository]) assert len(cv.read_json()['versions']) == 1 - save_test_data({'test_name': test_name, 'cv_name': cv.name}) - - @pytest.mark.post_upgrade(depend_on=test_cv_preupgrade_scenario) - def test_cv_postupgrade_scenario(self, request, target_sat, pre_upgrade_data): - """After upgrade, the existing content-view(created before upgrade) should be updated. - - :id: postupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 - - :steps: - 1. Check yum and file repository which was added in CV before upgrade. - 2. Check the content view which was was created before upgrade. - 3. Remove yum repository from existing CV. - 4. Create new yum repository in existing CV. - 5. Publish content-view - - :expectedresults: After upgrade, - 1. All the repositories should be intact. - 2. Content view created before upgrade should be intact. - 3. The new repository should be added/updated to the CV. - - """ - pre_test_name = pre_upgrade_data.get('test_name') - cv_name = pre_upgrade_data.get('cv_name') - org = target_sat.api.Organization().search(query={'search': f'name="{pre_test_name}_org"'})[ - 0 - ] - request.addfinalizer(org.delete) - product = target_sat.api.Product(organization=org.id).search( - query={'search': f'name="{pre_test_name}_prod"'} - )[0] - request.addfinalizer(product.delete) - cv = target_sat.api.ContentView(organization=org.id).search( - query={'search': f'name="{cv_name}"'} - )[0] - yum_repo = target_sat.api.Repository(organization=org.id).search( - query={'search': f'name="{pre_test_name}_yum_repo"'} - )[0] - request.addfinalizer(yum_repo.delete) - file_repo = target_sat.api.Repository(organization=org.id).search( - query={'search': f'name="{pre_test_name}_file_repo"'} - )[0] - request.addfinalizer(file_repo.delete) - request.addfinalizer(cv.delete) - cv.repository = [] - cv.update(['repository']) - assert len(cv.read_json()['repositories']) == 0 - - yum_repository2 = target_sat.api.Repository( - product=product, name=f'{pre_test_name}_yum_repos2', url=settings.repos.yum_2.url - ).create() - yum_repository2.sync() - cv.repository = [yum_repository2] - cv.update(['repository']) - assert cv.read_json()['repositories'][0]['name'] == yum_repository2.name - - cv.publish() - assert len(cv.read_json()['versions']) == 2 - content_view_json = cv.read_json()['environments'][0] - cv.delete_from_environment(content_view_json['id']) - assert len(cv.read_json()['environments']) == 0 + sat_upgrade.ready() + yield test_data + + +def test_cv_upgrade_scenario(cv_upgrade_setup): + """After upgrade, the existing content-view(created before upgrade) should be updated. + + :id: postupgrade-a4ebbfa1-106a-4962-9c7c-082833879ae8 + + :steps: + 1. Check yum and file repository which was added in CV before upgrade. + 2. Check the content view which was was created before upgrade. + 3. Remove yum repository from existing CV. + 4. Create new yum repository in existing CV. + 5. Publish content-view + + :expectedresults: After upgrade, + 1. All the repositories should be intact. + 2. Content view created before upgrade should be intact. + 3. The new repository should be added/updated to the CV. + + """ + target_sat = cv_upgrade_setup.target_sat + org = target_sat.api.Organization().search( + query={'search': f'name="{cv_upgrade_setup.org.name}"'} + )[0] + product = target_sat.api.Product(organization=org.id).search( + query={'search': f'name="{cv_upgrade_setup.product.name}"'} + )[0] + cv = target_sat.api.ContentView(organization=org.id).search( + query={'search': f'name="{cv_upgrade_setup.cv.name}"'} + )[0] + target_sat.api.Repository(organization=org.id).search( + query={'search': f'name="{cv_upgrade_setup.yum_repo.name}"'} + )[0] + target_sat.api.Repository(organization=org.id).search( + query={'search': f'name="{cv_upgrade_setup.file_repo.name}"'} + )[0] + cv.repository = [] + cv.update(['repository']) + assert len(cv.read_json()['repositories']) == 0 + + yum_repository2 = target_sat.api.Repository( + product=product, name='cv_upgrade_yum_repos2', url=settings.repos.yum_2.url + ).create() + yum_repository2.sync() + cv.repository = [yum_repository2] + cv.update(['repository']) + assert cv.read_json()['repositories'][0]['name'] == yum_repository2.name + + cv.publish() + assert len(cv.read_json()['versions']) == 2 + content_view_json = cv.read_json()['environments'][0] + cv.delete_from_environment(content_view_json['id']) + assert len(cv.read_json()['environments']) == 0 diff --git a/tests/upgrades/test_repository.py b/tests/upgrades/test_repository.py index 31233d820c6..b51e25ab4de 100644 --- a/tests/upgrades/test_repository.py +++ b/tests/upgrades/test_repository.py @@ -11,6 +11,7 @@ :CaseImportance: High """ +from box import Box import pytest from robottelo.config import settings @@ -21,6 +22,7 @@ REPOS, ) from robottelo.hosts import ContentHost +from robottelo.utils.shared_resource import SharedResource UPSTREAM_USERNAME = 'rTtest123' @@ -91,53 +93,67 @@ def test_post_repository_scenario_upstream_authorization(self, target_sat, pre_u assert UPSTREAM_USERNAME not in result.stdout -class TestScenarioCustomRepoCheck: - """Scenario test to verify if we can create a custom repository and consume it - via client then we alter the created custom repository and satellite will be able - to sync back the repo. +# class TestScenarioCustomRepoCheck: +# """Scenario test to verify if we can create a custom repository and consume it +# via client then we alter the created custom repository and satellite will be able +# to sync back the repo. - Test Steps: +# Test Steps: - 1. Before Satellite upgrade. - 2. Create new Organization and Location. - 3. Create Product, custom repo, cv. - 4. Create activation key and add subscription in it. - 5. Create a content host, register and install package on it. - 6. Upgrade Satellite. - 7. Remove Old package and add new package into custom repo. - 8. Sync repo, publish new version of cv. - 9. Try to install new package on client. +# 1. Before Satellite upgrade. +# 2. Create new Organization and Location. +# 3. Create Product, custom repo, cv. +# 4. Create activation key and add subscription in it. +# 5. Create a content host, register and install package on it. +# 6. Upgrade Satellite. +# 7. Remove Old package and add new package into custom repo. +# 8. Sync repo, publish new version of cv. +# 9. Try to install new package on client. - BZ: 1429201,1698549 - """ +# BZ: 1429201,1698549 +# """ - @pytest.mark.pre_upgrade - def test_pre_scenario_custom_repo_check(self, target_sat, sat_upgrade_chost, save_test_data): - """This is pre-upgrade scenario test to verify if we can create a - custom repository and consume it via content host. - :id: preupgrade-eb6831b1-c5b6-4941-a325-994a09467478 +@pytest.fixture +def custom_repo_check_setup(sat_upgrade_chost, content_upgrade_shared_satellite, upgrade_action): + """This is pre-upgrade scenario test to verify if we can create a + custom repository and consume it via content host. - :steps: - 1. Before Satellite upgrade. - 2. Create new Organization, Location. - 3. Create Product, custom repo, cv. - 4. Create activation key and add subscription. - 5. Create a content host, register and install package on it. + :id: preupgrade-eb6831b1-c5b6-4941-a325-994a09467478 - :expectedresults: + :steps: + 1. Before Satellite upgrade. + 2. Create new Organization, Location. + 3. Create Product, custom repo, cv. + 4. Create activation key and add subscription. + 5. Create a content host, register and install package on it. - 1. Custom repo is created. - 2. Package is installed on Content host. + :expectedresults: - """ + 1. Custom repo is created. + 2. Package is installed on Content host. + + """ + target_sat = content_upgrade_shared_satellite + with SharedResource(target_sat.hostname, upgrade_action, target_sat=target_sat) as sat_upgrade: + test_data = Box( + { + 'target_sat': target_sat, + 'rhel_client': sat_upgrade_chost, + 'lce': None, + 'repo': None, + 'content_view': None, + } + ) org = target_sat.api.Organization().create() lce = target_sat.api.LifecycleEnvironment(organization=org).create() - + test_data.lce = lce product = target_sat.api.Product(organization=org).create() repo = target_sat.api.Repository(product=product.id, url=settings.repos.yum_1.url).create() + test_data.repo = repo repo.sync() content_view = target_sat.publish_content_view(org, repo) + test_data.content_view = content_view content_view.version[0].promote(data={'environment_ids': lce.id}) ak = target_sat.api.ActivationKey( content_view=content_view, organization=org.id, environment=lce @@ -152,53 +168,43 @@ def test_pre_scenario_custom_repo_check(self, target_sat, sat_upgrade_chost, sav sat_upgrade_chost.execute('subscription-manager repos --enable=*;yum clean all') result = sat_upgrade_chost.execute(f'yum install -y {FAKE_0_CUSTOM_PACKAGE_NAME}') assert result.status == 0 - - save_test_data( - { - 'rhel_client': sat_upgrade_chost.hostname, - 'content_view_name': content_view.name, - 'lce_id': lce.id, - 'repo_name': repo.name, - } - ) - - @pytest.mark.post_upgrade(depend_on=test_pre_scenario_custom_repo_check) - def test_post_scenario_custom_repo_check(self, target_sat, pre_upgrade_data): - """This is post-upgrade scenario test to verify if we can alter the - created custom repository and satellite will be able to sync back - the repo. - - :id: postupgrade-5c793577-e573-46a7-abbf-b6fd1f20b06e - - :steps: - 1. Remove old and add new package into custom repo. - 2. Sync repo , publish the new version of cv. - 3. Try to install new package on client. + sat_upgrade.ready() + yield test_data - :expectedresults: Content host should be able to pull the new rpm. +def test_scenario_custom_repo_check(custom_repo_check_setup): + """This is post-upgrade scenario test to verify if we can alter the + created custom repository and satellite will be able to sync back + the repo. - """ - client_hostname = pre_upgrade_data.get('rhel_client') - content_view_name = pre_upgrade_data.get('content_view_name') - lce_id = pre_upgrade_data.get('lce_id') - repo_name = pre_upgrade_data.get('repo_name') + :id: postupgrade-5c793577-e573-46a7-abbf-b6fd1f20b06e - repo = target_sat.api.Repository(name=repo_name).search()[0] - repo.sync() + :steps: + 1. Remove old and add new package into custom repo. + 2. Sync repo , publish the new version of cv. + 3. Try to install new package on client. - content_view = target_sat.api.ContentView(name=content_view_name).search()[0] - content_view.publish() - content_view = target_sat.api.ContentView(name=content_view_name).search()[0] - latest_cvv_id = sorted(cvv.id for cvv in content_view.version)[-1] - target_sat.api.ContentViewVersion(id=latest_cvv_id).promote( - data={'environment_ids': lce_id} - ) + :expectedresults: Content host should be able to pull the new rpm. - rhel_client = ContentHost.get_host_by_hostname(client_hostname) - result = rhel_client.execute(f'yum install -y {FAKE_4_CUSTOM_PACKAGE_NAME}') - assert result.status == 0 + """ + test_data = custom_repo_check_setup + target_sat = test_data.target_sat + repo = target_sat.api.Repository(name=test_data.repo.name).search()[0] + repo.sync() + + content_view = target_sat.api.ContentView(name=test_data.content_view.name).search()[0] + content_view.publish() + + content_view = target_sat.api.ContentView(name=test_data.content_view.name).search()[0] + latest_cvv_id = sorted(cvv.id for cvv in content_view.version)[-1] + target_sat.api.ContentViewVersion(id=latest_cvv_id).promote( + data={'environment_ids': test_data.lce.id} + ) + + rhel_client = ContentHost.get_host_by_hostname(test_data.rhel_client.hostname) + result = rhel_client.execute(f'yum install -y {FAKE_4_CUSTOM_PACKAGE_NAME}') + assert result.status == 0 class TestScenarioCustomRepoOverrideCheck: