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 16, 2024
1 parent 42d1e96 commit 0b7ee6f
Show file tree
Hide file tree
Showing 3 changed files with 470 additions and 385 deletions.
28 changes: 5 additions & 23 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 @@ -735,17 +734,15 @@ 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 client: instance of a rhel contenthost to register.
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 @@ -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 @@ -945,7 +928,6 @@ def register_host_and_needed_setup(
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
76 changes: 76 additions & 0 deletions tests/foreman/api/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import re
from time import time

from broker import Broker
from fauxfactory import gen_string
Expand Down Expand Up @@ -341,6 +342,81 @@ def test_positive_export_report():
"""


@pytest.mark.tier2
@pytest.mark.rhel_ver_match('[^6]')
@pytest.mark.no_containers
def test_positive_applied_errata_by_search(
function_org, function_lce, rhel_contenthost, target_sat
):
"""Generate an Applied Errata report
:id: 0f7d2772-47a4-4215-b555-dd8ee675372f
:setup: A Host with some applied errata.
:steps:
1. Generate an Applied Errata report
:expectedresults: A report is generated with all applied errata listed
:CaseImportance: Medium
"""
activation_key = target_sat.api.ActivationKey(
environment=function_lce, organization=function_org
).create()
cv = target_sat.api.ContentView(organization=function_org).create()
ERRATUM_ID = str(settings.repos.yum_6.errata[2])
target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': settings.repos.yum_9.url,
'organization-id': function_org.id,
'content-view-id': cv.id,
'lifecycle-environment-id': function_lce.id,
'activationkey-id': activation_key.id,
}
)
errata_name = (
target_sat.api.Errata()
.search(query={'search': f'errata_id="{ERRATUM_ID}"'})[0]
.read()
.description
)
result = rhel_contenthost.register(function_org, None, activation_key.name, target_sat)
assert f'The registered system name is: {rhel_contenthost.hostname}' in result.stdout
assert rhel_contenthost.subscribed
epoch_timestamp = int(time() - 1)
rhel_contenthost.execute(r'subscription-manager repos --enable \*')
assert rhel_contenthost.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0
assert rhel_contenthost.execute(f'rpm -q {FAKE_1_CUSTOM_PACKAGE}').status == 0
rhel_contenthost.execute('subscription-manager repos')
task_id = target_sat.api.JobInvocation().run(
data={
'feature': 'katello_errata_install_by_search',
'inputs': {'Errata search query': errata_name},
'targeting_type': 'static_query',
'search_query': f'name = {rhel_contenthost.hostname}',
'organization_id': function_org.id,
},
)['id']
target_sat.wait_for_tasks(
search_query=(f'label = Actions::RemoteExecution::RunHostsJob and id = {task_id}'),
search_rate=15,
)
rt = (
target_sat.api.ReportTemplate()
.search(query={'search': 'name="Host - Applied Errata"'})[0]
.read()
)
res = rt.generate(
data={
'organization_id': function_org.id,
'report_format': 'json',
'input_values': {
'Filter Errata Type': 'all',
'Include Last Reboot': 'no',
'Status': 'all',
},
}
)
assert res[0]['erratum_id'] == ERRATUM_ID
assert res[0]['issued']


@pytest.mark.tier2
@pytest.mark.stubbed
def test_positive_generate_report_sanitized():
Expand Down
Loading

0 comments on commit 0b7ee6f

Please sign in to comment.