Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed May 21, 2024
1 parent a64c358 commit 7c06a78
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 271 deletions.
49 changes: 32 additions & 17 deletions robottelo/host_helpers/api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,6 @@ 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 enable_repos (bool): enable all available repos on the client, after registration?
Expand Down Expand Up @@ -773,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 @@ -892,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 @@ -916,18 +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
76 changes: 0 additions & 76 deletions tests/foreman/api/test_reporttemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

import re
from time import time

from broker import Broker
from fauxfactory import gen_string
Expand Down Expand Up @@ -342,81 +341,6 @@ 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 7c06a78

Please sign in to comment.