Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions robottelo/cli/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ def add_host_collection(cls, options=None):
cls.command_sub = 'add-host-collection'
return cls.execute(cls._construct_command(options))

@classmethod
def add_subscription(cls, options=None):
"""Add subscription"""
cls.command_sub = 'add-subscription'
return cls.execute(cls._construct_command(options))

@classmethod
def content_override(cls, options=None):
"""Override product content defaults"""
Expand Down Expand Up @@ -81,15 +75,3 @@ def remove_repository(cls, options=None):
"""Disassociate a resource"""
cls.command_sub = 'remove-repository'
return cls.execute(cls._construct_command(options))

@classmethod
def remove_subscription(cls, options=None):
"""Remove subscription"""
cls.command_sub = 'remove-subscription'
return cls.execute(cls._construct_command(options))

@classmethod
def subscriptions(cls, options=None, output_format=None):
"""List associated subscriptions"""
cls.command_sub = 'subscriptions'
return cls.execute(cls._construct_command(options), output_format=output_format)
39 changes: 0 additions & 39 deletions robottelo/cli/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,45 +407,6 @@ def subscription_unregister(cls, options=None):
cls.command_sub = 'subscription unregister'
return cls.execute(cls._construct_command(options))

@classmethod
def subscription_attach(cls, options=None):
"""Attach a subscription to host

Usage::

hammer host subscription attach [OPTIONS]

Options::

--host HOST_NAME Name to search by
--host-id HOST_ID Host ID
--quantity Quantity Quantity of this subscriptions to
add. Defaults to 1
--subscription-id SUBSCRIPTION_ID ID of subscription
"""
cls.command_sub = 'subscription attach'
return cls.execute(cls._construct_command(options))

@classmethod
def subscription_remove(cls, options=None):
"""Remove a subscription from host

Usage::

hammer host subscription remove [OPTIONS]

Options::

--host HOST_NAME Name to search by
--host-id HOST_ID
--quantity Quantity Remove the first instance of a
subscription with matching id
and quantity
--subscription-id SUBSCRIPTION_ID ID of subscription
"""
cls.command_sub = 'subscription remove'
return cls.execute(cls._construct_command(options))

@classmethod
def sc_params(cls, options=None):
"""List all smart class parameters
Expand Down
53 changes: 0 additions & 53 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,34 +546,6 @@ def make_template(self, options=None):

return create_object(self._satellite.cli.Template, args, options)

def activationkey_add_subscription_to_repo(self, options=None):
"""Helper function that adds subscription to an activation key"""
# List the subscriptions in given org
subscriptions = self._satellite.cli.Subscription.list(
{'organization-id': options['organization-id']}, per_page=False
)
# Add subscription to activation-key
if options['subscription'] not in (sub['name'] for sub in subscriptions):
raise CLIFactoryError(
'Subscription {} not found in the given org'.format(options['subscription'])
)
for subscription in subscriptions:
if subscription['name'] == options['subscription']:
if subscription['quantity'] != 'Unlimited' and int(subscription['quantity']) == 0:
raise CLIFactoryError('All the subscriptions are already consumed')
try:
self._satellite.cli.ActivationKey.add_subscription(
{
'id': options['activationkey-id'],
'subscription-id': subscription['id'],
'quantity': 1,
}
)
except CLIReturnCodeError as err:
raise CLIFactoryError(
f'Failed to add subscription to activation key\n{err.msg}'
) from err

def override_repos_for_activation_key(self, ak_id, repos, value=True):
"""Hammer override satellite repo(s) to value for Activation Key.

Expand Down Expand Up @@ -722,15 +694,6 @@ def setup_org_for_a_custom_repo(self, options=None):
f'Failed to associate activation-key with CV\n{err.msg}'
) from err

# Add custom_product subscription to activation-key, if SCA mode is disabled
if self._satellite.is_sca_mode_enabled(org_id) is False:
self.activationkey_add_subscription_to_repo(
{
'activationkey-id': activationkey_id,
'organization-id': org_id,
'subscription': custom_product['name'],
}
)
# Override custom product to true ( turned off by default in 6.14 )
custom_repo = self._satellite.cli.Repository.info({'id': custom_repo['id']})
self._satellite.cli.ActivationKey.content_override(
Expand Down Expand Up @@ -874,17 +837,6 @@ def _setup_org_for_a_rh_repo(self, options=None, force=False):
f'Failed to associate activation-key with CV\n{err.msg}'
) from err

