Skip to content

Commit

Permalink
UI::ERRATA WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed May 24, 2024
1 parent 22fb9ef commit dccc72f
Show file tree
Hide file tree
Showing 3 changed files with 557 additions and 542 deletions.
1 change: 1 addition & 0 deletions robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@
REAL_RHEL7_0_ERRATA_ID = 'RHBA-2020:3615' # for REAL_RHEL7_0_0_PACKAGE
REAL_RHEL7_1_ERRATA_ID = 'RHBA-2017:0395' # tcsh bug fix update
REAL_RHEL8_1_ERRATA_ID = 'RHSA-2022:4867' # for REAL_RHEL8_1_PACKAGE
REAL_RHEL8_ERRATA_CVES = ['CVE-2021-27023' , 'CVE-2021-27025']
FAKE_1_YUM_REPOS_COUNT = 32
FAKE_3_YUM_REPOS_COUNT = 78
FAKE_9_YUM_SECURITY_ERRATUM = [
Expand Down
90 changes: 44 additions & 46 deletions robottelo/host_helpers/api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,9 @@ def register_host_and_needed_setup(
environment,
content_view,
enable_repos=False,
unregister=False,
rex_key=False,
force=False,
loc=None,
):
"""
* Helper will setup desired entities to host content. Then, register the
Expand All @@ -734,50 +734,47 @@ def register_host_and_needed_setup(
* The host will be registered to location: None (visible to all locations).
param satellite: sat instance where needed entities exist.
param client: instance of a rhel contenthost to register.
param unregister (bool): unregister the host at the start, in case it is already registered
default: False, a reused fixture contenthost may fail if registered prior,
unregister before calling, or ensure it is a new host.
param enable_repos (bool): enable all available repos on the client, after registration?
default: False, be sure to enable any repo(s) for client, after calling this method.
param rex_key (bool): add a Remote Execution Key to client for satellite?
default: False
param force (bool): force registration of the client to bypass?
default: False, a reused fixture contenthost will fail if already registered.
param loc: pass a location object to limit host visibility.
default None, client is available to all locations.
type: Below arguments can be any of the following:
* (int): pass id of entity to be read
* (str): pass name of entity to be searched
* (entity): pass an entity instance
param organization: pass an Organization instance, name, or id to use.
param activation_key: pass an Activation-Key instance, name, or id.
param environment: pass a Lifecycle-Environment instance, name, or id.
for example: can pass string name 'Library'.
example: can pass string name 'Library'.
param content_view: pass a Content-View instance, name, or id.
for example: can pass string name 'Default Organization View'.
example: can pass string name 'Default Organization View'.
Notes:
1. Will fail if passed entities do not exist in the same organization and satellite.
2. Use param `enable_repos`, to try enabling any repositories on client,
that were added to content-view prior. But if there are no
repositories added/made available, this will fail.
3. The Default Organization View cannot be published, promoted, edited, or deleted.
3. The 'Default Organization View' cannot be published, promoted, edited, or deleted.
but you can register the client to it.
Steps:
1. get needed entities from arguments, id, name, or instance. Read all as instance.
2. publish the content-view if no versions exist, or needs_publish.
3. promote the newest content-view-version if not in environment already. Skip for 'Library'.
4. assign environment and content-view to the activation-key, if not associated.
5. Register the host, using the activation-key associated with content.
6. Add a rex_key to the client if desired, enable all available repositories if desired.
5. If desired, enable all repositories from content-view, for activation-key.
6. Register the host, using the activation-key associated with content.
7. Add a rex_key to the client if desired
return: if Succeeded: dict containing the updated entities:
{
Expand Down Expand Up @@ -808,17 +805,6 @@ def register_host_and_needed_setup(
'Argument "client" must be instance, with attribute "hostname".'
)
return method_error
if not force and client.subscribed:
if unregister:
client.unregister()
else:
method_error['message'] = (
'Passed client is already registered.'
' Unregister the host prior to calling this method.'
' Or, pass unregister=True, to unregister within this method first,'
' Or, pass force=True, to bypass during registration.'
)
return method_error
# for entity arguments matched to above params:
# fetch entity instance on satellite,
# from given id or name, else read passed argument as an instance.
Expand All @@ -830,18 +816,15 @@ def register_host_and_needed_setup(
param = getattr(self._satellite.api, entity)(id=value).read()
# passed str, search for entity by name
elif isinstance(value, str):
# search for org name itself, will be just scoped to satellite
search_query = f'name="{value}"'
if entity == 'Organization':
search_query = f'name="{value}"'
# search for org name itself, will be just scoped to satellite
# equivalent: _satellite_.api.{KEY}().search(...name={VALUE})
result = getattr(self._satellite.api, entity)().search(
query={'search': search_query}
)
# search of non-org entity by name, will be scoped to organization
else:
search_query = (
f"name='{value}' and organization_id={entities['Organization'].id}"
)
# search of non-org entity by name, will be scoped to organization
result = getattr(self._satellite.api, entity)(
organization=entities['Organization']
).search(query={'search': search_query})
Expand Down Expand Up @@ -909,13 +892,41 @@ def register_host_and_needed_setup(
entities['ActivationKey'].content_view = entities['ContentView']
entities['ActivationKey'].update(['content_view'])

# register with now setup entities, using ak
entities = {k: v.read() for k, v in entities.items()}
if enable_repos:
repositories = entities['ContentView'].repository
if len(repositories) < 1:
method_error['message'] = (
f' Cannot enable repositories for clients activation-key: {entities["ActivationKey"].name}'
f' There are no repositories added to the content-view: {entities["ContentView"].name}.'
)
return method_error
for repo in repositories:
# fetch content-label for any repo in cv
repo_content_label = self._satellite.cli.Repository.info(
{
'name': repo.read().name,
'organization-id': entities['Organization'].id,
'product': repo.read().product.read().name,
}
)['content-label']
# override the repository to enabled
self._satellite.cli.ActivationKey.content_override(
{
'content-label': repo_content_label,
'id': entities['ActivationKey'].id,
'organization-id': entities['Organization'].id,
'value': int(True),
}
)
repo.read().sync()

# register with now setup entities, using ak
result = client.register(
activation_keys=entities['ActivationKey'].name,
target=self._satellite,
org=entities['Organization'],
loc=None,
loc=loc,
force=force,
)
if result.status != 0:
Expand All @@ -933,19 +944,6 @@ def register_host_and_needed_setup(
if rex_key:
client.add_rex_key(self._satellite)

# enable all repositories available to client, using subscription manager,
# ie: any repos added to content-view prior to calling this method.
# note: this will fail if no repos are available to client from CV/AK
if enable_repos:
output = client.execute(r'subscription-manager repos --enable \*')
if output.status != 0:
method_error['client'] = client
method_error['message'] = (
'Failed to enable all available repositories using subscription-manager.'
f' For client: {client.hostname}.\n{output.stdout}'
)
return method_error

entities = {k: v.read() for k, v in entities.items()}
return ( # dict containing registered host client, and updated entities
{
Expand Down
Loading

0 comments on commit dccc72f

Please sign in to comment.