From 5974f1bf74ce65e6ca0df7e3384b3a7323569373 Mon Sep 17 00:00:00 2001 From: Jameer Pathan <21165044+jameerpathan111@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:48:24 +0200 Subject: [PATCH] refactor rh_cloud tests --- robottelo/hosts.py | 2 + tests/foreman/api/test_rhcloud_inventory.py | 197 ++++---------------- tests/foreman/cli/test_rhcloud_insights.py | 60 ------ tests/foreman/cli/test_rhcloud_inventory.py | 2 +- tests/foreman/ui/test_rhcloud_insights.py | 25 +-- 5 files changed, 44 insertions(+), 242 deletions(-) delete mode 100644 tests/foreman/cli/test_rhcloud_insights.py diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 727e4f98c87..e07b4fbd2f6 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1158,6 +1158,8 @@ def configure_rhai_client( # Register client if self.execute('insights-client --register').status != 0: raise ContentHostError('Unable to register client to Insights through Satellite') + if self.execute('insights-client --test-connection').status != 0: + raise ContentHostError('Test connection failed via insights.') def unregister_insights(self): """Unregister insights client. diff --git a/tests/foreman/api/test_rhcloud_inventory.py b/tests/foreman/api/test_rhcloud_inventory.py index 178797abb4a..0208aed3040 100644 --- a/tests/foreman/api/test_rhcloud_inventory.py +++ b/tests/foreman/api/test_rhcloud_inventory.py @@ -66,10 +66,11 @@ def test_rhcloud_inventory_api_e2e( 8. metadata contains source and foreman_rh_cloud_version keys. 9. Assert Hostnames, IP addresses, infrastructure type, and installed packages are present in report. + 10. Assert that system_purpose_sla field is present in the inventory report. :CaseImportance: Critical - :BZ: 1807829, 1926100, 1965234, 1824183, 1879453 + :BZ: 1807829, 1926100, 1965234, 1824183, 1879453, 1845113 :customerscenario: true """ @@ -83,18 +84,20 @@ def test_rhcloud_inventory_api_e2e( destination=local_report_path ) common_assertion(local_report_path) - # Assert Hostnames, IP addresses, and installed packages are present in report. json_data = get_report_data(local_report_path) json_meta_data = get_report_metadata(local_report_path) + # Verify that metadata contains source and foreman_rh_cloud_version keys. prefix = 'tfm-' if module_target_sat.os_version.major < 8 else '' package_version = module_target_sat.run( f'rpm -qa --qf "%{{VERSION}}" {prefix}rubygem-foreman_rh_cloud' ).stdout.strip() assert json_meta_data['source_metadata']['foreman_rh_cloud_version'] == str(package_version) assert json_meta_data['source'] == 'Satellite' + # Verify Hostnames are present in report. hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames + # Verify IP addresses are present in report. ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'][0] for host in json_data['hosts'] @@ -104,16 +107,21 @@ def test_rhcloud_inventory_api_e2e( assert baremetal_host.ip_addr in ip_addresses assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses - + # Verify infrastructure type. infrastructure_type = [ host['system_profile']['infrastructure_type'] for host in json_data['hosts'] ] assert 'physical' and 'virtual' in infrastructure_type - + # Verify installed packages are present in report. all_host_profiles = [host['system_profile'] for host in json_data['hosts']] for host_profiles in all_host_profiles: assert 'installed_packages' in host_profiles assert len(host_profiles['installed_packages']) > 1 + # Verify that system_purpose_sla field is present in the inventory report. + for host in json_data['hosts']: + assert host['facts'][0]['facts']['system_purpose_role'] == 'test-role' + assert host['facts'][0]['facts']['system_purpose_sla'] == 'Self-Support' + assert host['facts'][0]['facts']['system_purpose_usage'] == 'test-usage' @pytest.mark.e2e @@ -136,7 +144,7 @@ def test_rhcloud_inventory_api_hosts_synchronization( 5. Assert inventory status for the host. :expectedresults: - 1. Task detail should contain should contain number of hosts + 1. Task detail should contain number of hosts synchronized and disconnected. :BZ: 1970223 @@ -157,53 +165,6 @@ def test_rhcloud_inventory_api_hosts_synchronization( # To Do: Add support in Nailgun to get Insights and Inventory host properties. -@pytest.mark.run_in_one_thread -@pytest.mark.tier2 -def test_system_purpose_sla_field( - inventory_settings, - rhcloud_manifest_org, - rhcloud_registered_hosts, - module_target_sat, -): - """Verify that system_purpose_sla field is present in the inventory report - for the host subscribed using Activation key with service level set in it. - - :id: 3974338c-3a66-41ac-af32-ee76e3c37aef - - :customerscenario: true - - :Steps: - 1. Create an activation key with service level set in it. - 2. Register a content host using the created activation key. - 3. Generate inventory report. - 4. Assert that host is listed in the inventory report. - 5. Assert that system_purpose_sla field is present in the inventory report. - - :CaseImportance: Medium - - :expectedresults: - 1. Host is present in the inventory report. - 2. system_purpose_sla field is present in the inventory report. - - :BZ: 1845113 - - :CaseAutomation: Automated - """ - org = rhcloud_manifest_org - virtual_host, baremetal_host = rhcloud_registered_hosts - local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') - module_target_sat.generate_inventory_report(org) - # Download report - module_target_sat.api.Organization(id=org.id).rh_cloud_download_report( - destination=local_report_path - ) - json_data = get_report_data(local_report_path) - for host in json_data['hosts']: - assert host['facts'][0]['facts']['system_purpose_role'] == 'test-role' - assert host['facts'][0]['facts']['system_purpose_sla'] == 'Self-Support' - assert host['facts'][0]['facts']['system_purpose_usage'] == 'test-usage' - - @pytest.mark.stubbed def test_rhcloud_inventory_auto_upload_setting(): """Verify that Automatic inventory upload setting works as expected. @@ -227,7 +188,7 @@ def test_rhcloud_inventory_auto_upload_setting(): 2. If "Automatic inventory upload" setting is disable then satellite does not generate and upload inventory report automatically. - :BZ: 1793017 + :BZ: 1793017, 1865879 :CaseAutomation: ManualOnly """ @@ -244,8 +205,8 @@ def test_inventory_upload_with_http_proxy(): :Steps: 1. Create a http proxy which is using port 80. - 2. Register a content host with satellite. - 3. Set Default HTTP Proxy setting. + 2. Update general and content proxy in Satellite settings. + 3. Register a content host with satellite. 4. Generate and upload inventory report. 5. Assert that host is listed in the inventory report. 6. Assert that upload process finished successfully. @@ -276,14 +237,20 @@ def test_include_parameter_tags_setting( :Steps: 1. Enable include_parameter_tags setting. 2. Register a content host with satellite. - 3. Generate inventory report. - 4. Assert that generated report contains valid json file. + 3. Create a host parameter with long text value. + 4. Create Hostcollection with name containing double quotes. + 5. Generate inventory report. + 6. Assert that generated report contains valid json file. + 7. Observe the tag generated from the parameter. :expectedresults: 1. Valid json report is created. 2. satellite_parameter values are string. + 3. Parameter tag value must not be created after the + allowed length. + 4. Tag value is escaped properly. - :BZ: 1981869, 1967438 + :BZ: 1981869, 1967438, 2035204, 1874587, 1874619 :customerscenario: true @@ -291,113 +258,21 @@ def test_include_parameter_tags_setting( """ org = rhcloud_manifest_org virtual_host, baremetal_host = rhcloud_registered_hosts - local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') - module_target_sat.update_setting('include_parameter_tags', True) - module_target_sat.generate_inventory_report(org) - # Download report - module_target_sat.api.Organization(id=org.id).rh_cloud_download_report( - destination=local_report_path - ) - json_data = get_report_data(local_report_path) - common_assertion(local_report_path) - for host in json_data['hosts']: - for tag in host['tags']: - if tag['namespace'] == 'satellite_parameter': - assert type(tag['value']) is str - break - - -@pytest.mark.tier3 -def test_rh_cloud_tag_values( - inventory_settings, - rhcloud_manifest_org, - module_target_sat, - rhcloud_registered_hosts, -): - """Verify that tag values are escaped properly when hostgroup name - contains " (double quote) in it. - - :id: ea7cd7ca-4157-4aac-ad8e-e66b88740ce3 - - :customerscenario: true - - :Steps: - 1. Create Hostcollection with name containing double quotes. - 2. Register a content host with satellite. - 3. Add a content host to hostgroup. - 4. Generate inventory report. - 5. Assert that generated report contains valid json file. - 6. Assert that hostcollection tag value is escaped properly. - - :expectedresults: - 1. Valid json report is created. - 2. Tag value is escaped properly. - - :BZ: 1874587, 1874619 - - :CaseAutomation: Automated - """ - org = rhcloud_manifest_org - + # Create a host parameter with long text value. + param_name = gen_string('alpha') + param_value = gen_string('alpha', length=260) + module_target_sat.api.CommonParameter(name=param_name, value=param_value).create() + # Create Hostcollection with name containing double quotes. host_col_name = gen_string('alpha') host_name = rhcloud_registered_hosts[0].hostname host = module_target_sat.api.Host().search(query={'search': host_name})[0] host_collection = module_target_sat.api.HostCollection( organization=org, name=f'"{host_col_name}"', host=[host] ).create() - assert len(host_collection.host) == 1 + # Generate inventory report local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') - # Generate report - module_target_sat.generate_inventory_report(org) - module_target_sat.api.Organization(id=org.id).rh_cloud_download_report( - destination=local_report_path - ) - common_assertion(local_report_path) - json_data = get_report_data(local_report_path) - for host in json_data['hosts']: - if host['fqdn'] == host_name: - for tag in host['tags']: - if tag['key'] == 'host_collection': - assert tag['value'] == f'"{host_col_name}"' - break - - -@pytest.mark.run_in_one_thread -@pytest.mark.tier2 -def test_positive_tag_values_max_length( - inventory_settings, - rhcloud_manifest_org, - rhcloud_registered_hosts, - module_target_sat, - target_sat, -): - """Verify that tags values are truncated properly for the host parameter - with max length. - - :id: dbcc7245-88af-4c35-87b8-92de01030cb5 - - :Steps: - 1. Enable include_parameter_tags setting - 2. Create a host parameter with long text value. - 3. Generate a rh_cloud report. - 4. Observe the tag generated from the parameter. - - :expectedresults: - 1. Parameter tag value must not be created after the - allowed length. - - :BZ: 2035204 - - :CaseAutomation: Automated - """ - - param_name = gen_string('alpha') - param_value = gen_string('alpha', length=260) - target_sat.api.CommonParameter(name=param_name, value=param_value).create() - - org = rhcloud_manifest_org - local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') + # Enable include_parameter_tags setting module_target_sat.update_setting('include_parameter_tags', True) module_target_sat.generate_inventory_report(org) # Download report @@ -406,8 +281,16 @@ def test_positive_tag_values_max_length( ) json_data = get_report_data(local_report_path) common_assertion(local_report_path) + # Verify that parameter tag value is not be created. for host in json_data['hosts']: for tag in host['tags']: if tag['key'] == param_name: assert tag['value'] == "Original value exceeds 250 characters" break + # Verify that hostcollection tag value is escaped properly. + for host in json_data['hosts']: + if host['fqdn'] == host_name: + for tag in host['tags']: + if tag['key'] == 'host_collection': + assert tag['value'] == f'"{host_col_name}"' + break diff --git a/tests/foreman/cli/test_rhcloud_insights.py b/tests/foreman/cli/test_rhcloud_insights.py deleted file mode 100644 index 9682fc0d86c..00000000000 --- a/tests/foreman/cli/test_rhcloud_insights.py +++ /dev/null @@ -1,60 +0,0 @@ -"""CLI tests for Insights part of RH Cloud - Inventory plugin. - -:Requirement: RH Cloud - Inventory - -:CaseAutomation: Automated - -:CaseLevel: System - -:CaseComponent: RHCloud-Inventory - -:Team: Platform - -:TestType: Functional - -:CaseImportance: High - -:Upstream: No -""" -import pytest -from broker import Broker - -from robottelo.hosts import ContentHost - - -@pytest.mark.e2e -@pytest.mark.tier4 -@pytest.mark.parametrize('distro', ['rhel7', 'rhel8']) -def test_positive_connection_option( - rhcloud_activation_key, rhcloud_manifest_org, module_target_sat, distro -): - """Verify that 'insights-client --test-connection' successfully tests the proxy connection via - the Satellite. - - :id: 61a4a39e-b484-49f4-a6fd-46ffc7736e50 - - :customerscenario: true - - :Steps: - - 1. Create RHEL7 and RHEL8 VM and register to insights within org having manifest. - - 2. Run 'insights-client --test-connection'. - - :expectedresults: 'insights-client --test-connection' should return 0. - - :BZ: 1976754 - - :CaseImportance: Critical - """ - org = rhcloud_manifest_org - ak = rhcloud_activation_key - with Broker(nick=distro, host_class=ContentHost) as vm: - vm.configure_rhai_client(module_target_sat, ak.name, org.label, distro) - result = vm.run('insights-client --test-connection') - assert result.status == 0, ( - 'insights-client --test-connection failed.\n' - f'status: {result.status}\n' - f'stdout: {result.stdout}\n' - f'stderr: {result.stderr}' - ) diff --git a/tests/foreman/cli/test_rhcloud_inventory.py b/tests/foreman/cli/test_rhcloud_inventory.py index 0330420dd45..34d2f4a989f 100644 --- a/tests/foreman/cli/test_rhcloud_inventory.py +++ b/tests/foreman/cli/test_rhcloud_inventory.py @@ -209,7 +209,7 @@ def test_max_org_size_variable(): 1. Register few content hosts with satellite. 2. Change value of max_org_size for testing purpose(See BZ#1962694#c2). 3. Start report generation and upload using - ForemanInventoryUpload::Async::GenerateAllReportsJob.perform_now + ForemanTasks.sync_task(ForemanInventoryUpload::Async::GenerateAllReportsJob) :expectedresults: If organization had more hosts than specified by max_org_size variable then report won't be uploaded. diff --git a/tests/foreman/ui/test_rhcloud_insights.py b/tests/foreman/ui/test_rhcloud_insights.py index a57488414e3..861450011b4 100644 --- a/tests/foreman/ui/test_rhcloud_insights.py +++ b/tests/foreman/ui/test_rhcloud_insights.py @@ -64,7 +64,7 @@ def test_rhcloud_insights_e2e( :CaseImportance: Critical - :BZ: 1965901, 1962048 + :BZ: 1965901, 1962048, 1976754 :customerscenario: true @@ -189,29 +189,6 @@ def test_recommendation_sync_for_satellite(): """ -@pytest.mark.stubbed -def test_allow_auto_insights_sync_setting(): - """Test "allow_auto_insights_sync" setting. - - :id: ddc4ed5b-43c0-4121-bf2c-b8e040e45379 - - :Steps: - 1. Register few satellite content host with insights. - 2. Enable "allow_auto_insights_sync" setting. - 3. Wait for "InsightsScheduledSync" task to run. - - :expectedresults: - 1. Satellite has "Inventory scheduled sync" recurring logic, which syncs - inventory status automatically if "Automatic inventory upload" setting is enabled. - - :CaseImportance: Medium - - :BZ: 1865879 - - :CaseAutomation: ManualOnly - """ - - @pytest.mark.stubbed def test_host_sorting_based_on_recommendation_count(): """Verify that hosts can be sorted and filtered based on insights