Skip to content

Commit

Permalink
Remove use of install_katello_ca with register_contenthost
Browse files Browse the repository at this point in the history
  • Loading branch information
Griffin-Sullivan committed Jun 11, 2024
1 parent 9072e6f commit 7e167ed
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 122 deletions.
123 changes: 35 additions & 88 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from broker.hosts import Host
from dynaconf.vendor.box.exceptions import BoxKeyError
from fauxfactory import gen_alpha, gen_string
from manifester import Manifester
from nailgun import entities
from packaging.version import Version
import requests
Expand All @@ -41,12 +40,9 @@
CUSTOM_PUPPET_MODULE_REPOS,
CUSTOM_PUPPET_MODULE_REPOS_PATH,
CUSTOM_PUPPET_MODULE_REPOS_VERSION,
DEFAULT_ARCHITECTURE,
DEFAULT_LOC,
HAMMER_CONFIG,
KEY_CLOAK_CLI,
PRDS,
REPOS,
REPOSET,
RHSSO_NEW_GROUP,
RHSSO_NEW_USER,
RHSSO_RESET_PASSWORD,
Expand Down Expand Up @@ -108,53 +104,6 @@ def get_sat_rhel_version():
return Version(rhel_version)


def setup_capsule(satellite, capsule, org, registration_args=None, installation_args=None):
"""Given satellite and capsule instances, run the commands needed to set up the capsule
Note: This does not perform content setup actions on the Satellite
:param satellite: An instance of this module's Satellite class
:param capsule: An instance of this module's Capsule class
:param org: An instance of the org to use on the Satellite
:param registration_args: A dictionary mapping argument: value pairs for registration
:param installation_args: A dictionary mapping argument: value pairs for installation
:return: An ssh2-python result object for the installation command.
"""
# Unregister capsule incase it's registered to CDN
capsule.unregister()

# Add a manifest to the Satellite
with Manifester(manifest_category=settings.manifest.entitlement) as manifest:
satellite.upload_manifest(org.id, manifest.content)

# Enable RHEL 8 BaseOS and AppStream repos and sync
for rh_repo_key in ['rhel8_bos', 'rhel8_aps']:
satellite.api_factory.enable_rhrepo_and_fetchid(
basearch=DEFAULT_ARCHITECTURE,
org_id=org.id,
product=PRDS['rhel8'],
repo=REPOS[rh_repo_key]['name'],
reposet=REPOSET[rh_repo_key],
releasever=REPOS[rh_repo_key]['releasever'],
)
product = satellite.api.Product(name=PRDS['rhel8'], organization=org.id).search()[0]
product.sync(timeout=1800, synchronous=True)

if not registration_args:
registration_args = {}
file, _, cmd_args = satellite.capsule_certs_generate(capsule)
if installation_args:
cmd_args.update(installation_args)
satellite.execute(
f'sshpass -p "{capsule.password}" scp -o "StrictHostKeyChecking no" '
f'{file} root@{capsule.hostname}:{file}'
)
capsule.install_katello_ca(satellite)
capsule.register_contenthost(org=org.label, **registration_args)
return capsule.install(cmd_args)


class ContentHostError(Exception):
pass

Expand Down Expand Up @@ -673,27 +622,6 @@ def remove_katello_ca(self):
self.execute('subscription-manager clean')
self._satellite = None

def install_capsule_katello_ca(self, capsule=None):
"""Downloads and installs katello-ca rpm on the broker virtual machine.
:param: str capsule: Capsule hostname
:raises robottelo.hosts.ContentHostError: If katello-ca wasn't
installed.
"""
warnings.warn(
message=(
'The install_capsule_katello_ca method is deprecated, '
'use the register method instead.'
),
category=DeprecationWarning,
stacklevel=2,
)
url = urlunsplit(('http', capsule, 'pub/', '', ''))
ca_url = urljoin(url, 'katello-ca-consumer-latest.noarch.rpm')
result = self.execute(f'rpm -Uvh {ca_url}')
if result.status != 0:
raise ContentHostError('Failed to install the katello-ca rpm')

