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 Apr 23, 2024
1 parent 9de3979 commit 37ea130
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 132 deletions.
9 changes: 9 additions & 0 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions pytest_fixtures/component/contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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]
Expand Down
9 changes: 7 additions & 2 deletions tests/foreman/api/test_hostcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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
47 changes: 36 additions & 11 deletions tests/foreman/api/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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


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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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


Expand Down
Loading

0 comments on commit 37ea130

Please sign in to comment.