From 2449152943a75c4e34523b985ec9f18675a12abc Mon Sep 17 00:00:00 2001 From: David Moore Date: Wed, 22 Nov 2023 08:14:51 -0500 Subject: [PATCH 1/3] Check RHEL Lifecycle status in ContentHost UI --- tests/foreman/api/test_errata.py | 20 +++++++++- tests/foreman/ui/test_contenthost.py | 55 +++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/tests/foreman/api/test_errata.py b/tests/foreman/api/test_errata.py index bb545dda858..6f9e31316df 100644 --- a/tests/foreman/api/test_errata.py +++ b/tests/foreman/api/test_errata.py @@ -824,9 +824,25 @@ def test_apply_modular_errata_using_default_content_view( stream = '0' version = '20180704244205' - rhel8_contenthost.install_katello_ca(target_sat) + """rhel8_contenthost.install_katello_ca(target_sat) rhel8_contenthost.register_contenthost( module_entitlement_manifest_org.label, rhel8_module_ak.name + )""" + + # Associate custom repos with org, lce, ak: + target_sat.cli_factory.setup_org_for_a_custom_repo( + { + 'organization-id': module_entitlement_manifest_org.id, + 'lifecycle-environment-id': default_lce.id, + 'activationkey-id': rhel8_module_ak.id, + 'content-view-id': rhel8_custom_repo_cv.id, + } + ) + rhel8_contenthost.register( + activation_keys=rhel8_module_ak.name, + target=target_sat, + org=module_entitlement_manifest_org, + loc=None, ) assert rhel8_contenthost.subscribed host = rhel8_contenthost.nailgun_host @@ -834,7 +850,7 @@ def test_apply_modular_errata_using_default_content_view( # Assert no errata on host, no packages applicable or installable errata = _fetch_available_errata(module_entitlement_manifest_org, host, expected_amount=0) assert len(errata) == 0 - rhel8_contenthost.install_katello_host_tools() + # rhel8_contenthost.install_katello_host_tools() # Install older version of module stream to generate the errata result = rhel8_contenthost.execute( f'yum -y module install {module_name}:{stream}:{version}', diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index 4ca6059dfdf..b1b383b5219 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -102,8 +102,38 @@ def run_remote_command_on_content_host(command, vm_module_streams): return result +def get_supported_rhel_versions(): + """Helper to get the supported base rhel versions for contenthost. + return: a list of integers + """ + return [ + ver for ver in settings.supportability.content_hosts.rhel.versions if isinstance(ver, int) + ] + + +def get_rhel_lifecycle_support(rhel_version): + """Helper to get what the Lifecycle Support Status should be, + based on provided rhel version. + :param rhel_version: integer of the current base rhel version + :return: string with the expected status of rhel version support + """ + rhels = get_supported_rhel_versions() + rhel_lifecycle_status = 'Unknown' + if rhel_version not in rhels: + return rhel_lifecycle_status + elif (len(rhels) - 1) - rhels.index(rhel_version) <= 1: + rhel_lifecycle_status = 'Full support' + elif (len(rhels) - 1) - rhels.index(rhel_version) == 2: + rhel_lifecycle_status = 'Approaching end of maintenance support' + elif (len(rhels) - 1) - rhels.index(rhel_version) >= 3: + rhel_lifecycle_status = 'End of maintenance support' + + return rhel_lifecycle_status + + @pytest.mark.e2e @pytest.mark.tier3 +@pytest.mark.parametrize('setting_update', ['new_hosts_page'], indirect=True) @pytest.mark.parametrize( 'module_repos_collection_with_manifest', [ @@ -120,7 +150,14 @@ def run_remote_command_on_content_host(command, vm_module_streams): indirect=True, ) @pytest.mark.no_containers -def test_positive_end_to_end(session, default_location, module_repos_collection_with_manifest, vm): +def test_positive_end_to_end( + vm, + session, + module_org, + setting_update, + default_location, + module_repos_collection_with_manifest, +): """Create all entities required for content host, set up host, register it as a content host, read content host details, install package and errata. @@ -135,11 +172,27 @@ def test_positive_end_to_end(session, default_location, module_repos_collection_ :CaseImportance: Critical """ + property_name = setting_update.name + _distro = module_repos_collection_with_manifest.distro + host_rhel_version = None + if _distro.startswith('rhel'): + host_rhel_version = int(_distro[4:]) + rhel_status = get_rhel_lifecycle_support(host_rhel_version if not None else 0) + result = vm.run(f'yum -y install {FAKE_1_CUSTOM_PACKAGE}') assert result.status == 0 startdate = datetime.utcnow().strftime('%m/%d/%Y') with session: + session.settings.update(f'name = {property_name}', 'Yes') session.location.select(default_location.name) + session.organization.select(module_org.name) + # Use new hosts UI, only check the details and host status + host_details = session.host.get_details(vm.hostname, widget_names='properties') + host_status = session.host_new.get_host_statuses(vm.hostname) + # Use old hosts UI for remainder + session.settings.update(f'name = {property_name}', 'No') + assert rhel_status in host_status['RHEL lifecycle']['Status'] + assert rhel_status in host_details['properties']['properties_table']['RHEL lifecycle'] # Ensure content host is searchable assert session.contenthost.search(vm.hostname)[0]['Name'] == vm.hostname chost = session.contenthost.read( From 962e5496a3e3ac3e77bcf196e3f038e722396cc5 Mon Sep 17 00:00:00 2001 From: David Moore Date: Mon, 11 Dec 2023 09:28:10 -0500 Subject: [PATCH 2/3] Finish extension for RHEL lifecycle status --- tests/foreman/api/test_errata.py | 20 ++------------ tests/foreman/ui/test_contenthost.py | 41 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/tests/foreman/api/test_errata.py b/tests/foreman/api/test_errata.py index 6f9e31316df..bb545dda858 100644 --- a/tests/foreman/api/test_errata.py +++ b/tests/foreman/api/test_errata.py @@ -824,25 +824,9 @@ def test_apply_modular_errata_using_default_content_view( stream = '0' version = '20180704244205' - """rhel8_contenthost.install_katello_ca(target_sat) + rhel8_contenthost.install_katello_ca(target_sat) rhel8_contenthost.register_contenthost( module_entitlement_manifest_org.label, rhel8_module_ak.name - )""" - - # Associate custom repos with org, lce, ak: - target_sat.cli_factory.setup_org_for_a_custom_repo( - { - 'organization-id': module_entitlement_manifest_org.id, - 'lifecycle-environment-id': default_lce.id, - 'activationkey-id': rhel8_module_ak.id, - 'content-view-id': rhel8_custom_repo_cv.id, - } - ) - rhel8_contenthost.register( - activation_keys=rhel8_module_ak.name, - target=target_sat, - org=module_entitlement_manifest_org, - loc=None, ) assert rhel8_contenthost.subscribed host = rhel8_contenthost.nailgun_host @@ -850,7 +834,7 @@ def test_apply_modular_errata_using_default_content_view( # Assert no errata on host, no packages applicable or installable errata = _fetch_available_errata(module_entitlement_manifest_org, host, expected_amount=0) assert len(errata) == 0 - # rhel8_contenthost.install_katello_host_tools() + rhel8_contenthost.install_katello_host_tools() # Install older version of module stream to generate the errata result = rhel8_contenthost.execute( f'yum -y module install {module_name}:{stream}:{version}', diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index b1b383b5219..5132e86487f 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -117,23 +117,21 @@ def get_rhel_lifecycle_support(rhel_version): :param rhel_version: integer of the current base rhel version :return: string with the expected status of rhel version support """ - rhels = get_supported_rhel_versions() + rhels = sorted(get_supported_rhel_versions(), reverse=True) rhel_lifecycle_status = 'Unknown' if rhel_version not in rhels: return rhel_lifecycle_status - elif (len(rhels) - 1) - rhels.index(rhel_version) <= 1: + elif rhels.index(rhel_version) <= 1: rhel_lifecycle_status = 'Full support' - elif (len(rhels) - 1) - rhels.index(rhel_version) == 2: + elif rhels.index(rhel_version) == 2: rhel_lifecycle_status = 'Approaching end of maintenance support' - elif (len(rhels) - 1) - rhels.index(rhel_version) >= 3: + elif rhels.index(rhel_version) >= 3: rhel_lifecycle_status = 'End of maintenance support' - return rhel_lifecycle_status @pytest.mark.e2e @pytest.mark.tier3 -@pytest.mark.parametrize('setting_update', ['new_hosts_page'], indirect=True) @pytest.mark.parametrize( 'module_repos_collection_with_manifest', [ @@ -154,7 +152,6 @@ def test_positive_end_to_end( vm, session, module_org, - setting_update, default_location, module_repos_collection_with_manifest, ): @@ -163,6 +160,16 @@ def test_positive_end_to_end( :id: f43f2826-47c1-4069-9c9d-2410fd1b622c + :setup: Register a rhel7 vm as a content host. Import repos + collection and associated manifest. + + :steps: + 1. Install some outdated version for an applicable package + 2. In legacy Host UI, find the host status and rhel lifecycle status + 3. Using legacy ContentHost UI, find the chost and relevant details + 4. Install the errata, check legacy ContentHost UI and the updated package + 5. Delete the content host, then try to find it + :expectedresults: content host details are the same as expected, package and errata installation are successful @@ -172,7 +179,7 @@ def test_positive_end_to_end( :CaseImportance: Critical """ - property_name = setting_update.name + # Read rhel distro param, determine what rhel lifecycle status should be _distro = module_repos_collection_with_manifest.distro host_rhel_version = None if _distro.startswith('rhel'): @@ -182,19 +189,19 @@ def test_positive_end_to_end( result = vm.run(f'yum -y install {FAKE_1_CUSTOM_PACKAGE}') assert result.status == 0 startdate = datetime.utcnow().strftime('%m/%d/%Y') + with session: - session.settings.update(f'name = {property_name}', 'Yes') session.location.select(default_location.name) session.organization.select(module_org.name) - # Use new hosts UI, only check the details and host status - host_details = session.host.get_details(vm.hostname, widget_names='properties') - host_status = session.host_new.get_host_statuses(vm.hostname) - # Use old hosts UI for remainder - session.settings.update(f'name = {property_name}', 'No') - assert rhel_status in host_status['RHEL lifecycle']['Status'] - assert rhel_status in host_details['properties']['properties_table']['RHEL lifecycle'] + # Ensure host status and details show correct RHEL lifecycle status + host_status = session.host.host_status(vm.hostname) + host_rhel_lcs = session.contenthost.read(vm.hostname, widget_names=['permission_denied']) + assert rhel_status in host_rhel_lcs['permission_denied'] + assert rhel_status in host_status # Ensure content host is searchable - assert session.contenthost.search(vm.hostname)[0]['Name'] == vm.hostname + found_chost = session.contenthost.search(f'{vm.hostname}') + assert found_chost, f'Search for contenthost by name: "{vm.hostname}", returned no results.' + assert found_chost[0]['Name'] == vm.hostname chost = session.contenthost.read( vm.hostname, widget_names=['details', 'provisioning_details', 'subscriptions'] ) From be6862e5a42d3a664ac1bd122c31aa7d26793072 Mon Sep 17 00:00:00 2001 From: David Moore Date: Wed, 13 Dec 2023 15:00:42 -0500 Subject: [PATCH 3/3] Intermittent prt failures for search, errata install --- tests/foreman/ui/test_contenthost.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index 5132e86487f..28ea37df065 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -193,11 +193,6 @@ def test_positive_end_to_end( with session: session.location.select(default_location.name) session.organization.select(module_org.name) - # Ensure host status and details show correct RHEL lifecycle status - host_status = session.host.host_status(vm.hostname) - host_rhel_lcs = session.contenthost.read(vm.hostname, widget_names=['permission_denied']) - assert rhel_status in host_rhel_lcs['permission_denied'] - assert rhel_status in host_status # Ensure content host is searchable found_chost = session.contenthost.search(f'{vm.hostname}') assert found_chost, f'Search for contenthost by name: "{vm.hostname}", returned no results.' @@ -242,6 +237,11 @@ def test_positive_end_to_end( assert startdate in custom_sub['Expires'] else: assert startdate in custom_sub['Starts'] + # Ensure host status and details show correct RHEL lifecycle status + host_status = session.host.host_status(vm.hostname) + host_rhel_lcs = session.contenthost.read(vm.hostname, widget_names=['permission_denied']) + assert rhel_status in host_rhel_lcs['permission_denied'] + assert rhel_status in host_status # Update description new_description = gen_string('alpha') session.contenthost.update(vm.hostname, {'details.description': new_description}) @@ -256,9 +256,7 @@ def test_positive_end_to_end( packages = session.contenthost.search_package(vm.hostname, FAKE_0_CUSTOM_PACKAGE_NAME) assert packages[0]['Installed Package'] == FAKE_0_CUSTOM_PACKAGE # Install errata - result = session.contenthost.install_errata( - vm.hostname, settings.repos.yum_6.errata[2], install_via='rex' - ) + result = session.contenthost.install_errata(vm.hostname, FAKE_1_ERRATA_ID) assert result['overview']['hosts_table'][0]['Status'] == 'success' # Ensure errata installed packages = session.contenthost.search_package(vm.hostname, FAKE_2_CUSTOM_PACKAGE_NAME)