def test_rhcloud_inventory_e2e( inventory_settings, organization_ak_setup, registered_hosts, session ): """Generate report and verify its basic properties :id: 833bd61d-d6e7-4575-887a-9e0729d0fa76 :customerscenario: true :expectedresults: 1. Report can be generated 2. Report can be downloaded 3. Report has non-zero size 4. Report can be extracted 5. JSON files inside report can be parsed 6. metadata.json lists all and only slice JSON files in tar 7. Host counts in metadata matches host counts in slices 8. Assert Hostnames, IP addresses, and installed packages are present in report. :BZ: 1807829, 1926100 """ org, ak = organization_ak_setup virtual_host, baremetal_host = registered_hosts with session: session.organization.select(org_name=org.name) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) wait_for_tasks( search_query='label = ForemanInventoryUpload::Async::GenerateReportJob' f' and started_at >= "{timestamp}"', search_rate=15, max_tries=10, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) common_assertion(report_path, inventory_data, org) json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'][0] for host in json_data['hosts'] ] ipv4_addresses = [host['ip_addresses'][0] for host in json_data['hosts']] assert virtual_host.ip_addr in ip_addresses assert baremetal_host.ip_addr in ip_addresses assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses 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
def test_rh_cloud_tag_values( inventory_settings, organization_ak_setup, rhcloud_sat_host, 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, ak = organization_ak_setup host_col_name = gen_string('alpha') host_name = rhcloud_registered_hosts[0].hostname host = rhcloud_sat_host.api.Host().search(query={'search': host_name})[0] host_collection = rhcloud_sat_host.api.HostCollection( organization=org, name=f'"{host_col_name}"', host=[host] ).create() assert len(host_collection.host) == 1 local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') # Generate report generate_inventory_report(rhcloud_sat_host, org) rhcloud_sat_host.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
def test_positive_tag_values_max_length( inventory_settings, organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host, 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, ak = organization_ak_setup local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') rhcloud_sat_host.update_setting('include_parameter_tags', True) generate_inventory_report(rhcloud_sat_host, org) # Download report rhcloud_sat_host.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['key'] == param_name: assert tag['value'] == "Original value exceeds 250 characters" break
def test_include_parameter_tags_setting( inventory_settings, organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host ): """Verify that include_parameter_tags setting doesn't cause invalid report to be generated. :id: 3136a1e3-f844-416b-8334-75b27fd9e3a1 :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. :expectedresults: 1. Valid json report is created. 2. satellite_parameter values are string. :BZ: 1981869, 1967438 :customerscenario: true :CaseAutomation: Automated """ org, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') rhcloud_sat_host.update_setting('include_parameter_tags', True) generate_inventory_report(rhcloud_sat_host, org) # Download report rhcloud_sat_host.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
def test_system_purpose_sla_field( inventory_settings, organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host ): """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, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') generate_inventory_report(rhcloud_sat_host, org) # Download report rhcloud_sat_host.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'
def test_rhcloud_inventory_e2e(inventory_settings, organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host): """Generate report and verify its basic properties :id: 833bd61d-d6e7-4575-887a-9e0729d0fa76 :customerscenario: true :expectedresults: 1. Report can be generated 2. Report can be downloaded 3. Report has non-zero size 4. Report can be extracted 5. JSON files inside report can be parsed 6. metadata.json lists all and only slice JSON files in tar 7. Host counts in metadata matches host counts in slices 8. Assert Hostnames, IP addresses, and installed packages are present in report. :CaseImportance: Critical :BZ: 1807829, 1926100 """ org, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts with Session(hostname=rhcloud_sat_host.hostname) as session: session.organization.select(org_name=org.name) session.location.select(loc_name=DEFAULT_LOC) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) wait_for( lambda: rhcloud_sat_host.api.ForemanTask().search( query={ 'search': f'label = ForemanInventoryUpload::Async::GenerateReportJob ' f'and started_at >= "{timestamp}"' })[0].result == 'success', timeout=400, delay=15, silent_failure=True, handle_exception=True, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) common_assertion(report_path, inventory_data, org, rhcloud_sat_host) json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'][0] for host in json_data['hosts'] ] ipv4_addresses = [host['ip_addresses'][0] for host in json_data['hosts']] assert virtual_host.ip_addr in ip_addresses assert baremetal_host.ip_addr in ip_addresses assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses 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
def test_exclude_packages_setting(rhcloud_sat_host, inventory_settings, organization_ak_setup, rhcloud_registered_hosts): """Test whether `Exclude Packages` setting works as expected. :id: 646093fa-fdd6-4f70-82aa-725e31fa3f12 :customerscenario: true :Steps: 1. Prepare machine and upload its data to Insights 2. Add Cloud API key in Satellite 3. Go to Configure > Inventory upload > enable “Exclude Packages” setting. 4. Generate report after enabling the setting. 5. Check if packages are excluded from generated reports. 6. Disable previous setting. 7. Go to Administer > Settings > RH Cloud and enable "Don't upload installed packages" setting. 8. Generate report after enabling the setting. 9. Check if packages are excluded from generated reports. :expectedresults: 1. Packages are excluded from reports generated. :BZ: 1852594 :CaseAutomation: Automated """ org, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts with Session(hostname=rhcloud_sat_host.hostname) as session: session.organization.select(org_name=org.name) session.location.select(loc_name=DEFAULT_LOC) # Enable exclude_packages setting on inventory page. session.cloudinventory.update({'exclude_packages': True}) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) wait_for( lambda: rhcloud_sat_host.api.ForemanTask().search( query={ 'search': f'label = ForemanInventoryUpload::Async::GenerateReportJob ' f'and started_at >= "{timestamp}"' })[0].result == 'success', timeout=400, delay=15, silent_failure=True, handle_exception=True, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) assert inventory_data['exclude_packages'] is True # Disable exclude_packages setting on inventory page. session.cloudinventory.update({'exclude_packages': False}) # Assert that generated archive is valid. common_assertion(report_path, inventory_data, org, rhcloud_sat_host) # Get report data for assertion json_data = get_report_data(report_path) # Assert that right hosts 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 # Assert that packages are excluded from report all_host_profiles = [ host['system_profile'] for host in json_data['hosts'] ] for host_profiles in all_host_profiles: assert 'installed_packages' not in host_profiles # Enable exclude_installed_packages setting. rhcloud_sat_host.update_setting('exclude_installed_packages', True) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) wait_for( lambda: rhcloud_sat_host.api.ForemanTask().search( query={ 'search': f'label = ForemanInventoryUpload::Async::GenerateReportJob ' f'and started_at >= "{timestamp}"' })[0].result == 'success', timeout=400, delay=15, silent_failure=True, handle_exception=True, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) assert inventory_data['exclude_packages'] is True json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames all_host_profiles = [ host['system_profile'] for host in json_data['hosts'] ] for host_profiles in all_host_profiles: assert 'installed_packages' not in host_profiles
def test_obfuscate_host_ipv4_addresses(rhcloud_sat_host, inventory_settings, organization_ak_setup, rhcloud_registered_hosts): """Test whether `Obfuscate host ipv4 addresses` setting works as expected. :id: c0fc4ee9-a6a1-42c0-83f0-0f131ca9ab41 :customerscenario: true :Steps: 1. Prepare machine and upload its data to Insights 2. Add Cloud API key in Satellite 3. Go to Configure > Inventory upload > enable “Obfuscate host ipv4 addresses” setting. 4. Generate report after enabling the setting. 5. Check if hosts ipv4 addresses are obfuscated in generated reports. 6. Disable previous setting. 7. Go to Administer > Settings > RH Cloud and enable "Obfuscate IPs" setting. 8. Generate report after enabling the setting. 9. Check if hosts ipv4 addresses are obfuscated in generated reports. :expectedresults: 1. Obfuscated host ipv4 addresses in generated reports. :BZ: 1852594, 1889690 :CaseAutomation: Automated """ org, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts with Session(hostname=rhcloud_sat_host.hostname) as session: session.organization.select(org_name=org.name) session.location.select(loc_name=DEFAULT_LOC) # Enable obfuscate_ips setting on inventory page. session.cloudinventory.update({'obfuscate_ips': True}) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) # wait_for_tasks report generation task to finish. wait_for( lambda: rhcloud_sat_host.api.ForemanTask().search( query={ 'search': f'label = ForemanInventoryUpload::Async::GenerateReportJob ' f'and started_at >= "{timestamp}"' })[0].result == 'success', timeout=400, delay=15, silent_failure=True, handle_exception=True, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) # Assert that obfuscate_ips is enabled. assert inventory_data['obfuscate_ips'] is True # Assert that generated archive is valid. common_assertion(report_path, inventory_data, org, rhcloud_sat_host) # Get report data for assertion json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames # Assert that ip_addresses are obfuscated from report. ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'] [0] for host in json_data['hosts'] ] ipv4_addresses = [ host['ip_addresses'][0] for host in json_data['hosts'] ] assert virtual_host.ip_addr not in ip_addresses assert baremetal_host.ip_addr not in ip_addresses assert virtual_host.ip_addr not in ipv4_addresses assert baremetal_host.ip_addr not in ipv4_addresses # Disable obfuscate_ips setting on inventory page. session.cloudinventory.update({'obfuscate_ips': False}) # Enable obfuscate_inventory_ips setting. rhcloud_sat_host.update_setting('obfuscate_inventory_ips', True) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) # wait_for_tasks report generation task to finish. wait_for( lambda: rhcloud_sat_host.api.ForemanTask().search( query={ 'search': f'label = ForemanInventoryUpload::Async::GenerateReportJob ' f'and started_at >= "{timestamp}"' })[0].result == 'success', timeout=400, delay=15, silent_failure=True, handle_exception=True, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) assert inventory_data['obfuscate_ips'] is True # Get report data for assertion json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'] [0] for host in json_data['hosts'] ] ipv4_addresses = [ host['ip_addresses'][0] for host in json_data['hosts'] ] assert virtual_host.ip_addr not in ip_addresses assert baremetal_host.ip_addr not in ip_addresses assert virtual_host.ip_addr not in ipv4_addresses assert baremetal_host.ip_addr not in ipv4_addresses
def test_rhcloud_inventory_api_e2e( inventory_settings, organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host ): """Generate report using rh_cloud plugin api's and verify its basic properties. :id: 8ead1ff6-a8f5-461b-9dd3-f50d96d6ed57 :expectedresults: 1. Report can be generated 2. Report can be downloaded 3. Report has non-zero size 4. Report can be extracted 5. JSON files inside report can be parsed 6. metadata.json lists all and only slice JSON files in tar 7. Host counts in metadata matches host counts in slices 8. metadata contains source and foreman_rh_cloud_version keys. 9. Assert Hostnames, IP addresses, infrastructure type, and installed packages are present in report. :CaseImportance: Critical :BZ: 1807829, 1926100, 1965234, 1824183, 1879453 :customerscenario: true """ org, ak = organization_ak_setup virtual_host, baremetal_host = rhcloud_registered_hosts local_report_path = robottelo_tmp_dir.joinpath(f'{gen_alphanumeric()}_{org.id}.tar.xz') # Generate report generate_inventory_report(rhcloud_sat_host, org) # Download report rhcloud_sat_host.api.Organization(id=org.id).rh_cloud_download_report( 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) prefix = 'tfm-' if rhcloud_sat_host.os_version.major < 8 else '' package_version = rhcloud_sat_host.run( f'rpm -qa --qf "%{{VERSION}}" {prefix}rubygem-foreman_rh_cloud' ) assert json_meta_data['source_metadata']['foreman_rh_cloud_version'] == str(package_version) assert json_meta_data['source'] == 'Satellite' hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname in hostnames assert baremetal_host.hostname in hostnames ip_addresses = [ host['system_profile']['network_interfaces'][0]['ipv4_addresses'][0] for host in json_data['hosts'] ] ipv4_addresses = [host['ip_addresses'][0] for host in json_data['hosts']] assert virtual_host.ip_addr in ip_addresses assert baremetal_host.ip_addr in ip_addresses assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses infrastructure_type = [ host['system_profile']['infrastructure_type'] for host in json_data['hosts'] ] assert 'physical' and 'virtual' in infrastructure_type 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
def test_obfuscate_host_names(inventory_settings, organization_ak_setup, registered_hosts, session): """Test whether `Obfuscate host names` setting works as expected. :id: 3c3a36b6-6566-446b-b803-3f8f9aab2511 :Steps: 1. Prepare machine and upload its data to Insights 2. Add Cloud API key in Satellite 3. Go to Configure > Inventory upload > enable “Obfuscate host names” setting. 4. Generate report after enabling the setting. 5. Check if host names are obfuscated in generated reports. 6. Disable previous setting. 7. Go to Administer > Settings > RH Cloud and enable "Obfuscate host names" setting. 8. Generate report after enabling the setting. 9. Check if host names are obfuscated in generated reports. :expectedresults: 1. Obfuscated host names in reports generated. :CaseAutomation: Automated """ org, ak = organization_ak_setup virtual_host, baremetal_host = registered_hosts with session: session.organization.select(org_name=org.name) # Enable obfuscate_hostnames setting on inventory page. session.cloudinventory.update({'obfuscate_hostnames': True}) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) # wait_for_tasks report generation task to finish. wait_for_tasks( search_query='label = ForemanInventoryUpload::Async::GenerateReportJob' f' and started_at >= "{timestamp}"', search_rate=15, max_tries=10, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) # Assert that obfuscate_hostnames is enabled. assert inventory_data['obfuscate_hostnames'] is True # Assert that generated archive is valid. common_assertion(report_path, inventory_data, org) # Get report data for assertion json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname not in hostnames assert baremetal_host.hostname not in hostnames # Assert that host ip_addresses are present in the report. ipv4_addresses = [host['ip_addresses'][0] for host in json_data['hosts']] assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses # Disable obfuscate_hostnames setting on inventory page. session.cloudinventory.update({'obfuscate_hostnames': False}) # Enable obfuscate_hostnames setting. setting_update('obfuscate_inventory_hostnames', True) timestamp = (datetime.utcnow() - timedelta(minutes=2)).strftime('%Y-%m-%d %H:%M') session.cloudinventory.generate_report(org.name) # wait_for_tasks report generation task to finish. wait_for_tasks( search_query='label = ForemanInventoryUpload::Async::GenerateReportJob' f' and started_at >= "{timestamp}"', search_rate=15, max_tries=10, ) report_path = session.cloudinventory.download_report(org.name) inventory_data = session.cloudinventory.read(org.name) assert inventory_data['obfuscate_hostnames'] is True json_data = get_report_data(report_path) hostnames = [host['fqdn'] for host in json_data['hosts']] assert virtual_host.hostname not in hostnames assert baremetal_host.hostname not in hostnames ipv4_addresses = [host['ip_addresses'][0] for host in json_data['hosts']] assert virtual_host.ip_addr in ipv4_addresses assert baremetal_host.ip_addr in ipv4_addresses