Skip to content

Commit

Permalink
Replace old method of registration with global registration in robottelo
Browse files Browse the repository at this point in the history
  • Loading branch information
shweta83 committed Feb 29, 2024
1 parent a963b00 commit 9c1ce40
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 50 deletions.
9 changes: 7 additions & 2 deletions tests/foreman/api/test_hostcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
27 changes: 21 additions & 6 deletions tests/foreman/api/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions tests/foreman/api/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions tests/foreman/cli/test_activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -905,9 +903,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


Expand Down Expand Up @@ -1636,20 +1638,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:
Expand All @@ -1662,7 +1663,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
Expand All @@ -1683,8 +1686,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


Expand Down
7 changes: 4 additions & 3 deletions tests/foreman/cli/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@pytest.mark.e2e
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match('[^6].*')
def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost, module_ak_with_cv):
"""
Test successful execution of Ansible Job on host.
Expand Down Expand Up @@ -57,8 +57,9 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
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)
result = rhel_contenthost.register(
module_org, None, module_ak_with_cv.name, target_sat, force=True
)
assert rhel_contenthost.subscribed
rhel_contenthost.add_rex_key(satellite=target_sat)
proxy_id = target_sat.nailgun_smart_proxy.id
Expand Down
12 changes: 8 additions & 4 deletions tests/foreman/cli/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,14 @@ 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}',
# rhel7_contenthost.install_katello_ca(target_sat)
# rhel7_contenthost.register_contenthost(
# module_org.label,
# lce=f'{module_lce.label}/{module_promoted_cv.label}',
# )
lce = f'{module_lce.label}/{module_promoted_cv.label}'
result = rhel7_contenthost.register(
module_org, None, module_promoted_cv.name, target_sat
)
assert rhel7_contenthost.subscribed
hosts = target_sat.cli.Host.list(
Expand Down
7 changes: 4 additions & 3 deletions tests/foreman/cli/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -269,8 +269,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']
Expand Down
26 changes: 20 additions & 6 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ 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
Expand All @@ -116,8 +118,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
Expand Down Expand Up @@ -154,7 +161,9 @@ 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
Expand Down Expand Up @@ -194,8 +203,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
Expand Down

0 comments on commit 9c1ce40

Please sign in to comment.