# Add default subscription to activation-key, if SCA mode is disabled
if self._satellite.is_sca_mode_enabled(org_id) is False:
self.activationkey_add_subscription_to_repo(
{
'organization-id': org_id,
'activationkey-id': activationkey_id,
'subscription': options.get(
'subscription', constants.DEFAULT_SUBSCRIPTION_NAME
),
}
)
# Override RHST product to true ( turned off by default in 6.14 )
rhel_repo = self._satellite.cli.Repository.info({'id': rhel_repo['id']})
self._satellite.cli.ActivationKey.content_override(
Expand Down Expand Up @@ -1058,7 +1010,6 @@ def setup_cdn_and_custom_repos_content(
lce_id=None,
repos=None,
download_policy='on_demand',
rh_subscriptions=None,
default_cv=False,
):
"""Setup cdn and custom repositories, content view and activations key
Expand All @@ -1069,14 +1020,10 @@ def setup_cdn_and_custom_repos_content(
:param bool default_cv: whether to use the Default Organization CV
:param str download_policy: update the repositories with this download
policy
:param list rh_subscriptions: a list of RH subscription to attach to
activation key
:return: a dict containing the activation key, content view and repos info
"""
if repos is None:
repos = []
if rh_subscriptions is None:
rh_subscriptions = []

custom_product, repos_info = self.setup_cdn_and_custom_repositories(
org_id=org_id, repos=repos, download_policy=download_policy
Expand Down
54 changes: 3 additions & 51 deletions robottelo/host_helpers/repository_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,34 +716,6 @@ def setup_activation_key(
'value': int(override),
}
)
if self.satellite.is_sca_mode_enabled(org_id):
return activation_key
# Add subscriptions to activation-key
# Get organization subscriptions
subscriptions = self.satellite.cli.Subscription.list(
{'organization-id': org_id}, per_page=False
)
added_subscription_names = []
for subscription in subscriptions:
if (
subscription['name'] in 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(subscription_names):
break
missing_subscription_names = set(subscription_names).difference(
set(added_subscription_names)
)
if missing_subscription_names:
raise ValueError(f'Missing subscriptions: {missing_subscription_names}')
return activation_key

def organization_has_manifest(self, organization_id):
Expand All @@ -760,7 +732,6 @@ def setup_content(
org_id,
lce_id,
download_policy='on_demand',
rh_subscriptions=None,
override=None,
):
"""
Expand All @@ -769,34 +740,15 @@ def setup_content(
:param org_id: The organization id
:param lce_id: The lifecycle environment id
:param download_policy: The repositories download policy
:param rh_subscriptions: The RH subscriptions to be added to activation key
:param override: Content override (True = enable, False = disable, None = no action)
"""
if self._repos_info:
raise RepositoryAlreadyCreated('Repositories already created can not setup content')
if rh_subscriptions is None:
rh_subscriptions = []
if self.need_subscription and not rh_subscriptions:
# add the default subscription if no subscription provided
rh_subscriptions = [constants.DEFAULT_SUBSCRIPTION_NAME]
custom_product, repos_info = self.setup(org_id=org_id, download_policy=download_policy)
content_view, lce = self.setup_content_view(org_id, lce_id)
custom_product_name = custom_product['name'] if custom_product else None
subscription_names = list(rh_subscriptions)
if custom_product_name:
subscription_names.append(custom_product_name)
if not self.satellite.is_sca_mode_enabled(org_id):
activation_key = self.setup_activation_key(
org_id,
content_view['id'],
lce_id,
subscription_names=subscription_names,
override=override,
)
else:
activation_key = self.setup_activation_key(
org_id, content_view['id'], lce_id, override=override
)
activation_key = self.setup_activation_key(
org_id, content_view['id'], lce_id, override=override
)
setup_content_data = dict(
activation_key=activation_key,
content_view=content_view,
Expand Down
33 changes: 3 additions & 30 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ def virt_who_hypervisor_config(
org['id'],
lce['id'],
repos,
rh_subscriptions=[constants.DEFAULT_SUBSCRIPTION_NAME],
)
activation_key = content_setup_data['activation_key']
content_view = content_setup_data['content_view']
Expand Down Expand Up @@ -1447,20 +1446,8 @@ def virt_who_hypervisor_config(
if len(org_hosts) == 0:
raise CLIFactoryError(f'Failed to find hypervisor host:\n{result.stderr}')
virt_who_hypervisor_host = org_hosts[0]
subscription_id = None
if hypervisor_hostname and subscription_name:
subscriptions = satellite.cli.Subscription.list(
{'organization-id': org_id}, per_page=False
)
for subscription in subscriptions:
if subscription['name'] == subscription_name:
subscription_id = subscription['id']
Host.subscription_attach(
{'host': virt_who_hypervisor_hostname, 'subscription-id': subscription_id}
)
break
return {
'subscription_id': subscription_id,
'subscription_id': None,
'subscription_name': subscription_name,
'activation_key_id': activation_key['id'],
'organization_id': org['id'],
Expand Down Expand Up @@ -2481,22 +2468,8 @@ def register_host_custom_repo(self, module_org, rhel_contenthost, repo_urls):
rhsm_id = rhel_contenthost.execute('subscription-manager identity')
assert module_org.name in rhsm_id.stdout, 'Host is not registered to expected organization'
rhel_contenthost._satellite = self

# Attach product subscriptions to contenthost, only if SCA mode is disabled
if self.is_sca_mode_enabled(module_org.id) is False:
subs = self.api.Subscription(organization=module_org, name=prod.name).search()
assert len(subs), f'Subscription for sat client product: {prod.name} was not found.'
subscription = subs[0]

rhel_contenthost.nailgun_host.bulk_add_subscriptions(
data={
"organization_id": module_org.id,
"included": {"ids": [rhel_contenthost.nailgun_host.id]},
"subscriptions": [{"id": subscription.id, "quantity": 1}],
}
)
# refresh repository metadata on the host
rhel_contenthost.execute('subscription-manager repos --list')
# refresh repository metadata on the host
rhel_contenthost.execute('subscription-manager repos --list')
Comment on lines +2471 to +2472
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this, but I don't mind keeping it either.


# Override the repos to enabled
rhel_contenthost.execute(r'subscription-manager repos --enable \*')
Expand Down
15 changes: 0 additions & 15 deletions tests/foreman/api/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
from nailgun.config import ServerConfig
from nailgun.entity_mixins import TaskFailedError
import pytest
from requests.exceptions import HTTPError

from robottelo.config import settings
from robottelo.constants import (
DEFAULT_SUBSCRIPTION_NAME,
FAKE_0_CUSTOM_PACKAGE_NAME,
PRDS,
REPOS,
Expand Down Expand Up @@ -226,19 +224,6 @@ def test_sca_end_to_end(
)
assert result.status == 0, f'Failed to register host: {result.stderr}'
assert rhel_contenthost.subscribed
# Verify that you cannot attach a subscription to an activation key in SCA Mode
subscription = target_sat.api.Subscription(organization=module_sca_manifest_org).search(
query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'}
)[0]
with pytest.raises(HTTPError) as ak_context:
module_ak.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id})
assert 'Simple Content Access' in ak_context.value.response.text
# Verify that you cannot attach a subscription to an Host in SCA Mode
with pytest.raises(HTTPError) as host_context:
target_sat.api.HostSubscription(host=rhel_contenthost.nailgun_host.id).add_subscriptions(
data={'subscriptions': [{'id': subscription.id, 'quantity': 1}]}
)
assert 'Simple Content Access' in host_context.value.response.text
# Create a content view with repos and check to see that the client has access
content_view = target_sat.api.ContentView(organization=module_sca_manifest_org).create()
content_view.repository = [rh_repo, custom_repo]
Expand Down
12 changes: 0 additions & 12 deletions tests/foreman/cli/test_activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,15 +1672,3 @@ def test_syspurpose_end_to_end(
assert host['subscription-information']['system-purpose']['purpose-role'] == "test-role2"
assert host['subscription-information']['system-purpose']['purpose-usage'] == "test-usage2"
assert host['subscription-information']['system-purpose']['service-level'] == "Self-Support2"

rhel_contenthost.unregister()
with pytest.raises(CLIReturnCodeError):
# raise error that the host was not registered by
# subscription-manager register
target_sat.cli.ActivationKey.subscriptions(
{
'organization-id': module_org.id,
'id': activation_key.id,
'host-id': host['id'],
}
)
11 changes: 0 additions & 11 deletions tests/foreman/cli/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,17 +1847,6 @@ def test_positive_register(
assert len(hosts) > 0
host = target_sat.cli.Host.info({'id': hosts[0]['id']})
assert host['name'] == rhel_contenthost.hostname
# note: when not registered the following command lead to exception,
# see unregister
host_subscriptions = target_sat.cli.ActivationKey.subscriptions(
{
'organization-id': module_org.id,
'id': module_ak_with_cv.id,
'host-id': host['id'],
},
output_format='json',
)
assert len(host_subscriptions) == 0


# -------------------------- MULTI-CV SCENARIOS -------------------------
Expand Down
2 changes: 0 additions & 2 deletions tests/foreman/cli/test_rhcloud_iop.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def test_positive_install_iop_custom_certs(
service_level='Self-Support',
purpose_usage='test-usage',
purpose_role='test-role',
auto_attach=False,
).create()

host.configure_rex(satellite=satellite, org=org, register=False)
Expand Down Expand Up @@ -198,7 +197,6 @@ def test_disable_enable_iop(satellite_iop, module_sca_manifest, rhel_contenthost
service_level='Self-Support',
purpose_usage='test-usage',
purpose_role='test-role',
auto_attach=False,
).create()

host.configure_rex(satellite=satellite, org=org, register=False)
Expand Down
Loading