diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index 1ee0f0c8816..d3264f19006 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -25,8 +25,6 @@ from robottelo.config import settings from robottelo.constants import ( - CONTAINER_REGISTRY_HUB, - CONTAINER_UPSTREAM_NAME, DEFAULT_LOC, FAKE_1_CUSTOM_PACKAGE, FAKE_2_CUSTOM_PACKAGE, @@ -45,10 +43,6 @@ REAL_4_ERRATA_CVES, REAL_4_ERRATA_ID, ) -from robottelo.constants.repos import ( - ANSIBLE_GALAXY, - CUSTOM_FILE_REPO, -) from robottelo.hosts import ContentHost CUSTOM_REPO_URL = settings.repos.yum_9.url @@ -75,7 +69,21 @@ def _install_client_package(client, package, errata_applicability=False): :param errata_applicability: If True, force host to generate errata applicability. :returns: True if package installed successfully, False otherwise. """ - result = client.run(f'yum install -y {package}') + result = client.execute(f'yum install -y {package}') + if errata_applicability: + _generate_errata_applicability(client.hostname) + return result.status == 0 + + +def _remove_client_package(client, package, errata_applicability=False): + """Delete a package in virtual machine client. + + :param client: The Virtual machine client. + :param package: the package (general name, or version) to remove from virtual machine client. + :param errata_applicability: If True, force host to generate errata applicability. + :returns: True if a package was removed successfully, False otherwise. + """ + result = client.execute(f'yum delete -y {package}') if errata_applicability: _generate_errata_applicability(client.hostname) return result.status == 0 @@ -170,19 +178,21 @@ def vm(module_repos_collection_with_setup, rhel7_contenthost, target_sat): @pytest.fixture(scope='function') -def function_registered_contenthost( +def registered_contenthost( rhel_contenthost, module_org, module_lce, module_target_sat, - repo_url=CUSTOM_REPO_URL, + repos=[CUSTOM_REPO_URL], ): """RHEL ContentHost registered in satellite, Using SCA and global registration. - Associate custom repository from URL, enable.""" - # TODO: Impliment global registration through SCA - """Publish and promote content view, - Create and associate activation key.""" + + :param repos: list of upstream URLs for custom repositories, + default to CUSTOM_REPO_URL + """ + # Publish and promote a content view + # Create and associate an activation key content_view = module_target_sat.api.ContentView( organization=module_org, environment=[module_lce], @@ -193,16 +203,20 @@ def function_registered_contenthost( environment=module_lce, ).create() - rhel_contenthost.create_custom_repos(custom_repo=repo_url) - custom_repo_id = module_target_sat.cli_factory.setup_org_for_a_custom_repo( - { - 'url': repo_url, - 'organization-id': module_org.id, - 'lifecycle-environment-id': module_lce.id, - 'activationkey-id': activation_key.id, - 'content-view-id': content_view.id, - } - )['repository-id'] + custom_repos = [] + for repo_url in repos: + # Associate org, ak, cv, with custom repo: + rhel_contenthost.create_custom_repos(custom_repo=repo_url) + custom_repo_id = module_target_sat.cli_factory.setup_org_for_a_custom_repo( + { + 'url': repo_url, + 'organization-id': module_org.id, + 'lifecycle-environment-id': module_lce.id, + 'activationkey-id': activation_key.id, + 'content-view-id': content_view.id, + } + )['repository-id'] + custom_repos.append(custom_repo_id) result = rhel_contenthost.register( activation_keys=activation_key.name, @@ -214,16 +228,16 @@ def function_registered_contenthost( assert result.status == 0, f'Failed to register host: {result.stdout}' assert rhel_contenthost.subscribed - rhel_contenthost.create_custom_repos(custom_repo=repo_url) - rhel_contenthost.execute(r'subscription-manager refresh') - custom_repo = module_target_sat.api.Repository(id=custom_repo_id).read() - assert custom_repo + for custom_repo_id in custom_repos: + custom_repo = module_target_sat.api.Repository(id=custom_repo_id).read() + assert custom_repo + result = custom_repo.sync()['humanized'] + assert ( + len(result['errors']) == 0 + ), f'Failed to sync custom repository: {str(result["errors"])}' - result = custom_repo.sync()['humanized'] - assert len(result['errors']) == 0, f'Failed to sync custom repository: {str(result["errors"])}' yield rhel_contenthost -from time import time, localtime @pytest.mark.e2e @pytest.mark.tier3 @@ -235,7 +249,7 @@ def test_end_to_end( module_lce, module_cv, module_target_sat, - function_registered_contenthost, + registered_contenthost, ): """Create all entities required for errata, set up applicable host, read errata details and apply it to host @@ -256,10 +270,7 @@ def test_end_to_end( :CaseLevel: System """ - #for repo in repos_collection: - # function_registered_contenthost.create_custom_repos(repo=repo.url) - # repo.sync() - # function_registered_contenthost.execute(f'subscription-manager repos --enable {repo.id}') + ERRATA_DETAILS = { 'advisory': 'RHSA-2012:0055', 'cves': 'N/A', @@ -278,35 +289,30 @@ def test_end_to_end( ], 'module_stream_packages': [], } - contenthost = function_registered_contenthost - assert _install_client_package(contenthost, FAKE_1_CUSTOM_PACKAGE) - contenthost.execute('subscription-manager repos') + + assert len(product_list := module_target_sat.api.Product(organization=module_org).search()) == 1 + _product = product_list[0] + assert len(repo_list := module_target_sat.api.Repository(organization=module_org).search()) == 1 + _repository = repo_list[0] + + _remove_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE) + assert _install_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE) module_target_sat.cli.Host.errata_recalculate( - {'host-id': contenthost.nailgun_host.id} + {'host-id': registered_contenthost.nailgun_host.id} ) - assert contenthost.applicable_errata_count > 0 - _UTC_time_epoch = time() - _local_time_epoch = localtime() - _local_timezone = _local_time_epoch.tm_zone - + assert registered_contenthost.applicable_errata_count == 1 with session: - # TODO: Update setting per BZ 2029192 without setting_update fixture - # TODO: FIX -- session.settings.update(f'name = {setting_update.name}', property_value) # BZ 2029192 + # TODO: Update setting per BZ 2029192 & setting_update fixture + # FIX -- session.settings.update(f'name = {setting_update.name}', property_value) # BZ 2029192 # Check selection box function for BZ#1688636 - breakpoint() - #session.organization.select(org_name=module_org.name) session.location.select(loc_name=DEFAULT_LOC) + session.organization.select(org_name=module_org.name) assert session.errata.search_content_hosts( - CUSTOM_REPO_ERRATA_ID, contenthost.hostname, environment=module_lce.name + CUSTOM_REPO_ERRATA_ID, registered_contenthost.hostname, environment=module_lce.name ) - - #assert session.errata.search(CUSTOM_REPO_ERRATA_ID, applicable=True)[0]['Errata ID'] - #assert session.errata.search(CUSTOM_REPO_ERRATA_ID, installable=True)[0]['Errata ID'] + assert (errata := session.errata.read(CUSTOM_REPO_ERRATA_ID)) # Check all tabs of Errata Details page - errata = session.errata.read(CUSTOM_REPO_ERRATA_ID) - breakpoint() - assert errata # We ignore issued date and updated date in ERRATA_DETAILS, so we don't perform an # equality check here. # DONE: Find a way to account for browser time zone, so that the errata dates displayed @@ -321,31 +327,25 @@ def test_end_to_end( errata['packages']['module_stream_packages'] == ERRATA_PACKAGES['module_stream_packages'] ) - #assert ( - # errata['repositories']['table'][-1]['Name'] - # == repos_collection.custom_repos_info[-1]['name'] - #) - #assert ( - # errata['repositories']['table'][-1]['Product'] - # == repos_collection.custom_product['name'] - #) - status = session.contenthost.install_errata( - contenthost.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex' - ) - assert status['overview']['job_status'] == 'Success' - assert status['overview']['job_status_progress'] == '100%' - _generate_errata_applicability(contenthost.hostname) - contenthost.execute('subscription-manager repos') - module_target_sat.cli.Host.errata_recalculate( - {'host-id': contenthost.nailgun_host.id} - ) - breakpoint() - install_time_UTC = session.errata.read(CUSTOM_REPO_ERRATA_ID)['install_date'] - #install_time_local = time.convert_from_utc(install_time_UTC, browser_time_zone) + assert errata['repositories']['table'][-1]['Name'] == _repository.name + assert errata['repositories']['table'][-1]['Product'] == _product.name - #assert + session.host_new.apply_erratas( + entity_name=registered_contenthost.hostname, + search=f"errata_id == {CUSTOM_REPO_ERRATA_ID}", + ) - assert contenthost.applicable_errata_count == 0 + result = module_target_sat.wait_for_tasks( + search_query=( + f'"Install errata errata_id == {CUSTOM_REPO_ERRATA_ID} ' + f'on {registered_contenthost.hostname}"' + ), + search_rate=2, + max_tries=60, + ) + task_status = module_target_sat.api.ForemanTask(id=result[0].id).poll() + assert task_status['result'] == 'success' + assert registered_contenthost.applicable_errata_count == 0 @pytest.mark.tier2