def install_cockpit(self):
"""Installs cockpit on the broker virtual machine.
Expand Down Expand Up @@ -1085,8 +1013,20 @@ def configure_rex(self, satellite, org, subnet_id=None, by_ip=True, register=Tru
:param bool register: Whether to register to the Satellite. Keyexchange done regardless
"""
if register:
self.install_katello_ca(satellite)
self.register_contenthost(org.label, lce='Library')
ak = satellite.api.ActivationKey(
content_view=org.default_content_view.id,
environment=org.library.id,
organization=org,
).create()
loc = satellite.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[0]
self.register(
org,
loc,
ak,
satellite,
setup_remote_execution=True,
setup_remote_execution_pull=True,
)
assert self.subscribed
self.add_rex_key(satellite=satellite)
if register and subnet_id is not None:
Expand Down Expand Up @@ -1122,10 +1062,14 @@ def configure_rhai_client(
:return: None
"""
if register:
# Install Satellite CA rpm
self.install_katello_ca(satellite)

self.register_contenthost(org, activation_key)
if not activation_key:
activation_key = satellite.api.ActivationKey(
content_view=org.default_content_view.id,
environment=org.library.id,
organization=org,
).create()
loc = satellite.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[0]
self.register(org, loc, activation_key, satellite)

# Red Hat Insights requires RHEL 6/7/8 repo and it is not
# possible to sync the repo during the tests, Adding repo file.
Expand Down Expand Up @@ -1220,8 +1164,11 @@ def contenthost_setup(
repo_labels = repo_labels or []
if location_title:
self.set_facts({'locations.facts': {'foreman_location': str(location_title)}})
self.install_katello_ca(satellite)
result = self.register_contenthost(org_label, activation_key=activation_key, lce=lce)
loc = satellite.api.Location().search(query={'search': f'name="{location_title}"'})[0]
else:
loc = satellite.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[0]
org = satellite.api.Organization().search(query={'search': f'name="{org_label}"'})[0]
result = self.register(org, loc, activation_key, satellite)
if not self.subscribed:
logger.info(result.stdout)
raise CLIFactoryError('Virtual machine failed subscription')
Expand Down Expand Up @@ -2147,13 +2094,13 @@ def register_host_custom_repo(self, module_org, rhel_contenthost, repo_urls):
assert task_status['result'] == 'success'

# register contenthost
rhel_contenthost.install_katello_ca(self)
register = rhel_contenthost.register_contenthost(
org=module_org.label,
lce='Library',
name=f'{gen_string("alpha")}-{rhel_contenthost.hostname}',
force=True,
)
ak = self.api.ActivationKey(
content_view=module_org.default_content_view.id,
environment=module_org.library.id,
organization=module_org,
).create()
loc = self.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[0]
register = rhel_contenthost.register(module_org, loc, ak, self)
assert register.status == 0, (
f'Failed to register the host: {rhel_contenthost.hostname}:'
f'rc: {register.status}: {register.stderr}'
Expand Down
18 changes: 4 additions & 14 deletions tests/foreman/cli/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,14 +2057,9 @@ def test_positive_sub_host_with_restricted_user_perm_at_custom_loc(
)
# assert that this is the same content view
assert content_view['name'] == user_content_view['name']
ak = target_sat.api.ActivationKey(content_view=user_content_view, organization=org).create()
# create a client host and register it with the created user
rhel7_contenthost.install_katello_ca(target_sat)
rhel7_contenthost.register_contenthost(
org['label'],
lce=f'{env["name"]}/{content_view["name"]}',
username=user_name,
password=user_password,
)
rhel7_contenthost.register(org, loc, ak, target_sat)
assert rhel7_contenthost.subscribed
# check that the client host exist in the system
org_hosts = target_sat.cli.Host.list({'organization-id': org['id']})
Expand Down Expand Up @@ -2211,14 +2206,9 @@ def test_positive_sub_host_with_restricted_user_perm_at_default_loc(
)
# assert that this is the same content view
assert content_view['name'] == user_content_view['name']
ak = target_sat.api.ActivationKey(content_view=user_content_view, organization=org).create()
# create a client host and register it with the created user
rhel7_contenthost.install_katello_ca(target_sat)
rhel7_contenthost.register_contenthost(
org['label'],
lce='/'.join([env['name'], content_view['name']]),
username=user_name,
password=user_password,
)
rhel7_contenthost.register(org, loc, ak, target_sat)
assert rhel7_contenthost.subscribed
# check that the client host exist in the system
org_hosts = target_sat.cli.Host.list({'organization-id': org['id']})
Expand Down
8 changes: 3 additions & 5 deletions tests/foreman/destructive/test_capsule_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from robottelo import constants
from robottelo.config import settings
from robottelo.constants import CLIENT_PORT, DataFile
from robottelo.constants import CLIENT_PORT, DEFAULT_LOC, DataFile
from robottelo.utils.installer import InstallerCommand

pytestmark = [pytest.mark.no_containers, pytest.mark.destructive]
Expand Down Expand Up @@ -121,8 +121,8 @@ def setup_haproxy(
haproxy_ak = content_for_client['client_ak']
haproxy.execute('firewall-cmd --add-service RH-Satellite-6-capsule')
haproxy.execute('firewall-cmd --runtime-to-permanent')
haproxy.install_katello_ca(module_target_sat)
haproxy.register_contenthost(module_org.label, haproxy_ak.name)
loc = module_target_sat.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[0]
haproxy.register(module_org, loc, haproxy_ak, module_target_sat)
result = haproxy.execute('yum install haproxy policycoreutils-python-utils -y')
assert result.status == 0
haproxy.execute('rm -f /etc/haproxy/haproxy.cfg')
Expand Down Expand Up @@ -230,8 +230,6 @@ def test_loadbalancer_install_package(
)
assert rhel_contenthost.hostname in [host['name'] for host in hosts]

result = rhel_contenthost.execute('rpm -qa | grep katello-ca-consumer')

# Find which capsule the host is registered to since it's RoundRobin
# The following also asserts the above result
registered_to_capsule = (
Expand Down
6 changes: 4 additions & 2 deletions tests/foreman/endtoend/test_api_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,11 @@ def test_positive_end_to_end(self, function_sca_manifest, target_sat, rhel_conte
# step 2.18: Provision a client
# TODO this isn't provisioning through satellite as intended
# Note it wasn't well before the change that added this todo
rhel_contenthost.install_katello_ca(target_sat)
# Register client with foreman server using act keys
rhel_contenthost.register_contenthost(org.label, activation_key_name)
loc = target_sat.api.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[
0
]
rhel_contenthost.register(org, loc, activation_key, target_sat)
assert rhel_contenthost.subscribed
# Install rpm on client
package_name = 'katello-agent'
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/endtoend/test_cli_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def test_positive_cli_end_to_end(function_sca_manifest, target_sat, rhel_content
# step 2.18: Provision a client
# TODO this isn't provisioning through satellite as intended
# Note it wasn't well before the change that added this todo
rhel_contenthost.install_katello_ca(target_sat)
# Register client with foreman server using act keys
rhel_contenthost.register_contenthost(org['label'], activation_key['name'])
loc = target_sat.api.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[0]
rhel_contenthost.register(org, loc, activation_key, target_sat)
assert rhel_contenthost.subscribed
# Install rpm on client
package_name = 'katello-agent'
Expand Down
14 changes: 11 additions & 3 deletions tests/foreman/installer/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

from robottelo import ssh
from robottelo.config import settings
from robottelo.constants import FOREMAN_SETTINGS_YML, PRDS, REPOS, REPOSET
from robottelo.hosts import setup_capsule
from robottelo.constants import DEFAULT_LOC, FOREMAN_SETTINGS_YML, PRDS, REPOS, REPOSET
from robottelo.utils.installer import InstallerCommand
from robottelo.utils.issue_handlers import is_open

Expand Down Expand Up @@ -228,7 +227,16 @@ def test_capsule_installation(sat_non_default_install, cap_ready_rhel, setting_u
cap_ready_rhel.install_satellite_or_capsule_package()
assert cap_ready_rhel.execute('rpm -q foreman-proxy-fapolicyd').status == 0
# Setup Capsule
setup_capsule(sat_non_default_install, cap_ready_rhel, org)
loc = sat_non_default_install.api.Location().search(query={'search': f'name="{DEFAULT_LOC}"'})[
0
]
ak = sat_non_default_install.api.ActivationKey(
content_view=org.default_content_view.id,
environment=org.library.id,
organization=org,
).create()
cap_ready_rhel.register(org, loc, ak, sat_non_default_install)
cap_ready_rhel.capsule_setup(sat_host=sat_non_default_install)
assert sat_non_default_install.api.Capsule().search(
query={'search': f'name={cap_ready_rhel.hostname}'}
)[0]
Expand Down
6 changes: 4 additions & 2 deletions tests/upgrades/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ def test_pre_scenario_generate_errata_for_client(
query={'search': f'name={product.name}'}
)[0]
ak.add_subscriptions(data={'subscription_id': subscription.id})
rhel_contenthost.install_katello_ca(target_sat)
rhel_contenthost.register_contenthost(org=function_org.name, activation_key=ak.name)
loc = target_sat.api.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[
0
]
rhel_contenthost.register(function_org, loc, ak, target_sat)
rhel_contenthost.add_rex_key(satellite=target_sat)
rhel_contenthost.install_katello_host_tools()
rhel_contenthost.execute('subscription-manager refresh')
Expand Down
8 changes: 6 additions & 2 deletions tests/upgrades/test_hostcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def test_pre_db_seed_host_mismatch(
:customerscenario: true
"""
rhel7_contenthost_module.install_katello_ca(target_sat)
rhel7_contenthost_module.register_contenthost(org=function_org.label, lce='Library')
ak = self.api.ActivationKey(
content_view=function_org.default_content_view.id,
environment=function_org.library.id,
organization=function_org,
).create()
rhel7_contenthost_module.register(function_org, function_location, ak, target_sat)

assert rhel7_contenthost_module.nailgun_host.organization.id == function_org.id

Expand Down
6 changes: 4 additions & 2 deletions tests/upgrades/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ def test_pre_scenario_custom_repo_check(self, target_sat, sat_upgrade_chost, sav
query={'search': f'name={product.name}'}
)[0]
ak.add_subscriptions(data={'subscription_id': subscription.id})
sat_upgrade_chost.install_katello_ca(target_sat)
sat_upgrade_chost.register_contenthost(org.label, ak.name)
loc = target_sat.api.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[
0
]
sat_upgrade_chost.register(org, loc, ak, target_sat)
sat_upgrade_chost.execute('subscription-manager repos --enable=*;yum clean all')
result = sat_upgrade_chost.execute(f'yum install -y {FAKE_0_CUSTOM_PACKAGE_NAME}')
assert result.status == 0
Expand Down
6 changes: 4 additions & 2 deletions tests/upgrades/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ def test_pre_subscription_scenario_auto_attach(
auto_attach=False,
).create()
activation_key.add_subscriptions(data={'subscription_id': subscription[0].id})
rhel_contenthost.install_katello_ca(target_sat)
rhel_contenthost.register_contenthost(org=org.name, activation_key=activation_key.name)
loc = target_sat.api.Location().search(query={'search': f'name="{constants.DEFAULT_LOC}"'})[
0
]
rhel_contenthost.register(org, loc, activation_key, target_sat)
assert rhel_contenthost.subscribed
save_test_data(
{
Expand Down

0 comments on commit 7e167ed

Please sign in to comment.