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 21, 2024
1 parent 7c79799 commit 6b1257c
Show file tree
Hide file tree
Showing 3 changed files with 540 additions and 520 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
75 changes: 36 additions & 39 deletions robottelo/host_helpers/api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ def register_host_and_needed_setup(
environment,
content_view,
enable_repos=False,
unregister=False,
rex_key=False,
force=False,
):
Expand All @@ -734,18 +733,14 @@ 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.
Expand Down Expand Up @@ -776,8 +771,9 @@ def register_host_and_needed_setup(
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 +804,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 +815,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,8 +891,36 @@ 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,
Expand All @@ -933,19 +943,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 6b1257c

Please sign in to comment.