Skip to content

Commit

Permalink
Local Insights advisor testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapaioa committed Jan 22, 2025
1 parent 76662ae commit 192f93b
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 101 deletions.
85 changes: 58 additions & 27 deletions pytest_fixtures/component/rh_cloud.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
from broker import Broker
import pytest

from robottelo.constants import CAPSULE_REGISTRATION_OPTS


@pytest.fixture(scope='module')
def rhcloud_manifest_org(module_target_sat, module_sca_manifest):
def module_target_sat_insights(request, module_target_sat, satellite_factory):
hosted_insights = getattr(request, 'param', True)

satellite = module_target_sat if hosted_insights else satellite_factory()
if not hosted_insights:
satellite.execute('satellite-installer --enable-local-advisor')

yield satellite

if not hosted_insights:
satellite.teardown()
Broker(hosts=[satellite]).checkin()


@pytest.fixture(scope='module')
def rhcloud_manifest_org(module_target_sat_insights, module_sca_manifest):
"""A module level fixture to get organization with manifest."""
org = module_target_sat.api.Organization().create()
module_target_sat.upload_manifest(org.id, module_sca_manifest.content)
org = module_target_sat_insights.api.Organization().create()
module_target_sat_insights.upload_manifest(org.id, module_sca_manifest.content)
return org


@pytest.fixture(scope='module')
def rhcloud_activation_key(module_target_sat, rhcloud_manifest_org):
def rhcloud_activation_key(module_target_sat_insights, rhcloud_manifest_org):
"""A module-level fixture to create an Activation key in module_org"""
return module_target_sat.api.ActivationKey(
return module_target_sat_insights.api.ActivationKey(
content_view=rhcloud_manifest_org.default_content_view,
organization=rhcloud_manifest_org,
environment=module_target_sat.api.LifecycleEnvironment(id=rhcloud_manifest_org.library.id),
environment=module_target_sat_insights.api.LifecycleEnvironment(
id=rhcloud_manifest_org.library.id
),
service_level='Self-Support',
purpose_usage='test-usage',
purpose_role='test-role',
Expand All @@ -27,12 +45,12 @@ def rhcloud_activation_key(module_target_sat, rhcloud_manifest_org):

@pytest.fixture(scope='module')
def rhcloud_registered_hosts(
rhcloud_activation_key, rhcloud_manifest_org, mod_content_hosts, module_target_sat
rhcloud_activation_key, rhcloud_manifest_org, mod_content_hosts, module_target_sat_insights
):
"""Fixture that registers content hosts to Satellite and Insights."""
for vm in mod_content_hosts:
vm.configure_insights_client(
satellite=module_target_sat,
satellite=module_target_sat_insights,
activation_key=rhcloud_activation_key,
org=rhcloud_manifest_org,
rhel_distro=f"rhel{vm.os_version.major}",
Expand All @@ -43,44 +61,57 @@ def rhcloud_registered_hosts(

@pytest.fixture
def rhel_insights_vm(
module_target_sat, rhcloud_activation_key, rhcloud_manifest_org, rhel_contenthost
request,
module_target_sat_insights,
rhcloud_activation_key,
rhcloud_manifest_org,
rhel_contenthost,
):
"""A function-level fixture to create rhel content host registered with insights."""
rhel_contenthost.configure_rex(
satellite=module_target_sat, org=rhcloud_manifest_org, register=False
satellite=module_target_sat_insights, org=rhcloud_manifest_org, register=False
)
rhel_contenthost.configure_insights_client(
satellite=module_target_sat,
satellite=module_target_sat_insights,
activation_key=rhcloud_activation_key,
org=rhcloud_manifest_org,
rhel_distro=f"rhel{rhel_contenthost.os_version.major}",
)
# Generate report
module_target_sat.generate_inventory_report(rhcloud_manifest_org)
# Sync inventory status
module_target_sat.sync_inventory_status(rhcloud_manifest_org)
if not module_target_sat.api.RHCloud().advisor_engine_config()['use_local_advisor_engine']:
module_target_sat_insights.generate_inventory_report(rhcloud_manifest_org)
module_target_sat_insights.sync_inventory_status(rhcloud_manifest_org)
return rhel_contenthost


@pytest.fixture
def inventory_settings(module_target_sat):
hostnames_setting = module_target_sat.update_setting('obfuscate_inventory_hostnames', False)
ip_setting = module_target_sat.update_setting('obfuscate_inventory_ips', False)
packages_setting = module_target_sat.update_setting('exclude_installed_packages', False)
parameter_tags_setting = module_target_sat.update_setting('include_parameter_tags', False)
def inventory_settings(module_target_sat_insights):
hostnames_setting = module_target_sat_insights.update_setting(
'obfuscate_inventory_hostnames', False
)
ip_setting = module_target_sat_insights.update_setting('obfuscate_inventory_ips', False)
packages_setting = module_target_sat_insights.update_setting(
'exclude_installed_packages', False
)
parameter_tags_setting = module_target_sat_insights.update_setting(
'include_parameter_tags', False
)
yield
module_target_sat.update_setting('obfuscate_inventory_hostnames', hostnames_setting)
module_target_sat.update_setting('obfuscate_inventory_ips', ip_setting)
module_target_sat.update_setting('exclude_installed_packages', packages_setting)
module_target_sat.update_setting('include_parameter_tags', parameter_tags_setting)
module_target_sat_insights.update_setting('obfuscate_inventory_hostnames', hostnames_setting)
module_target_sat_insights.update_setting('obfuscate_inventory_ips', ip_setting)
module_target_sat_insights.update_setting('exclude_installed_packages', packages_setting)
module_target_sat_insights.update_setting('include_parameter_tags', parameter_tags_setting)


@pytest.fixture(scope='module')
def rhcloud_capsule(module_capsule_host, module_target_sat, rhcloud_manifest_org, default_location):
def rhcloud_capsule(
module_capsule_host, module_target_sat_insights, rhcloud_manifest_org, default_location
):
"""Configure the capsule instance with the satellite from settings.server.hostname"""
org = rhcloud_manifest_org
module_capsule_host.capsule_setup(sat_host=module_target_sat, **CAPSULE_REGISTRATION_OPTS)
module_target_sat.cli.Capsule.update(
module_capsule_host.capsule_setup(
sat_host=module_target_sat_insights, **CAPSULE_REGISTRATION_OPTS
)
module_target_sat_insights.cli.Capsule.update(
{
'name': module_capsule_host.hostname,
'organization-ids': org.id,
Expand Down
Loading

0 comments on commit 192f93b

Please sign in to comment.