Skip to content

Commit

Permalink
refactor rh_cloud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jameerpathan111 committed Sep 15, 2023
1 parent aeebfdf commit 20fd135
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 242 deletions.
2 changes: 2 additions & 0 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,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.
Expand Down
197 changes: 40 additions & 157 deletions tests/foreman/api/test_rhcloud_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
"""
Expand All @@ -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.
Expand Down Expand Up @@ -276,128 +237,42 @@ 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
: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.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
Expand All @@ -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
60 changes: 0 additions & 60 deletions tests/foreman/cli/test_rhcloud_insights.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/foreman/cli/test_rhcloud_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 20fd135

Please sign in to comment.