From 03147f6d5e56f7c66f66bfbe1b9b3cfa07bdd765 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 --- tests/foreman/api/test_hostcollection.py | 9 ++++-- tests/foreman/api/test_reporttemplates.py | 27 ++++++++++++---- tests/foreman/api/test_subscription.py | 38 +++++++++++++++++------ tests/foreman/cli/test_activationkey.py | 36 ++++++++++----------- tests/foreman/cli/test_subscription.py | 5 ++- tests/foreman/ui/test_ansible.py | 22 +++++++++---- 6 files changed, 91 insertions(+), 46 deletions(-) diff --git a/tests/foreman/api/test_hostcollection.py b/tests/foreman/api/test_hostcollection.py index aea239ac1ad..ee0a4b98ea3 100644 --- a/tests/foreman/api/test_hostcollection.py +++ b/tests/foreman/api/test_hostcollection.py @@ -433,8 +433,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 3f988471913..1abf6c84ae3 100644 --- a/tests/foreman/api/test_subscription.py +++ b/tests/foreman/api/test_subscription.py @@ -230,8 +230,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) @@ -257,8 +262,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 ( @@ -336,8 +346,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() @@ -393,10 +408,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 diff --git a/tests/foreman/cli/test_activationkey.py b/tests/foreman/cli/test_activationkey.py index 68c43807fae..b29e53c65ef 100644 --- a/tests/foreman/cli/test_activationkey.py +++ b/tests/foreman/cli/test_activationkey.py @@ -267,7 +267,7 @@ def test_negative_create_with_usage_limit_with_not_integers(module_org, limit, m @pytest.mark.tier3 @pytest.mark.parametrize('invalid_values', ['-1', '-500', 0]) def test_negative_create_with_usage_limit_with_invalid_integers( - module_org, invalid_values, module_target_sat + module_org, invalid_values, module_target_sat ): """Create Activation key with invalid integers Usage Limit @@ -594,7 +594,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 @@ -629,11 +629,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 @@ -757,7 +755,7 @@ def test_positive_add_custom_product(module_org, module_target_sat): @pytest.mark.upgrade @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') def test_positive_add_redhat_and_custom_products( - module_target_sat, function_entitlement_manifest_org + module_target_sat, function_entitlement_manifest_org ): """Test if RH/Custom product can be associated to Activation key @@ -877,7 +875,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 @@ -905,9 +903,11 @@ 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 @@ -1499,7 +1499,7 @@ def test_positive_remove_user(module_org, module_target_sat): @pytest.mark.run_in_one_thread @pytest.mark.tier3 def test_positive_view_subscriptions_by_non_admin_user( - module_entitlement_manifest_org, module_target_sat + module_entitlement_manifest_org, module_target_sat ): """Attempt to read activation key subscriptions by non admin user @@ -1636,20 +1636,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: @@ -1662,7 +1661,7 @@ 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 @@ -1683,8 +1682,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_subscription.py b/tests/foreman/cli/test_subscription.py index c6d053a4659..44ea51a2c81 100644 --- a/tests/foreman/cli/test_subscription.py +++ b/tests/foreman/cli/test_subscription.py @@ -251,7 +251,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) @@ -269,8 +269,7 @@ 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_ansible.py b/tests/foreman/ui/test_ansible.py index a7a2ed28c06..e2409ad23ed 100644 --- a/tests/foreman/ui/test_ansible.py +++ b/tests/foreman/ui/test_ansible.py @@ -93,7 +93,7 @@ def test_positive_create_variable_with_overrides(target_sat): @pytest.mark.no_containers @pytest.mark.rhel_ver_match('[^6]') -def test_positive_config_report_ansible(session, target_sat, module_org, rhel_contenthost): +def test_positive_config_report_ansible(session, target_sat, module_org, rhel_contenthost, module_ak_with_cv): """Test Config Report generation with Ansible Jobs. :id: 118e25e5-409e-44ba-b908-217da9722576 @@ -116,8 +116,13 @@ def test_positive_config_report_ansible(session, target_sat, module_org, rhel_co if rhel_contenthost.os_version.major <= 7: rhel_contenthost.create_custom_repos(rhel7=settings.repos.rhel7_os) assert rhel_contenthost.execute('yum install -y insights-client').status == 0 - rhel_contenthost.install_katello_ca(target_sat) - rhel_contenthost.register_contenthost(module_org.label, force=True) + command = target_sat.api.RegistrationCommand( + organization=module_org, + activation_keys=[module_ak_with_cv.name], + insecure=True, + force=True, + ).create() + result = rhel_contenthost.execute(command) assert rhel_contenthost.subscribed rhel_contenthost.add_rex_key(satellite=target_sat) id = target_sat.nailgun_smart_proxy.id @@ -154,7 +159,7 @@ def test_positive_config_report_ansible(session, target_sat, module_org, rhel_co @pytest.mark.no_containers @pytest.mark.rhel_ver_match('9') -def test_positive_ansible_custom_role(target_sat, session, module_org, rhel_contenthost, request): +def test_positive_ansible_custom_role(target_sat, session, module_org, rhel_contenthost, request, module_ak_with_cv): """ Test Config report generation with Custom Ansible Role @@ -194,8 +199,13 @@ def test_positive_ansible_custom_role(target_sat, session, module_org, rhel_cont yaml.dump(data, f, sort_keys=False, default_flow_style=False) target_sat.execute('mkdir /etc/ansible/roles/custom_role') target_sat.put(playbook, '/etc/ansible/roles/custom_role/playbook.yaml') - rhel_contenthost.install_katello_ca(target_sat) - rhel_contenthost.register_contenthost(module_org.label, force=True) + command = target_sat.api.RegistrationCommand( + organization=module_org, + activation_keys=[module_ak_with_cv.name], + insecure=True, + force=True, + ).create() + result = rhel_contenthost.execute(command) assert rhel_contenthost.subscribed rhel_contenthost.add_rex_key(satellite=target_sat) proxy_id = target_sat.nailgun_smart_proxy.id