Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for Satellite with local Insights Advisor #17342

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 63 additions & 27 deletions pytest_fixtures/component/rh_cloud.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
from broker import Broker
import pytest

from robottelo.config import settings
from robottelo.constants import CAPSULE_REGISTRATION_OPTS


def _hosted_insights(satellite):
return not satellite.api.RHCloud().advisor_engine_config()['use_local_advisor_engine']


@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) or settings.server.use_existing_satellite

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 +50,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 +66,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 _hosted_insights(module_target_sat_insights):
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
Loading