From 6e85ba1d0bacf3e2c9d80d5109d12d87b9f113e1 Mon Sep 17 00:00:00 2001 From: David Moore Date: Thu, 26 Oct 2023 16:31:17 -0400 Subject: [PATCH] Registration & setup --- pytest_fixtures/component/repository.py | 7 +- robottelo/cli/factory.py | 9 +- tests/foreman/ui/test_errata.py | 132 +++++++++++------------- 3 files changed, 74 insertions(+), 74 deletions(-) diff --git a/pytest_fixtures/component/repository.py b/pytest_fixtures/component/repository.py index 2f210842632..209245ff649 100644 --- a/pytest_fixtures/component/repository.py +++ b/pytest_fixtures/component/repository.py @@ -198,10 +198,11 @@ def repos_collection(request, target_sat): repos = getattr(request, 'param', []) repo_distro, repos = _simplify_repos(request, repos) _repos_collection = target_sat.cli_factory.RepositoryCollection( - distro=repo_distro, + distro=repo_distro or request.getfixturevalue('distro'), repositories=[ - target_sat.cli_factory.SatelliteToolsRepository(), - target_sat.cli_factory.YumRepository(url=repos.url), + getattr(target_sat.cli_factory, repo_name)(**repo_params) + for repo in repos + for repo_name, repo_params in repo.items() ], ) return _repos_collection diff --git a/robottelo/cli/factory.py b/robottelo/cli/factory.py index 7b9d539a5c4..5965bdd776e 100644 --- a/robottelo/cli/factory.py +++ b/robottelo/cli/factory.py @@ -1692,14 +1692,19 @@ def setup_org_for_a_custom_repo(options=None): raise CLIFactoryError(f'Failed to publish new version of content view\n{err.msg}') # Get the content view info cv_info = ContentView.info({'id': cv_id}) + assert len(cv_info['versions']) > 0 lce_promoted = cv_info['lifecycle-environments'] cvv = sorted(cvv['id'] for cvv in cv_info['versions'])[-1] - cvv = cv_info['versions'][-1] # Promote version to next env try: if env_id not in [int(lce['id']) for lce in lce_promoted]: ContentView.version_promote( - {'id': cvv['id'], 'organization-id': org_id, 'to-lifecycle-environment-id': env_id} + { + 'id': cvv['id'], + 'contetn-view-id': cv_id, + 'organization-id': org_id, + 'to-lifecycle-environment-id': env_id, + } ) except CLIReturnCodeError as err: raise CLIFactoryError(f'Failed to promote version to next environment\n{err.msg}') diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index fb4c9f4419e..b0ab1542d2c 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -187,20 +187,13 @@ def function_registered_contenthost( organization=module_org, environment=[module_lce], ).create() - content_view.publish() - latest_cvv_id = sorted(cvv.id for cvv in content_view.read().version)[-1] - latest_cv_version = [ - version for version in content_view.read().version if version.id == latest_cvv_id - ][-1] - latest_cv_version.promote(data={'environment_ids': module_lce.id}) - content_view = content_view.read() activation_key = module_target_sat.api.ActivationKey( organization=module_org, environment=module_lce, - content_view=content_view, ).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, @@ -210,14 +203,7 @@ def function_registered_contenthost( 'content-view-id': content_view.id, } )['repository-id'] - rhel_contenthost.create_custom_repos(repo=repo_url) - rhel_contenthost.execute(r'subscription-manager repos --enable \*') - rhel_contenthost.execute(r'yum-config-manager --enable \*') - 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"])}' - rhel_contenthost.execute(r'subscription-manager refresh') + result = rhel_contenthost.register( activation_keys=activation_key.name, lifecycle_environment=module_lce, @@ -225,51 +211,31 @@ def function_registered_contenthost( org=module_org, loc=None, ) - assert result.status == 0, f'Failed to register host: {result.stderr}' + 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') - rhel_contenthost.execute(f'yum-config-manager --enable {custom_repo_id}') - result = rhel_contenthost.execute(f'subscription-manager repos --enable {custom_repo_id}') - assert ( - result.status == 0 - ), f'Failed to enable custom repo with subscription-manager: {result.stderr}' - assert rhel_contenthost.subscribed, f'Failed to subscribe the registered host: {result.stderr}' + 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"])}' yield rhel_contenthost +from time import time, localtime @pytest.mark.e2e @pytest.mark.tier3 @pytest.mark.rhel_ver_match('8') -@pytest.mark.parametrize( - 'repos_collection', - [ - { - 'distro': 'rhel8', - 'YumRepository': {'url': CUSTOM_REPO_URL}, - 'FileRepository': {'url': CUSTOM_FILE_REPO}, - 'DockerRepository': { - 'url': CONTAINER_REGISTRY_HUB, - 'upstream_name': CONTAINER_UPSTREAM_NAME, - }, - 'AnsibleRepository': { - 'url': ANSIBLE_GALAXY, - 'requirements': [ - {'name': 'theforeman.foreman', 'version': '2.1.0'}, - {'name': 'theforeman.operations', 'version': '0.1.0'}, - ], - }, - } - ], - indirect=True, -) @pytest.mark.no_containers def test_end_to_end( session, - function_registered_contenthost, - module_entitlement_manifest_org, + module_org, module_lce, module_cv, module_target_sat, - repos_collection, + function_registered_contenthost ): """Create all entities required for errata, set up applicable host, read errata details and apply it to host @@ -290,10 +256,10 @@ 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}') + #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', @@ -312,19 +278,38 @@ def test_end_to_end( ], 'module_stream_packages': [], } - assert _install_client_package(function_registered_contenthost, FAKE_1_CUSTOM_PACKAGE) + contenthost = function_registered_contenthost + assert _install_client_package(contenthost, FAKE_1_CUSTOM_PACKAGE) + contenthost.execute('subscription-manager repos') + module_target_sat.cli.Host.errata_recalculate( + {'host-id': 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 + + 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 # Check selection box function for BZ#1688636 - session.location.select(loc_name=DEFAULT_LOC) - 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'] + breakpoint() + session.organization.select(org_name=module_org.name) + #session.location.select(loc_name=) + assert session.errata.search_content_hosts( + CUSTOM_REPO_ERRATA_ID, 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'] # 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. - # TODO: Find a way to account for browser time zone, so that the errata dates displayed + # DONE: Find a way to account for browser time zone, so that the errata dates displayed # in the UI can be compared to the UTC values in ERRATA_DETAILS. assert ( not ERRATA_DETAILS.items() - errata['details'].items() @@ -336,22 +321,31 @@ 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'] - ) + #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( - function_registered_contenthost.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex' + 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(vm.hostname) - function_registered_contenthost = function_registered_contenthost.nailgun_host.read() - assert function_registered_contenthost.applicable_errata_count == 0 + _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 + + assert contenthost.applicable_errata_count == 0 @pytest.mark.tier2