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

Remove use of install_katello_ca with register_contenthost #15395

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions pytest_fixtures/component/rh_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def rhcloud_registered_hosts(
vm.configure_rhai_client(
satellite=module_target_sat,
activation_key=rhcloud_activation_key.name,
org=rhcloud_manifest_org.label,
org=rhcloud_manifest_org,
rhel_distro=f"rhel{vm.os_version.major}",
)
assert vm.subscribed
Expand All @@ -54,7 +54,7 @@ def rhel_insights_vm(
rhel_contenthost.configure_rhai_client(
satellite=module_target_sat,
activation_key=rhcloud_activation_key.name,
org=rhcloud_manifest_org.label,
org=rhcloud_manifest_org,
rhel_distro=f"rhel{rhel_contenthost.os_version.major}",
)
# Generate report
Expand Down
129 changes: 33 additions & 96 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,8 @@
CUSTOM_PUPPET_MODULE_REPOS,
CUSTOM_PUPPET_MODULE_REPOS_PATH,
CUSTOM_PUPPET_MODULE_REPOS_VERSION,
DEFAULT_ARCHITECTURE,
HAMMER_CONFIG,
KEY_CLOAK_CLI,
PRDS,
REPOS,
REPOSET,
RHSSO_NEW_GROUP,
RHSSO_NEW_USER,
RHSSO_RESET_PASSWORD,
Expand Down Expand Up @@ -109,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 @@ -674,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 @@ -1095,8 +1022,19 @@ 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()
self.register(
org,
None,
ak.name,
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 @@ -1132,10 +1070,15 @@ 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()
self.register(
org, None, activation_key.name, satellite, setup_insights=register_insights
)

# 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 All @@ -1155,17 +1098,10 @@ def configure_rhai_client(
else:
self.create_custom_repos(**{rhel_distro: rhel_repo})

# Install insights-client rpm
# Ensure insights-client rpm is installed
if self.execute('yum install -y insights-client').status != 0:
raise ContentHostError('Unable to install insights-client rpm')

if register_insights:
# 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.')
vsedmik marked this conversation as resolved.
Show resolved Hide resolved

def unregister_insights(self):
"""Unregister insights client.

Expand Down Expand Up @@ -1228,10 +1164,12 @@ def contenthost_setup(
"""
rh_repo_ids = rh_repo_ids or []
repo_labels = repo_labels or []
loc = location_title
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]
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 @@ -2222,13 +2160,12 @@ 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()
register = rhel_contenthost.register(module_org, None, ak.name, self)
assert register.status == 0, (
f'Failed to register the host: {rhel_contenthost.hostname}:'
f'rc: {register.status}: {register.stderr}'
Expand Down
27 changes: 13 additions & 14 deletions tests/foreman/cli/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,14 +2057,18 @@ 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']
# 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,
# Create activation key with content view
ak_name = gen_alphanumeric
jameerpathan111 marked this conversation as resolved.
Show resolved Hide resolved
target_sat.cli.ActivationKey.create(
{
'organization-id': org.id,
'lifecycle-environment': env.name,
'content-view': content_view['name'],
'name': ak_name,
}
)
# create a client host and register it with the created user
rhel7_contenthost.register(org, loc, ak_name, 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 +2215,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.name, 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
11 changes: 4 additions & 7 deletions tests/foreman/cli/test_http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,11 @@ def test_insights_client_registration_with_http_proxy(

:customerscenario: true
"""
rhel_contenthost.configure_rex(
satellite=module_target_sat, org=rhcloud_manifest_org, register=False
)
rhel_contenthost.configure_rhai_client(
satellite=module_target_sat,
activation_key=rhcloud_activation_key.name,
org=rhcloud_manifest_org.label,
rhel_distro=f"rhel{rhel_contenthost.os_version.major}",
module_target_sat,
rhcloud_activation_key,
rhcloud_manifest_org,
f"rhel{rhel_contenthost.os_version.major}",
)
assert rhel_contenthost.execute('insights-client --register').status == 0
assert rhel_contenthost.execute('insights-client --test-connection').status == 0
Expand Down
5 changes: 1 addition & 4 deletions tests/foreman/destructive/test_capsule_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ 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)
haproxy.register(module_org, None, haproxy_ak.name, 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 +229,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
3 changes: 1 addition & 2 deletions tests/foreman/endtoend/test_api_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,8 @@ 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)
rhel_contenthost.register(org, None, activation_key.name, target_sat)
assert rhel_contenthost.subscribed
# Install rpm on client
package_name = 'katello-agent'
Expand Down
3 changes: 1 addition & 2 deletions tests/foreman/endtoend/test_cli_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ 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'])
rhel_contenthost.register(org, None, activation_key['name'], target_sat)
assert rhel_contenthost.subscribed
# Install rpm on client
package_name = 'katello-agent'
Expand Down
4 changes: 1 addition & 3 deletions tests/foreman/installer/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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.utils.installer import InstallerCommand
from robottelo.utils.issue_handlers import is_open

Expand Down Expand Up @@ -213,7 +212,6 @@ def test_capsule_installation(sat_non_default_install, cap_ready_rhel, setting_u
:customerscenario: true
"""
# Get Capsule repofile, and enable and download satellite-capsule
org = sat_non_default_install.api.Organization().create()
cap_ready_rhel.register_to_cdn()
cap_ready_rhel.download_repofile(
product='capsule',
Expand All @@ -230,7 +228,7 @@ 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)
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
3 changes: 1 addition & 2 deletions tests/upgrades/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ 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)
rhel_contenthost.register(function_org, None, ak.name, 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.name, target_sat)

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

Expand Down
3 changes: 1 addition & 2 deletions tests/upgrades/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ 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)
sat_upgrade_chost.register(org, None, ak.name, 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
3 changes: 1 addition & 2 deletions tests/upgrades/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ 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)
rhel_contenthost.register(org, None, activation_key.name, target_sat)
assert rhel_contenthost.subscribed
save_test_data(
{
Expand Down