Skip to content

Commit

Permalink
[RFE] Updating Subscription Management to be SCA Only (#15637)
Browse files Browse the repository at this point in the history
* Updating sub man to be sca only

* Sca only upgrades

* Addessing comments

* Updating old manifest to golden ticket

* adding sleep to stomp test

* Address comments and update manifester

* update failures with precommit
  • Loading branch information
ColeHiggins2 authored Aug 30, 2024
1 parent 8add98b commit 8dfeed3
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 276 deletions.
29 changes: 27 additions & 2 deletions pytest_fixtures/component/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def upgrade_entitlement_manifest_org(function_org, upgrade_entitlement_manifest,
return function_org


@pytest.fixture
def sca_manifest_org_for_upgrade(function_org, sca_manifest_for_upgrade, target_sat):
"""A Pytest fixture that creates an organization and uploads an sca mode manifest
generated with Manifester. This will be used for upgrade scenarios"""
sca_manifest, _ = sca_manifest_for_upgrade
target_sat.upload_manifest(function_org.id, sca_manifest.content)
return function_org


@pytest.fixture
def function_sca_manifest_org(function_org, function_sca_manifest, target_sat):
"""Creates an organization and uploads an SCA mode manifest generated with manifester"""
Expand Down Expand Up @@ -247,6 +256,15 @@ def function_sca_manifest():
yield manifest


@pytest.fixture
def second_function_sca_manifest():
"""Yields a manifest in Simple Content Access mode with subscriptions determined by the
`manifest_category.golden_ticket` setting in conf/manifest.yaml.
A different one than is used in `function_sca_manifest_org`."""
with Manifester(manifest_category=settings.manifest.golden_ticket) as manifest:
yield manifest


@pytest.fixture(scope='module')
def smart_proxy_location(module_org, module_target_sat, default_smart_proxy):
location = module_target_sat.api.Location(organization=[module_org]).create()
Expand All @@ -260,5 +278,12 @@ def upgrade_entitlement_manifest():
"""Returns a manifest in entitlement mode with subscriptions determined by the
`manifest_category.entitlement` setting in conf/manifest.yaml. used only for
upgrade scenarios"""
manifestor = Manifester(manifest_category=settings.manifest.entitlement)
return manifestor.get_manifest(), manifestor
manifester = Manifester(manifest_category=settings.manifest.entitlement)
return manifester.get_manifest(), manifester


@pytest.fixture
def sca_manifest_for_upgrade():
"""Returns a manifest in sca mode. Used only for upgrade scenarios"""
manifester = Manifester(manifest_category=settings.manifest.golden_ticket)
return manifester.get_manifest(), manifester
29 changes: 0 additions & 29 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,35 +1151,6 @@ def setup_cdn_and_custom_repos_content(
'content-view-id': content_view['id'],
}
)
# Get organization subscriptions
subscriptions = self._satellite.cli.Subscription.list(
{'organization-id': org_id}, per_page=False
)
# Add subscriptions to activation-key
needed_subscription_names = list(rh_subscriptions)
if custom_product:
needed_subscription_names.append(custom_product['name'])
added_subscription_names = []
for subscription in subscriptions:
if (
subscription['name'] in needed_subscription_names
and subscription['name'] not in added_subscription_names
):
self._satellite.cli.ActivationKey.add_subscription(
{
'id': activation_key['id'],
'subscription-id': subscription['id'],
'quantity': 1,
}
)
added_subscription_names.append(subscription['name'])
if len(added_subscription_names) == len(needed_subscription_names):
break
missing_subscription_names = set(needed_subscription_names).difference(
set(added_subscription_names)
)
if missing_subscription_names:
raise CLIFactoryError(f'Missing subscriptions: {missing_subscription_names}')
data = dict(
activation_key=activation_key,
content_view=content_view,
Expand Down
4 changes: 2 additions & 2 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ def virt_who_hypervisor_config(
]
repos.extend(extra_repos)
content_setup_data = satellite.cli_factory.setup_cdn_and_custom_repos_content(
org[id],
lce[id],
org['id'],
lce['id'],
repos,
upload_manifest=upload_manifest,
rh_subscriptions=[constants.DEFAULT_SUBSCRIPTION_NAME],
Expand Down
133 changes: 45 additions & 88 deletions tests/foreman/api/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"""

import re
import time

from fauxfactory import gen_string
from nailgun.config import ServerConfig
from nailgun.entity_mixins import TaskFailedError
Expand Down Expand Up @@ -68,7 +71,7 @@ def module_ak(module_sca_manifest_org, rh_repo, custom_repo, module_target_sat):

@pytest.mark.tier1
@pytest.mark.pit_server
def test_positive_create(module_entitlement_manifest, module_target_sat):
def test_positive_create(module_sca_manifest, module_target_sat):
"""Upload a manifest.
:id: 6faf9d96-9b45-4bdc-afa9-ec3fbae83d41
Expand All @@ -78,11 +81,11 @@ def test_positive_create(module_entitlement_manifest, module_target_sat):
:CaseImportance: Critical
"""
org = module_target_sat.api.Organization().create()
module_target_sat.upload_manifest(org.id, module_entitlement_manifest.content)
module_target_sat.upload_manifest(org.id, module_sca_manifest.content)


@pytest.mark.tier1
def test_positive_refresh(function_entitlement_manifest_org, request, target_sat):
def test_positive_refresh(function_sca_manifest_org, request, target_sat):
"""Upload a manifest and refresh it afterwards.
:id: cd195db6-e81b-42cb-a28d-ec0eb8a53341
Expand All @@ -91,7 +94,7 @@ def test_positive_refresh(function_entitlement_manifest_org, request, target_sat
:CaseImportance: Critical
"""
org = function_entitlement_manifest_org
org = function_sca_manifest_org
sub = target_sat.api.Subscription(organization=org)
request.addfinalizer(lambda: sub.delete_manifest(data={'organization_id': org.id}))
sub.refresh_manifest(data={'organization_id': org.id})
Expand All @@ -100,7 +103,7 @@ def test_positive_refresh(function_entitlement_manifest_org, request, target_sat

@pytest.mark.tier1
def test_positive_create_after_refresh(
function_entitlement_manifest_org, function_secondary_entitlement_manifest, target_sat
function_sca_manifest_org, second_function_sca_manifest, target_sat
):
"""Upload a manifest,refresh it and upload a new manifest to an other
organization.
Expand All @@ -115,20 +118,20 @@ def test_positive_create_after_refresh(
:CaseImportance: Critical
"""
org_sub = target_sat.api.Subscription(organization=function_entitlement_manifest_org)
org_sub = target_sat.api.Subscription(organization=function_sca_manifest_org)
new_org = target_sat.api.Organization().create()
new_org_sub = target_sat.api.Subscription(organization=new_org)
try:
org_sub.refresh_manifest(data={'organization_id': function_entitlement_manifest_org.id})
org_sub.refresh_manifest(data={'organization_id': function_sca_manifest_org.id})
assert org_sub.search()
target_sat.upload_manifest(new_org.id, function_secondary_entitlement_manifest.content)
target_sat.upload_manifest(new_org.id, second_function_sca_manifest.content)
assert new_org_sub.search()
finally:
org_sub.delete_manifest(data={'organization_id': function_entitlement_manifest_org.id})
org_sub.delete_manifest(data={'organization_id': function_sca_manifest_org.id})


@pytest.mark.tier1
def test_positive_delete(function_entitlement_manifest_org, target_sat):
def test_positive_delete(function_sca_manifest_org, target_sat):
"""Delete an Uploaded manifest.
:id: 4c21c7c9-2b26-4a65-a304-b978d5ba34fc
Expand All @@ -137,14 +140,14 @@ def test_positive_delete(function_entitlement_manifest_org, target_sat):
:CaseImportance: Critical
"""
sub = target_sat.api.Subscription(organization=function_entitlement_manifest_org)
sub = target_sat.api.Subscription(organization=function_sca_manifest_org)
assert sub.search()
sub.delete_manifest(data={'organization_id': function_entitlement_manifest_org.id})
sub.delete_manifest(data={'organization_id': function_sca_manifest_org.id})
assert len(sub.search()) == 0


@pytest.mark.tier2
def test_negative_upload(function_entitlement_manifest, target_sat):
def test_negative_upload(function_sca_manifest, target_sat):
"""Upload the same manifest to two organizations.
:id: 60ca078d-cfaf-402e-b0db-34d8901449fe
Expand All @@ -153,17 +156,15 @@ def test_negative_upload(function_entitlement_manifest, target_sat):
organization.
"""
orgs = [target_sat.api.Organization().create() for _ in range(2)]
with function_entitlement_manifest as manifest:
with function_sca_manifest as manifest:
target_sat.upload_manifest(orgs[0].id, manifest.content)
with pytest.raises(TaskFailedError):
target_sat.upload_manifest(orgs[1].id, manifest.content)
assert len(target_sat.api.Subscription(organization=orgs[1]).search()) == 0


@pytest.mark.tier2
def test_positive_delete_manifest_as_another_user(
function_org, function_entitlement_manifest, target_sat
):
def test_positive_delete_manifest_as_another_user(function_org, function_sca_manifest, target_sat):
"""Verify that uploaded manifest if visible and deletable
by a different user than the one who uploaded it
Expand Down Expand Up @@ -202,7 +203,7 @@ def test_positive_delete_manifest_as_another_user(
verify=settings.server.verify_ca,
)
# use the first admin to upload a manifest
with function_entitlement_manifest as manifest:
with function_sca_manifest as manifest:
target_sat.api.Subscription(server_config=sc1, organization=function_org).upload(
data={'organization_id': function_org.id}, files={'content': manifest.content}
)
Expand All @@ -213,34 +214,6 @@ def test_positive_delete_manifest_as_another_user(
assert len(target_sat.cli.Subscription.list({'organization-id': function_org.id})) == 0


@pytest.mark.tier2
def test_positive_subscription_status_disabled(
module_ak, rhel_contenthost, module_sca_manifest_org, target_sat
):
"""Verify that Content host Subscription status is set to 'Disabled'
for a golden ticket manifest
:id: d7d7e20a-e386-43d5-9619-da933aa06694
:expectedresults: subscription status is 'Disabled'
:customerscenario: true
:BZ: 1789924
:CaseImportance: Medium
"""
result = rhel_contenthost.api_register(
target_sat,
organization=module_sca_manifest_org,
activation_keys=[module_ak.name],
)
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)


@pytest.mark.tier2
@pytest.mark.e2e
@pytest.mark.pit_client
Expand Down Expand Up @@ -311,23 +284,24 @@ def test_sca_end_to_end(
@pytest.mark.rhel_ver_match('7')
@pytest.mark.tier2
def test_positive_candlepin_events_processed_by_stomp(
rhel_contenthost, function_entitlement_manifest, function_org, target_sat
function_org, target_sat, function_sca_manifest
):
"""Verify that Candlepin events are being read and processed by
attaching subscriptions, validating host subscriptions status,
checking candlepin events, uploading a manifest,
and viewing processed and failed Candlepin events
:id: efd20ffd-8f98-4536-abb6-d080f9d23169
:steps:
1. Add subscriptions to content host
2. Verify subscription status is invalid at
<your-satellite-url>/api/v2/hosts
1. Create a manifest
2. Check the number of candlepin events
/katello/api/v2/ping
3. Import a Manifest
4. Attach subs to content host
5. Verify subscription status is valid
6. Check ping api for processed and failed events
4. Check the number of new candlepin events
/katello/api/v2/ping
5. Verify that the new candlepin events value is greater than the old value
6. Verify that there are no failed candlepin events
/katello/api/v2/ping
:expectedresults: Candlepin events are being read and processed
Expand All @@ -338,40 +312,23 @@ def test_positive_candlepin_events_processed_by_stomp(
:CaseImportance: High
"""
repo = target_sat.api.Repository(
product=target_sat.api.Product(organization=function_org).create()
).create()
repo.sync()
ak = target_sat.api.ActivationKey(
content_view=function_org.default_content_view,
max_hosts=100,
organization=function_org,
environment=target_sat.api.LifecycleEnvironment(id=function_org.library.id),
auto_attach=True,
).create()
result = rhel_contenthost.api_register(
target_sat,
organization=function_org,
activation_keys=[ak.name],
)
assert result.status == 0, f'Failed to register host: {result.stderr}'
host = target_sat.api.Host().search(query={'search': f'name={rhel_contenthost.hostname}'})
host_id = host[0].id
host_content = target_sat.api.Host(id=host_id).read_json()
assert host_content['subscription_status'] == 2
with function_entitlement_manifest as manifest:
target_sat.upload_manifest(function_org.id, manifest.content)
subscription = target_sat.api.Subscription(organization=function_org).search(
query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'}
)[0]
target_sat.api.HostSubscription(host=host_id).add_subscriptions(
data={'subscriptions': [{'id': subscription.cp_id, 'quantity': 1}]}
)
host_content = target_sat.api.Host(id=host_id).read_json()
assert host_content['subscription_status'] == 0
response = target_sat.api.Ping().search_json()['services']['candlepin_events']
assert response['status'] == 'ok'
assert '0 Failed' in response['message']

# Function to parse candlepin events
def parse(events):
return {key: int(value) for value, key in re.findall(r'(\d+)\s(\w+)', events)}

pre_candlepin_events = target_sat.api.Ping().search_json()['services']['candlepin_events'][
'message'
]
target_sat.upload_manifest(function_org.id, function_sca_manifest.content)
time.sleep(5)
assert target_sat.api.Ping().search_json()['services']['candlepin_events']['status'] == 'ok'
post_candlepin_events = target_sat.api.Ping().search_json()['services']['candlepin_events'][
'message'
]
assert parse(post_candlepin_events)['Processed'] > parse(pre_candlepin_events)['Processed']
assert parse(pre_candlepin_events)['Failed'] == 0
assert parse(post_candlepin_events)['Failed'] == 0


@pytest.mark.rhel_ver_match('7')
Expand Down
Loading

0 comments on commit 8dfeed3

Please sign in to comment.