From 37ea130aa9bd06c7c9724a58030b7276be9fe490 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Mon, 12 Feb 2024 10:22:15 +0530 Subject: [PATCH] Replace old method of registration with global registration in robottelo --- pytest_fixtures/component/activationkey.py | 9 +++ pytest_fixtures/component/contentview.py | 15 ++++ tests/foreman/api/test_hostcollection.py | 9 ++- tests/foreman/api/test_reporttemplates.py | 27 ++++++-- tests/foreman/api/test_subscription.py | 47 ++++++++++--- tests/foreman/cli/test_activationkey.py | 34 +++++----- tests/foreman/cli/test_host.py | 79 +++++++++------------- tests/foreman/cli/test_hostcollection.py | 3 +- tests/foreman/cli/test_reporttemplates.py | 37 +++++++--- tests/foreman/cli/test_subscription.py | 7 +- tests/foreman/ui/test_activationkey.py | 60 ++++++++-------- tests/foreman/ui/test_reporttemplates.py | 8 +-- tests/foreman/ui/test_subscription.py | 8 +-- 13 files changed, 211 insertions(+), 132 deletions(-) diff --git a/pytest_fixtures/component/activationkey.py b/pytest_fixtures/component/activationkey.py index 8101a446ffa..0e0166f2bf2 100644 --- a/pytest_fixtures/component/activationkey.py +++ b/pytest_fixtures/component/activationkey.py @@ -42,6 +42,15 @@ def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_ ).create() +@pytest.fixture +def function_ak_with_cv(function_lce, function_org, function_promoted_cv, target_sat): + return target_sat.api.ActivationKey( + content_view=function_promoted_cv, + environment=function_lce, + organization=function_org, + ).create() + + @pytest.fixture(scope='module') def module_ak_with_cv_repo(module_lce, module_org, module_cv_repo, module_target_sat): return module_target_sat.api.ActivationKey( diff --git a/pytest_fixtures/component/contentview.py b/pytest_fixtures/component/contentview.py index 79d66014949..2c6b6877193 100644 --- a/pytest_fixtures/component/contentview.py +++ b/pytest_fixtures/component/contentview.py @@ -17,6 +17,13 @@ def module_published_cv(module_org, module_target_sat): return content_view.read() +@pytest.fixture +def function_published_cv(function_org, target_sat): + content_view = target_sat.api.ContentView(organization=function_org).create() + content_view.publish() + return content_view.read() + + @pytest.fixture(scope="module") def module_promoted_cv(module_lce, module_published_cv, module_target_sat): """Promote published content view""" @@ -25,6 +32,14 @@ def module_promoted_cv(module_lce, module_published_cv, module_target_sat): return module_published_cv +@pytest.fixture +def function_promoted_cv(function_lce, function_published_cv, target_sat): + """Promote published content view""" + content_view_version = function_published_cv.version[0] + content_view_version.promote(data={'environment_ids': function_lce.id}) + return function_published_cv + + @pytest.fixture(scope='module') def module_default_org_view(module_org, module_target_sat): return module_target_sat.api.ContentView(organization=module_org, name=DEFAULT_CV).search()[0] diff --git a/tests/foreman/api/test_hostcollection.py b/tests/foreman/api/test_hostcollection.py index 985f989718e..5bd124a1d40 100644 --- a/tests/foreman/api/test_hostcollection.py +++ b/tests/foreman/api/test_hostcollection.py @@ -432,8 +432,13 @@ def test_positive_add_remove_subscription(module_org, module_ak_cv_lce, target_s # Create and register VMs as members of Host Collection with Broker(nick='rhel7', host_class=ContentHost, _count=2) as hosts: for client in hosts: - client.install_katello_ca(target_sat) - client.register_contenthost(module_org.label, module_ak_cv_lce.name) + command = target_sat.api.RegistrationCommand( + organization=module_org, + activation_keys=[module_ak_cv_lce.name], + insecure=True, + ).create() + result = client.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' # Read host_collection back from Satellite to get host_ids host_collection = module_ak_cv_lce.host_collection[0].read() host_ids = [host.id for host in host_collection.host] diff --git a/tests/foreman/api/test_reporttemplates.py b/tests/foreman/api/test_reporttemplates.py index a0c79506cf3..71fb34bf99f 100644 --- a/tests/foreman/api/test_reporttemplates.py +++ b/tests/foreman/api/test_reporttemplates.py @@ -598,8 +598,13 @@ def test_positive_generate_entitlements_report(setup_content, target_sat): """ with Broker(nick='rhel7', host_class=ContentHost) as vm: ak, org = setup_content - vm.install_katello_ca(target_sat) - vm.register_contenthost(org.label, ak.name) + command = target_sat.api.RegistrationCommand( + organization=org, + activation_keys=[ak.name], + insecure=True, + ).create() + result = vm.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert vm.subscribed rt = ( target_sat.api.ReportTemplate() @@ -637,8 +642,13 @@ def test_positive_schedule_entitlements_report(setup_content, target_sat): """ with Broker(nick='rhel7', host_class=ContentHost) as vm: ak, org = setup_content - vm.install_katello_ca(target_sat) - vm.register_contenthost(org.label, ak.name) + command = target_sat.api.RegistrationCommand( + organization=org, + activation_keys=[ak.name], + insecure=True, + ).create() + result = vm.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert vm.subscribed rt = ( target_sat.api.ReportTemplate() @@ -685,8 +695,13 @@ def test_positive_generate_job_report(setup_content, target_sat, rhel7_contentho :customerscenario: true """ ak, org = setup_content - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(org.label, ak.name) + command = target_sat.api.RegistrationCommand( + organization=org, + activation_keys=[ak.name], + insecure=True, + ).create() + result = rhel7_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' rhel7_contenthost.add_rex_key(target_sat) assert rhel7_contenthost.subscribed # Run a Job on the Host diff --git a/tests/foreman/api/test_subscription.py b/tests/foreman/api/test_subscription.py index ec122ec6bfb..b57254ce133 100644 --- a/tests/foreman/api/test_subscription.py +++ b/tests/foreman/api/test_subscription.py @@ -229,8 +229,13 @@ def test_positive_subscription_status_disabled( :CaseImportance: Medium """ - rhel_contenthost.install_katello_ca(target_sat) - rhel_contenthost.register_contenthost(module_sca_manifest_org.label, module_ak.name) + command = target_sat.api.RegistrationCommand( + organization=module_sca_manifest_org, + activation_keys=[module_ak.name], + insecure=True, + ).create() + result = rhel_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel_contenthost.subscribed host_content = target_sat.api.Host(id=rhel_contenthost.nailgun_host.id).read_raw().content assert 'Simple Content Access' in str(host_content) @@ -256,8 +261,13 @@ def test_sca_end_to_end( :CaseImportance: Critical """ - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(module_sca_manifest_org.label, module_ak.name) + command = target_sat.api.RegistrationCommand( + organization=module_sca_manifest_org, + activation_keys=[module_ak.name], + insecure=True, + ).create() + result = rhel7_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed # Check to see if Organization is in SCA Mode assert ( @@ -335,8 +345,13 @@ def test_positive_candlepin_events_processed_by_stomp( environment=target_sat.api.LifecycleEnvironment(id=function_org.library.id), auto_attach=True, ).create() - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(function_org.name, ak.name) + command = target_sat.api.RegistrationCommand( + organization=function_org, + activation_keys=[ak.name], + insecure=True, + ).create() + result = rhel7_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' host = target_sat.api.Host().search(query={'search': f'name={rhel7_contenthost.hostname}'}) host_id = host[0].id host_content = target_sat.api.Host(id=host_id).read_json() @@ -392,10 +407,13 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel7_conte ).create() # registering the content host with no content enabled/synced in the org # should create a client SCA cert with no content - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost( - org=module_sca_manifest_org.label, activation_key=ak.name - ) + command = target_sat.api.RegistrationCommand( + organization=module_sca_manifest_org, + activation_keys=[ak.name], + insecure=True, + ).create() + result = rhel7_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed rhel7_contenthost.unregister() # syncing content with the content host unregistered should invalidate @@ -412,7 +430,14 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel7_conte rh_repo.sync() # re-registering the host should test whether Candlepin gracefully handles # registration of a host with an expired SCA cert - rhel7_contenthost.register_contenthost(module_sca_manifest_org.label, ak.name) + command = target_sat.api.RegistrationCommand( + organization=module_sca_manifest_org, + activation_keys=[ak.name], + insecure=True, + force=True, + ).create() + result = rhel7_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed diff --git a/tests/foreman/cli/test_activationkey.py b/tests/foreman/cli/test_activationkey.py index b4a0616ed4f..d89130a9620 100644 --- a/tests/foreman/cli/test_activationkey.py +++ b/tests/foreman/cli/test_activationkey.py @@ -593,7 +593,7 @@ def test_negative_update_usage_limit(module_org, module_target_sat): @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 @pytest.mark.upgrade -def test_positive_usage_limit(module_org, target_sat): +def test_positive_usage_limit(module_org, module_location, target_sat): """Test that Usage limit actually limits usage :id: 00ded856-e939-4140-ac84-91b6a8643623 @@ -628,11 +628,9 @@ def test_positive_usage_limit(module_org, target_sat): ) with Broker(nick='rhel7', host_class=ContentHost, _count=2) as clients: vm1, vm2 = clients - vm1.install_katello_ca(target_sat) - vm1.register_contenthost(module_org.label, new_ak['name']) + vm1.register(module_org, module_location, new_ak['name'], target_sat) assert vm1.subscribed - vm2.install_katello_ca(target_sat) - result = vm2.register_contenthost(module_org.label, new_ak['name']) + result = vm2.register(module_org, module_location, new_ak['name'], target_sat) assert not vm2.subscribed assert result.status == 70 assert len(result.stderr) > 0 @@ -876,7 +874,7 @@ def test_positive_delete_subscription(function_entitlement_manifest_org, module_ @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 @pytest.mark.upgrade -def test_positive_update_aks_to_chost(module_org, rhel7_contenthost, target_sat): +def test_positive_update_aks_to_chost(module_org, module_location, rhel7_contenthost, target_sat): """Check if multiple Activation keys can be attached to a Content host @@ -904,9 +902,13 @@ def test_positive_update_aks_to_chost(module_org, rhel7_contenthost, target_sat) ) for _ in range(2) ] - rhel7_contenthost.install_katello_ca(target_sat) for i in range(2): - rhel7_contenthost.register_contenthost(module_org.label, new_aks[i]['name']) + rhel7_contenthost.register( + org=module_org, + loc=module_location, + activation_keys=new_aks[i]['name'], + target=target_sat, + ) assert rhel7_contenthost.subscribed @@ -1635,20 +1637,19 @@ def test_positive_subscription_quantity_attached(function_org, rhel7_contenthost target_sat.cli_factory.setup_org_for_a_custom_repo( { 'url': settings.repos.yum_0.url, - 'organization-id': org['id'], + 'organization-id': org.id, 'activationkey-id': result['activationkey-id'], 'content-view-id': result['content-view-id'], 'lifecycle-environment-id': result['lifecycle-environment-id'], } ) - subs = target_sat.cli.Subscription.list({'organization-id': org['id']}, per_page=False) + subs = target_sat.cli.Subscription.list({'organization-id': org.id}, per_page=False) subs_lookup = {s['id']: s for s in subs} - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(org['label'], activation_key=ak['name']) + rhel7_contenthost.register(org, None, ak['name'], target_sat) assert rhel7_contenthost.subscribed ak_subs = target_sat.cli.ActivationKey.subscriptions( - {'activation-key': ak['name'], 'organization-id': org['id']}, output_format='json' + {'activation-key': ak['name'], 'organization-id': org.id}, output_format='json' ) assert len(ak_subs) == 2 # one for #rh product, one for custom product for ak_sub in ak_subs: @@ -1661,7 +1662,9 @@ def test_positive_subscription_quantity_attached(function_org, rhel7_contenthost @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 -def test_positive_ak_with_custom_product_on_rhel6(module_org, rhel6_contenthost, target_sat): +def test_positive_ak_with_custom_product_on_rhel6( + module_org, module_location, rhel6_contenthost, target_sat +): """Registering a rhel6 host using an ak with custom repos should not fail :id: d02c2664-8034-4562-914a-3b68f0c35b32 @@ -1682,8 +1685,7 @@ def test_positive_ak_with_custom_product_on_rhel6(module_org, rhel6_contenthost, {'url': settings.repos.yum_1.url, 'organization-id': module_org.id} ) ak = target_sat.api.ActivationKey(id=entities_ids['activationkey-id']).read() - rhel6_contenthost.install_katello_ca(target_sat) - result = rhel6_contenthost.register_contenthost(module_org.label, activation_key=ak.name) + result = rhel6_contenthost.register(module_org.label, module_location, ak.name, target_sat) assert 'The system has been registered with ID' in result.stdout diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index fe01b0bc973..68fb9d16631 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -598,7 +598,8 @@ def test_positive_list_and_unregister( :parametrized: yes """ - rhel7_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) + result = rhel7_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) + assert result.status == 0 assert rhel7_contenthost.subscribed hosts = target_sat.cli.Host.list({'organization-id': module_org.id}) assert rhel7_contenthost.hostname in [host['name'] for host in hosts] @@ -611,7 +612,7 @@ def test_positive_list_and_unregister( @pytest.mark.cli_host_create @pytest.mark.tier3 def test_positive_list_by_last_checkin( - module_lce, module_org, module_promoted_cv, rhel7_contenthost, target_sat + module_org, rhel7_contenthost, target_sat, module_ak_with_cv ): """List all content hosts using last checkin criteria @@ -625,11 +626,8 @@ def test_positive_list_by_last_checkin( :parametrized: yes """ - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost( - module_org.label, - lce=f'{module_lce.label}/{module_promoted_cv.label}', - ) + result = rhel7_contenthost.register(module_org, None, [module_ak_with_cv.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed hosts = target_sat.cli.Host.list( {'search': 'last_checkin = "Today" or last_checkin = "Yesterday"'} @@ -641,7 +639,7 @@ def test_positive_list_by_last_checkin( @pytest.mark.cli_host_create @pytest.mark.tier3 def test_positive_list_infrastructure_hosts( - module_lce, module_org, module_promoted_cv, rhel7_contenthost, target_sat + module_org, rhel7_contenthost, target_sat, module_ak_with_cv ): """List infrasturcture hosts (Satellite and Capsule) @@ -651,11 +649,8 @@ def test_positive_list_infrastructure_hosts( :parametrized: yes """ - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost( - module_org.label, - lce=f'{module_lce.label}/{module_promoted_cv.label}', - ) + result = rhel7_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) + assert result.status == 0 assert rhel7_contenthost.subscribed target_sat.cli.Host.update({'name': target_sat.hostname, 'new-organization-id': module_org.id}) # list satellite hosts @@ -1909,9 +1904,8 @@ def test_positive_attach( } ) host = target_sat.cli.Host.info({'name': host_subscription_client.hostname}) - host_subscription_client.register_contenthost( - module_org.name, activation_key=module_ak_with_cv.name - ) + result = host_subscription_client.register(module_org, None, module_ak_with_cv.name, target_sat) + assert result.status == 0 assert host_subscription_client.subscribed # attach the subscription to host target_sat.cli.Host.subscription_attach( @@ -1933,8 +1927,7 @@ def test_positive_attach( @pytest.mark.tier3 def test_positive_attach_with_lce( module_org, - module_promoted_cv, - module_lce, + module_ak_with_cv, module_rhst_repo, default_subscription, host_subscription_client, @@ -1953,11 +1946,8 @@ def test_positive_attach_with_lce( :parametrized: yes """ - host_subscription_client.register_contenthost( - module_org.name, - lce=f'{module_lce.name}/{module_promoted_cv.name}', - auto_attach=False, - ) + res = host_subscription_client.register(module_org, None, module_ak_with_cv.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' assert host_subscription_client.subscribed host = target_sat.cli.Host.info({'name': host_subscription_client.hostname}) target_sat.cli.Host.subscription_attach( @@ -1999,6 +1989,7 @@ def test_negative_without_attach( } ) host = target_sat.cli.Host.info({'name': host_subscription_client.hostname}) + host_subscription_client.register_contenthost( module_org.name, lce=None, # required, to jump into right branch in register_contenthost method @@ -2016,6 +2007,7 @@ def test_negative_without_attach( def test_negative_without_attach_with_lce( target_sat, host_subscription_client, + function_ak_with_cv, function_org, function_lce, ): @@ -2031,10 +2023,11 @@ def test_negative_without_attach_with_lce( :parametrized: yes """ content_view = target_sat.api.ContentView(organization=function_org).create() - ak = target_sat.api.ActivationKey( - environment=function_lce, - organization=function_org, - ).create() + # ak = target_sat.api.ActivationKey( + # environment=function_lce, + # organization=function_org, + # content_view + # ).create() target_sat.cli_factory.setup_org_for_a_rh_repo( { 'product': PRDS['rhel'], @@ -2043,19 +2036,17 @@ def test_negative_without_attach_with_lce( 'organization-id': function_org.id, 'content-view-id': content_view.id, 'lifecycle-environment-id': function_lce.id, - 'activationkey-id': ak.id, + 'activationkey-id': function_ak_with_cv.id, 'subscription': DEFAULT_SUBSCRIPTION_NAME, }, force_use_cdn=True, ) # register client - host_subscription_client.register_contenthost( - function_org.name, - lce=f'{function_lce.name}/{content_view.name}', - auto_attach=False, + result = host_subscription_client.register( + function_org, None, function_ak_with_cv.name, target_sat ) - + assert result.status == 0 assert host_subscription_client.subscribed res = host_subscription_client.enable_repo(REPOS['rhsclient7']['id']) assert res.status == 0 @@ -2101,9 +2092,8 @@ def test_positive_remove( output_format='json', ) assert default_subscription.name not in [sub['name'] for sub in host_subscriptions] - host_subscription_client.register_contenthost( - module_org.name, activation_key=ak_with_subscription.name - ) + res = host_subscription_client.register(module_org, None, ak_with_subscription.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' target_sat.cli.Host.subscription_attach( { 'host-id': host['id'], @@ -2165,9 +2155,9 @@ def test_positive_auto_attach( } ) host = target_sat.cli.Host.info({'name': host_subscription_client.hostname}) - host_subscription_client.register_contenthost( - module_org.name, activation_key=ak_with_subscription.name - ) + + res = host_subscription_client.register(module_org, None, ak_with_subscription.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' target_sat.cli.Host.subscription_auto_attach({'host-id': host['id']}) host_subscription_client.enable_repo(module_rhst_repo) # ensure that katello-host-tools can be installed @@ -2191,10 +2181,8 @@ def test_positive_unregister_host_subscription( :parametrized: yes """ # register the host client - host_subscription_client.register_contenthost( - module_org.name, activation_key=ak_with_subscription.name - ) - + res = host_subscription_client.register(module_org, None, ak_with_subscription.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' assert host_subscription_client.subscribed host_subscription_client.run('subscription-manager attach --auto') host_subscription_client.enable_repo(module_rhst_repo) @@ -2265,9 +2253,8 @@ def test_syspurpose_end_to_end( } ) # Register a host using the activation key - host_subscription_client.register_contenthost( - module_org.name, activation_key=activation_key.name - ) + res = host_subscription_client.register(module_org, None, activation_key.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' assert host_subscription_client.subscribed host_subscription_client.run('subscription-manager attach --auto') host_subscription_client.enable_repo(module_rhst_repo) diff --git a/tests/foreman/cli/test_hostcollection.py b/tests/foreman/cli/test_hostcollection.py index ce3426030b5..4be5197431b 100644 --- a/tests/foreman/cli/test_hostcollection.py +++ b/tests/foreman/cli/test_hostcollection.py @@ -317,9 +317,8 @@ def test_positive_register_host_ak_with_host_collection(module_org, module_ak_wi ) with Broker(nick='rhel7', host_class=ContentHost) as client: - client.install_katello_ca(target_sat) # register the client host with the current activation key - client.register_contenthost(module_org.name, activation_key=module_ak_with_cv.name) + client.register(module_org, None, module_ak_with_cv.name, target_sat) assert client.subscribed # note: when registering the host, it should be automatically added to the host-collection client_host = target_sat.cli.Host.info({'name': client.hostname}) diff --git a/tests/foreman/cli/test_reporttemplates.py b/tests/foreman/cli/test_reporttemplates.py index 9c9bcf0e5a6..ec954a5f0b1 100644 --- a/tests/foreman/cli/test_reporttemplates.py +++ b/tests/foreman/cli/test_reporttemplates.py @@ -770,8 +770,13 @@ def test_positive_generate_entitlements_report_multiple_formats( :customerscenario: true """ client = rhel7_contenthost - client.install_katello_ca(target_sat) - client.register_contenthost(module_entitlement_manifest_org.label, local_ak['name']) + result = client.register( + module_entitlement_manifest_org, + None, + [local_ak.name], + insecure=True, + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed result_html = target_sat.cli.ReportTemplate.generate( { @@ -832,8 +837,13 @@ def test_positive_schedule_entitlements_report( :parametrized: yes """ client = rhel7_contenthost - client.install_katello_ca(target_sat) - client.register_contenthost(module_entitlement_manifest_org.label, local_ak['name']) + result = client.register( + module_entitlement_manifest_org, + None, + [local_ak.name], + insecure=True, + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed scheduled_csv = target_sat.cli.ReportTemplate.schedule( { @@ -939,9 +949,13 @@ def test_positive_generate_hostpkgcompare( with Broker(nick='rhel7', host_class=ContentHost, _count=2) as hosts: for client in hosts: # Create RHEL hosts via broker and register content host - client.install_katello_ca(target_sat) - # Register content host, install katello-agent - client.register_contenthost(module_entitlement_manifest_org.label, local_ak['name']) + result = client.register( + module_entitlement_manifest_org, + None, + [local_ak.name], + insecure=True, + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed clients.append(client) client.enable_repo(REPOS['rhst7']['id']) @@ -1065,8 +1079,13 @@ def test_positive_generate_installed_packages_report( } ) client = rhel_contenthost - client.install_katello_ca(target_sat) - client.register_contenthost(module_entitlement_manifest_org.label, local_ak['name']) + result = client.register( + module_entitlement_manifest_org, + None, + [local_ak.name], + insecure=True, + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed client.execute(f'yum -y install {FAKE_0_CUSTOM_PACKAGE_NAME} {FAKE_1_CUSTOM_PACKAGE}') result_html = target_sat.cli.ReportTemplate.generate( diff --git a/tests/foreman/cli/test_subscription.py b/tests/foreman/cli/test_subscription.py index c28ba08e61a..2953655aa66 100644 --- a/tests/foreman/cli/test_subscription.py +++ b/tests/foreman/cli/test_subscription.py @@ -252,7 +252,7 @@ def test_positive_candlepin_events_processed_by_STOMP(): @pytest.mark.tier2 def test_positive_auto_attach_disabled_golden_ticket( - module_org, golden_ticket_host_setup, rhel7_contenthost_class, target_sat + module_org, module_location, golden_ticket_host_setup, rhel7_contenthost_class, target_sat ): """Verify that Auto-Attach is disabled or "Not Applicable" when a host organization is in Simple Content Access mode (Golden Ticket) @@ -270,8 +270,9 @@ def test_positive_auto_attach_disabled_golden_ticket( :CaseImportance: Medium """ - rhel7_contenthost_class.install_katello_ca(target_sat) - rhel7_contenthost_class.register_contenthost(module_org.label, golden_ticket_host_setup['name']) + rhel7_contenthost_class.register( + module_org, module_location, golden_ticket_host_setup['name'], target_sat + ) assert rhel7_contenthost_class.subscribed host = target_sat.cli.Host.list({'search': rhel7_contenthost_class.hostname}) host_id = host[0]['id'] diff --git a/tests/foreman/ui/test_activationkey.py b/tests/foreman/ui/test_activationkey.py index 7630a1761b9..1a2765bab80 100644 --- a/tests/foreman/ui/test_activationkey.py +++ b/tests/foreman/ui/test_activationkey.py @@ -819,7 +819,7 @@ def test_positive_add_docker_repo_ccv(session, module_org, module_target_sat): @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 -def test_positive_add_host(session, module_org, rhel6_contenthost, target_sat): +def test_positive_add_host(session, module_org, rhel_contenthost, target_sat): """Test that hosts can be associated to Activation Keys :id: 886e9ea5-d917-40e0-a3b1-41254c4bf5bf @@ -839,21 +839,20 @@ def test_positive_add_host(session, module_org, rhel6_contenthost, target_sat): ).search()[0], organization=module_org, ).create() - - rhel6_contenthost.install_katello_ca(target_sat) - rhel6_contenthost.register_contenthost(module_org.label, ak.name) - assert rhel6_contenthost.subscribed + result = rhel_contenthost.register(module_org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' + assert rhel_contenthost.subscribed with session: session.location.select(constants.DEFAULT_LOC) session.organization.select(module_org.name) ak = session.activationkey.read(ak.name, widget_names='content_hosts') assert len(ak['content_hosts']['table']) == 1 - assert ak['content_hosts']['table'][0]['Name'] == rhel6_contenthost.hostname + assert ak['content_hosts']['table'][0]['Name'] == rhel_contenthost.hostname @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 -def test_positive_delete_with_system(session, rhel6_contenthost, target_sat): +def test_positive_delete_with_system(session, rhel_contenthost, target_sat): """Delete an Activation key which has registered systems :id: 86cd070e-cf46-4bb1-b555-e7cb42e4dc9f @@ -884,9 +883,9 @@ def test_positive_delete_with_system(session, rhel6_contenthost, target_sat): ) assert session.activationkey.search(name)[0]['Name'] == name session.activationkey.add_subscription(name, product_name) - rhel6_contenthost.install_katello_ca(target_sat) - rhel6_contenthost.register_contenthost(org.label, name) - assert rhel6_contenthost.subscribed + result = rhel_contenthost.register(org, None, name, target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' + assert rhel_contenthost.subscribed session.activationkey.delete(name) assert session.activationkey.search(name)[0]['Name'] != name @@ -917,11 +916,10 @@ def test_negative_usage_limit(session, module_org, target_sat): assert ak['details']['hosts_limit'] == hosts_limit with Broker(nick='rhel6', host_class=ContentHost, _count=2) as hosts: vm1, vm2 = hosts - vm1.install_katello_ca(target_sat) - vm1.register_contenthost(module_org.label, name) + result = vm1.register(module_org, None, name, target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert vm1.subscribed - vm2.install_katello_ca(target_sat) - result = vm2.register_contenthost(module_org.label, name) + result = vm2.register(module_org, None, name, target_sat) assert not vm2.subscribed assert len(result.stderr) assert f'Max Hosts ({hosts_limit}) reached for activation key' in str(result.stderr) @@ -931,7 +929,7 @@ def test_negative_usage_limit(session, module_org, target_sat): @pytest.mark.tier3 @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.repos_hosting_url), reason='Missing repos_hosting_url') -def test_positive_add_multiple_aks_to_system(session, module_org, rhel6_contenthost, target_sat): +def test_positive_add_multiple_aks_to_system(session, module_org, rhel_contenthost, target_sat): """Check if multiple Activation keys can be attached to a system :id: 4d6b6b69-9d63-4180-af2e-a5d908f8adb7 @@ -975,14 +973,16 @@ def test_positive_add_multiple_aks_to_system(session, module_org, rhel6_contenth ] assert product_name in subscriptions # Create VM - rhel6_contenthost.install_katello_ca(target_sat) - rhel6_contenthost.register_contenthost(module_org.label, ','.join([key_1_name, key_2_name])) - assert rhel6_contenthost.subscribed + result = rhel_contenthost.register( + module_org, None, ','.join([key_1_name, key_2_name]), target_sat + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' + assert rhel_contenthost.subscribed # Assert the content-host association with activation keys for key_name in [key_1_name, key_2_name]: ak = session.activationkey.read(key_name, widget_names='content_hosts') assert len(ak['content_hosts']['table']) == 1 - assert ak['content_hosts']['table'][0]['Name'] == rhel6_contenthost.hostname + assert ak['content_hosts']['table'][0]['Name'] == rhel_contenthost.hostname @pytest.mark.skip_if_not_set('clients') @@ -1014,11 +1014,12 @@ def test_positive_host_associations(session, target_sat): ).create() with Broker(nick='rhel7', host_class=ContentHost, _count=2) as hosts: vm1, vm2 = hosts - vm1.install_katello_ca(target_sat) - vm1.register_contenthost(org.label, ak1.name) + result = vm1.register(org, None, [ak1.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert vm1.subscribed - vm2.install_katello_ca(target_sat) - vm2.register_contenthost(org.label, ak2.name) + + result = vm2.register(org, None, [ak2.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert vm2.subscribed with session: session.organization.select(org.name) @@ -1084,8 +1085,8 @@ def test_positive_service_level_subscription_with_custom_product( activation_key.service_level = 'Premium' activation_key = activation_key.update(['service_level']) - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(org.label, activation_key=activation_key.name) + result = rhel7_contenthost.register(org, None, [activation_key.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed result = rhel7_contenthost.run('subscription-manager list --consumed') assert result.status == 0 @@ -1144,7 +1145,7 @@ def test_positive_delete_manifest(session, function_entitlement_manifest_org, ta @pytest.mark.skip_if_not_set('clients') @pytest.mark.tier3 @pytest.mark.skipif((not settings.robottelo.repos_hosting_url), reason='Missing repos_hosting_url') -def test_positive_ak_with_custom_product_on_rhel6(session, rhel6_contenthost, target_sat): +def test_positive_ak_with_custom_product_on_rhel6(session, rhel_contenthost, target_sat): """Registering a rhel6 host using an ak with custom repos should not fail :id: 4efed0b5-99af-4933-bea7-92a33984ce10 @@ -1166,15 +1167,16 @@ def test_positive_ak_with_custom_product_on_rhel6(session, rhel6_contenthost, ta {'url': settings.repos.yum_1.url, 'organization-id': org.id} ) ak = target_sat.api.ActivationKey(id=entities_ids['activationkey-id']).read() - rhel6_contenthost.install_katello_ca(target_sat) - result = rhel6_contenthost.register_contenthost(org.label, activation_key=ak.name) + + result = rhel_contenthost.register(org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert 'The system has been registered with ID' in result.stdout with target_sat.ui_session() as session: session.location.select(constants.DEFAULT_LOC) session.organization.select(org.name) ak = session.activationkey.read(ak.name, widget_names='content_hosts') assert len(ak['content_hosts']['table']) == 1 - assert ak['content_hosts']['table'][0]['Name'] == rhel6_contenthost.hostname + assert ak['content_hosts']['table'][0]['Name'] == rhel_contenthost.hostname def test_positive_prepare_for_sca_only_ak(target_sat, function_entitlement_manifest_org): diff --git a/tests/foreman/ui/test_reporttemplates.py b/tests/foreman/ui/test_reporttemplates.py index fe833d683fb..66a06a6dfb0 100644 --- a/tests/foreman/ui/test_reporttemplates.py +++ b/tests/foreman/ui/test_reporttemplates.py @@ -515,9 +515,9 @@ def test_positive_gen_entitlements_reports_multiple_formats( :CaseImportance: High """ client = rhel7_contenthost - client.install_katello_ca(target_sat) module_org, ak = setup_content - client.register_contenthost(module_org.label, ak.name) + result = client.register(module_org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed with session: session.location.select('Default Location') @@ -597,8 +597,8 @@ def test_positive_generate_all_installed_packages_report( } ) client = rhel_contenthost - client.install_katello_ca(target_sat) - client.register_contenthost(org.label, ak.name) + result = client.register(org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert client.subscribed client.execute(f'yum -y install {FAKE_0_CUSTOM_PACKAGE_NAME} {FAKE_1_CUSTOM_PACKAGE}') with session: diff --git a/tests/foreman/ui/test_subscription.py b/tests/foreman/ui/test_subscription.py index 45bfcd47d91..9a581291536 100644 --- a/tests/foreman/ui/test_subscription.py +++ b/tests/foreman/ui/test_subscription.py @@ -467,9 +467,9 @@ def test_positive_subscription_status_disabled_golden_ticket( :CaseImportance: Medium """ - rhel7_contenthost.install_katello_ca(target_sat) org, ak = golden_ticket_host_setup - rhel7_contenthost.register_contenthost(org.label, ak.name) + result = rhel7_contenthost.register(org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' assert rhel7_contenthost.subscribed with session: session.organization.select(org_name=org.name) @@ -518,8 +518,8 @@ def test_positive_candlepin_events_processed_by_STOMP( organization=org, environment=target_sat.api.LifecycleEnvironment(id=org.library.id), ).create() - rhel7_contenthost.install_katello_ca(target_sat) - rhel7_contenthost.register_contenthost(org.name, ak.name) + result = rhel7_contenthost.register(org, None, [ak.name], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' with session: session.organization.select(org_name=org.name) host = session.contenthost.read(rhel7_contenthost.hostname, widget_names='details')[