From 54d2ed06ca90438e58eea380e946c409fdd83174 Mon Sep 17 00:00:00 2001 From: Griffin-Sullivan Date: Tue, 11 Jun 2024 12:28:23 -0400 Subject: [PATCH] Remove use of install_katello_ca with register_contenthost --- pytest_fixtures/component/rh_cloud.py | 4 +- robottelo/hosts.py | 123 +++++------------- tests/foreman/cli/test_contentview.py | 18 +-- tests/foreman/cli/test_http_proxy.py | 2 +- .../destructive/test_capsule_loadbalancer.py | 8 +- tests/foreman/endtoend/test_api_endtoend.py | 6 +- tests/foreman/endtoend/test_cli_endtoend.py | 4 +- tests/foreman/installer/test_installer.py | 14 +- tests/upgrades/test_errata.py | 6 +- tests/upgrades/test_hostcontent.py | 8 +- tests/upgrades/test_repository.py | 6 +- tests/upgrades/test_subscription.py | 6 +- 12 files changed, 80 insertions(+), 125 deletions(-) diff --git a/pytest_fixtures/component/rh_cloud.py b/pytest_fixtures/component/rh_cloud.py index fd035f653c3..9db98fced25 100644 --- a/pytest_fixtures/component/rh_cloud.py +++ b/pytest_fixtures/component/rh_cloud.py @@ -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 @@ -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 diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 838ecbcb02b..a7b7cf45da1 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -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 @@ -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, @@ -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 @@ -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. @@ -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.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: @@ -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.name, 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. @@ -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') @@ -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.name, self) assert register.status == 0, ( f'Failed to register the host: {rhel_contenthost.hostname}:' f'rc: {register.status}: {register.stderr}' diff --git a/tests/foreman/cli/test_contentview.py b/tests/foreman/cli/test_contentview.py index 7f2a8d1c75c..466071c680a 100644 --- a/tests/foreman/cli/test_contentview.py +++ b/tests/foreman/cli/test_contentview.py @@ -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.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']}) @@ -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.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']}) diff --git a/tests/foreman/cli/test_http_proxy.py b/tests/foreman/cli/test_http_proxy.py index 7f37fd88c9d..df3f7b6d838 100644 --- a/tests/foreman/cli/test_http_proxy.py +++ b/tests/foreman/cli/test_http_proxy.py @@ -128,7 +128,7 @@ def test_insights_client_registration_with_http_proxy( 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}", ) assert rhel_contenthost.execute('insights-client --register').status == 0 diff --git a/tests/foreman/destructive/test_capsule_loadbalancer.py b/tests/foreman/destructive/test_capsule_loadbalancer.py index f9b3bbbf8d7..1f9015d529a 100644 --- a/tests/foreman/destructive/test_capsule_loadbalancer.py +++ b/tests/foreman/destructive/test_capsule_loadbalancer.py @@ -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] @@ -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.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') @@ -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 = ( diff --git a/tests/foreman/endtoend/test_api_endtoend.py b/tests/foreman/endtoend/test_api_endtoend.py index a692354062b..7280e26598b 100644 --- a/tests/foreman/endtoend/test_api_endtoend.py +++ b/tests/foreman/endtoend/test_api_endtoend.py @@ -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.name, target_sat) assert rhel_contenthost.subscribed # Install rpm on client package_name = 'katello-agent' diff --git a/tests/foreman/endtoend/test_cli_endtoend.py b/tests/foreman/endtoend/test_cli_endtoend.py index 789b0bf4d18..7bd3e5ed343 100644 --- a/tests/foreman/endtoend/test_cli_endtoend.py +++ b/tests/foreman/endtoend/test_cli_endtoend.py @@ -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.name, target_sat) assert rhel_contenthost.subscribed # Install rpm on client package_name = 'katello-agent' diff --git a/tests/foreman/installer/test_installer.py b/tests/foreman/installer/test_installer.py index 8332753b162..3b51486220d 100644 --- a/tests/foreman/installer/test_installer.py +++ b/tests/foreman/installer/test_installer.py @@ -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 @@ -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.name, 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] diff --git a/tests/upgrades/test_errata.py b/tests/upgrades/test_errata.py index 1425d341158..9c070dcc5fd 100644 --- a/tests/upgrades/test_errata.py +++ b/tests/upgrades/test_errata.py @@ -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.name, target_sat) rhel_contenthost.add_rex_key(satellite=target_sat) rhel_contenthost.install_katello_host_tools() rhel_contenthost.execute('subscription-manager refresh') diff --git a/tests/upgrades/test_hostcontent.py b/tests/upgrades/test_hostcontent.py index b8faff77feb..5fb180661fc 100644 --- a/tests/upgrades/test_hostcontent.py +++ b/tests/upgrades/test_hostcontent.py @@ -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 diff --git a/tests/upgrades/test_repository.py b/tests/upgrades/test_repository.py index ae8f672ab3f..2ec66215e9c 100644 --- a/tests/upgrades/test_repository.py +++ b/tests/upgrades/test_repository.py @@ -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.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 diff --git a/tests/upgrades/test_subscription.py b/tests/upgrades/test_subscription.py index cbf34dd05a6..08f6f732f28 100644 --- a/tests/upgrades/test_subscription.py +++ b/tests/upgrades/test_subscription.py @@ -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.name, target_sat) assert rhel_contenthost.subscribed save_test_data( {