def oscap_content_path(default_sat): """Download scap content from satellite and return local path of it.""" local_file = robottelo_tmp_dir.joinpath( PurePath(settings.oscap.content_path).name) default_sat.put(remote_path=settings.oscap.content_path, local_path=local_file) return local_file
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_positive_inventory_generate_upload_cli(organization_ak_setup, rhcloud_registered_hosts, rhcloud_sat_host): """Tests Insights inventory generation and upload via foreman-rake commands: https://github.com/theforeman/foreman_rh_cloud/blob/master/README.md :id: f2da9506-97d4-4d1c-b373-9f71a52b8ab8 :customerscenario: true :Steps: 0. Create a VM and register to insights within org having manifest. 1. Generate and upload report for all organizations # /usr/sbin/foreman-rake rh_cloud_inventory:report:generate_upload 2. Generate and upload report for specific organization # export organization_id=1 # /usr/sbin/foreman-rake rh_cloud_inventory:report:generate_upload 3. Generate report for specific organization (don't upload) # export organization_id=1 # export target=/var/lib/foreman/red_hat_inventory/generated_reports/ # /usr/sbin/foreman-rake rh_cloud_inventory:report:generate 4. Upload previously generated report (needs to be named 'report_for_#{organization_id}.tar.gz') # export organization_id=1 # export target=/var/lib/foreman/red_hat_inventory/generated_reports/ # /usr/sbin/foreman-rake rh_cloud_inventory:report:upload :expectedresults: Inventory is generated and uploaded to cloud.redhat.com. :BZ: 1957129, 1895953, 1956190 :CaseAutomation: Automated :CaseLevel: System """ org, _ = organization_ak_setup cmd = f'organization_id={org.id} foreman-rake rh_cloud_inventory:report:generate_upload' upload_success_msg = f"Generated and uploaded inventory report for organization '{org.name}'" result = rhcloud_sat_host.execute(cmd) assert result.status == 0 assert upload_success_msg in result.stdout local_report_path = robottelo_tmp_dir.joinpath( f'report_for_{org.id}.tar.xz') remote_report_path = ( f'/var/lib/foreman/red_hat_inventory/uploads/done/report_for_{org.id}.tar.xz' ) rhcloud_sat_host.get(remote_path=remote_report_path, local_path=local_report_path) local_file_data = get_local_file_data(local_report_path) assert local_file_data['checksum'] == get_remote_report_checksum( rhcloud_sat_host, org.id) assert local_file_data['size'] > 0 assert local_file_data['extractable'] assert local_file_data['json_files_parsable'] slices_in_metadata = set(local_file_data['metadata_counts'].keys()) slices_in_tar = set(local_file_data['slices_counts'].keys()) assert slices_in_metadata == slices_in_tar for slice_name, hosts_count in local_file_data['metadata_counts'].items(): assert hosts_count == local_file_data['slices_counts'][slice_name]
def oscap_content_path(default_sat): _, file_name = os.path.split(settings.oscap.content_path) local_file = robottelo_tmp_dir.joinpath(file_name) default_sat.get(remote_path=settings.oscap.content_path, local_path=local_file) return local_file
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_positive_schedule_generation_and_get_mail(session, module_manifest_org, module_location, target_sat): """Schedule generating a report. Request the result be sent via e-mail. :id: cd19b90d-836f-4efd-c3bc-d5e09a909a67 :setup: User with reporting access rights, some Host, Org with imported manifest :steps: 1. Monitor -> Report Templates 2. Host - Registered Content Hosts -> Generate 3. Set schedule to current time + 1 minute 4. Check that the result should be sent via e-mail 5. Submit 6. Receive the e-mail :expectedresults: After ~1 minute, the same report is generated as if the results were downloaded from WebUI. The result is compressed. :CaseImportance: High """ # generate Subscriptions report with session: session.reporttemplate.schedule( 'Subscription - General Report', values={ 'output_format': 'JSON', 'generate_at': '1970-01-01 17:10:00', 'email': True, 'email_to': 'root@localhost', }, ) randstring = gen_string('alpha') file_path = PurePath('/tmp/').joinpath(f'{randstring}.json') gzip_path = PurePath(f'{file_path}.gz') local_file = robottelo_tmp_dir.joinpath(f'{randstring}.json') local_gzip_file = Path(f'{local_file}.gz') expect_script = (f'#!/usr/bin/env expect\n' f'spawn mail\n' f'expect "& "\n' f'send "w $ /dev/null\\r"\n' f'expect "Enter filename"\n' f'send "\\r"\n' f'expect "Enter filename"\n' f'send "\\r"\n' f'expect "Enter filename"\n' f'send "\\025{gzip_path}\\r"\n' f'expect "&"\n' f'send "q\\r"\n') assert target_sat.execute(f"expect -c '{expect_script}'").status == 0 target_sat.get(remote_path=str(gzip_path), local_path=str(local_gzip_file)) assert os.system(f'gunzip {local_gzip_file}') == 0 data = json.loads(local_file.read_text()) subscription_search = target_sat.api.Subscription( organization=module_manifest_org).search() assert len(data) >= len(subscription_search) > 0 keys_expected = [ 'Account number', 'Available', 'Contract number', 'End date', 'ID', 'Name', 'Organization', 'Quantity', 'SKU', 'Start date', ] for subscription in data: assert sorted(list(subscription.keys())) == keys_expected