Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed May 18, 2024
1 parent 45cff78 commit d9710b9
Showing 1 changed file with 79 additions and 49 deletions.
128 changes: 79 additions & 49 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _publish_and_wait(sat, org, cv, timeout=60):
"""Synchrnous publish of a new version of content-view to organization,
wait for task completion.
return: the polled task, if success or failed.
return: the polled task, success or fail.
"""
task_id = sat.api.ContentView(id=cv.id).publish({'id': cv.id, 'organization': org})['id']
assert task_id, f'No task was invoked to publish the Content-View: {cv.id}.'
Expand All @@ -216,16 +216,6 @@ def _publish_and_wait(sat, org, cv, timeout=60):
return sat.api.ForemanTask(id=task_id).poll(must_succeed=False)


@pytest.fixture
def errata_host_ak(module_target_sat, module_sca_manifest_org, module_lce):
"""New activation key created in module SCA org and module lce"""
ak = module_target_sat.api.ActivationKey(
organization=module_sca_manifest_org,
environment=module_lce,
).create()
return ak.read()


@pytest.fixture
def registered_contenthost(
module_sca_manifest_org,
Expand Down Expand Up @@ -330,7 +320,7 @@ def registered_contenthost(
# found index (repo) with matching name, grab sub-manager repo-id:
assert repo.name in repo_ids_names['names']
sub_man_repo_id = repo_ids_names['ids'][repo_ids_names['names'].index(repo.name)]
# repo present, and can be enabled without error
# repo can be enabled by id without error
enable_repo = client.execute(f'subscription-manager repos --enable {sub_man_repo_id}')
assert enable_repo.status == 0, (
f'Failed to enable a repository with subscription-manager, on client: {client.hostname}.'
Expand All @@ -357,6 +347,7 @@ def cleanup():
@pytest.mark.e2e
@pytest.mark.tier3
@pytest.mark.rhel_ver_match('[^6]')
@pytest.mark.parametrize('registered_contenthost', [[CUSTOM_REPO_URL]], indirect=True)
@pytest.mark.no_containers
def test_end_to_end(
registered_contenthost,
Expand All @@ -366,7 +357,7 @@ def test_end_to_end(
module_cv,
session,
):
"""Create all entities required for errata, set up applicable host,
"""Create all entities required for errata, register an applicable host,
read errata details and apply it to host.
:id: a26182fc-f31a-493f-b094-3f5f8d2ece47
Expand Down Expand Up @@ -408,21 +399,7 @@ def test_end_to_end(
client = registered_contenthost
hostname = client.hostname
assert client.subscribed
# create new custom repo, sync, add to content view
custom_repo = module_target_sat.api.Repository(
url=CUSTOM_REPO_URL, product=module_product
).create()
custom_repo.sync()
module_cv.repository = [custom_repo]
module_cv.update(['repository'])
# publish new version with the newly added content, promote.
# once promoted, the new version with content
# will be available to host.
module_cv.read().publish()
module_cv = module_cv.read()
module_cv.version.sort(key=lambda version: version.id)
content_view_version = module_cv.version[-1].read()
content_view_version.promote(data={'environment_ids': module_lce.id})
custom_repo = module_cv.read().repository[0].read()
# nothing applicable to start
result = client.execute('subscription-manager repos')
assert (
Expand Down Expand Up @@ -460,9 +437,9 @@ def test_end_to_end(
# BZ 2265095: Check all columns in table of applicable host:
# from ContentTypes > Errata > Details > Content Hosts tab
assert results[0]['Name'] == hostname
#assert str(client.deploy_rhel_version) in results[0]['OS']
#assert results[0]['Environment'] == module_lce.name
#assert results[0]['Content View'] == module_cv.name
# assert str(client.deploy_rhel_version) in results[0]['OS']
# assert results[0]['Environment'] == module_lce.name
# assert results[0]['Content View'] == module_cv.name
# Check errata details
errata = session.errata.read(CUSTOM_REPO_ERRATA_ID)
assert errata['repositories']['table'], (
Expand Down Expand Up @@ -573,12 +550,12 @@ def test_end_to_end(
@pytest.mark.parametrize('registered_contenthost', [[CUSTOM_REPO_3_URL]], indirect=True)
@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url')
def test_host_content_errata_tab_pagination(
session,
module_target_sat,
registered_contenthost,
module_sca_manifest_org,
registered_contenthost,
module_target_sat,
module_lce,
module_cv,
session,
):
"""
# Test per-page pagination for BZ#1662254
Expand Down Expand Up @@ -621,7 +598,7 @@ def test_host_content_errata_tab_pagination(
# custom_repo was created & added to cv, in registered_contenthost fixture
# search for the instance
custom_repo = [repo for repo in all_repos if repo.url == CUSTOM_REPO_3_URL]
assert len(custom_repo) == 1
assert len(custom_repo) > 0
custom_repo = custom_repo[0].read()
custom_repo.sync()
# Set up rh_repo
Expand Down Expand Up @@ -738,7 +715,7 @@ def test_host_content_errata_tab_pagination(
item_count = pf4_pagination.total_items
assert item_count == _prior_app_count - 1

# Install all available from errata tab, we pass no search filter,
# Install All available from errata tab, we pass no search filter,
# so that all errata are selected, on all pages.
session.host_new.apply_erratas(_chost_name)
# find host's errata install job non-pending, timeout is 120s
Expand Down Expand Up @@ -803,12 +780,12 @@ def test_host_content_errata_tab_pagination(
@pytest.mark.tier2
@pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url')
def test_positive_list(
function_sca_manifest_org,
module_sca_manifest_org,
errata_host_ak,
function_org,
function_lce,
target_sat,
module_lce,
target_sat,
module_ak,
module_cv,
session,
):
Expand All @@ -828,15 +805,14 @@ def test_positive_list(
:customerscenario: true
"""
_org_module = module_sca_manifest_org
_org_function = function_org
module_cv = module_cv.read() # for module sca org
_org_function = function_sca_manifest_org
# create and sync repository, for module org's errata
target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': CUSTOM_REPO_URL,
'organization-id': _org_module.id,
'lifecycle-environment-id': module_lce.id,
'activationkey-id': errata_host_ak.id,
'activationkey-id': module_ak.id,
'content-view-id': module_cv.id,
},
)
Expand Down Expand Up @@ -907,7 +883,9 @@ def test_positive_list_permission(
)
rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read()
rh_repo.sync()
custom_repo = module_target_sat.api.Repository(url=CUSTOM_REPO_URL, product=function_product).create()
custom_repo = module_target_sat.api.Repository(
url=CUSTOM_REPO_URL, product=function_product
).create()
custom_repo.sync()
# create role with access only to 'RHEL8' RedHat product
role = module_target_sat.api.Role().create()
Expand Down Expand Up @@ -972,15 +950,20 @@ def test_positive_apply_for_all_hosts(
:expectedresults: Check that the erratum is applied in all the content
hosts.
"""
num_hosts = 4
distro = 'rhel9'
# one custom repo on satellite, for all hosts to use
custom_repo = target_sat.api.Repository(url=CUSTOM_REPO_URL, product=module_product).create()
custom_repo.sync()
module_cv.repository = [custom_repo]
module_cv.update(['repository'])
with Broker(
nick='rhel9', workflow='deploy-rhel', host_class=ContentHost, _count=4,
nick=distro,
workflow='deploy-rhel',
host_class=ContentHost,
_count=num_hosts,
) as hosts:
if not isinstance(hosts, list) or len(hosts) != 4:
if not isinstance(hosts, list) or len(hosts) != num_hosts:
pytest.fail('Failed to provision the expected number of hosts.')
for client in hosts:
# setup/register all hosts to same ak, content-view, and the one custom repo
Expand All @@ -995,22 +978,38 @@ def test_positive_apply_for_all_hosts(
assert setup['result'] != 'error', f'{setup["message"]}'
assert (client := setup['client'])
assert client.subscribed
assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0
pkgs = ' '.join(FAKE_9_YUM_OUTDATED_PACKAGES)
assert client.execute(f'yum install -y {pkgs}').status == 0
assert client.execute('subscription-manager repos').status == 0

with session:
session.location.select(loc_name=DEFAULT_LOC)
# for first errata, install in each chost and check, one at a time.
# from Legacy Chost UI > details > Errata tab
for client in hosts:
status = session.contenthost.install_errata(
client.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex'
)
assert status['overview']['job_status'] == 'Success'
assert status['overview']['job_status_progress'] == '100%'
# check updated package in chost details
assert client.execute('subscription-manager repos').status == 0
packages_rows = session.contenthost.search_package(
client.hostname, FAKE_2_CUSTOM_PACKAGE
)
assert packages_rows[0]['Installed Package'] == FAKE_2_CUSTOM_PACKAGE

# for second errata, apply to all chosts at once
# from Content > Errata > info > ContentHosts tab
errata_id = settings.repos.yum_9.errata[4] # RHBA-2012:1030
session.errata.install(
entity_name=errata_id,
host_names="All",
)
# bulk action task for expected hosts
# Actions::RemoteExecution::RunHostsJob
# check each task's status, and each chost's package version


@pytest.mark.tier2
@pytest.mark.upgrade
Expand Down Expand Up @@ -1267,6 +1266,7 @@ def test_positive_host_content_library(

assert client.applicable_errata_count == 0
assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0
assert client.execute('subscription-manager repos').status == 0
assert client.applicable_errata_count == 1
assert client.applicable_package_count == 1

Expand Down Expand Up @@ -1587,12 +1587,14 @@ def test_positive_filtered_errata_status_installable_param(
"""
client = registered_contenthost
assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0
assert client.execute('subscription-manager repos').status == 0
# Adding content view filter and content view filter rule to exclude errata,
# for the installed package above.
cv_filter = target_sat.api.ErratumContentViewFilter(
content_view=module_cv, inclusion=False
).create()
module_cv = module_cv.read()
module_cv.version.sort(key=lambda version: version.id)
errata = target_sat.api.Errata(content_view_version=module_cv.version[-1]).search(
query={'search': f'errata_id="{CUSTOM_REPO_ERRATA_ID}"'}
)[0]
Expand Down Expand Up @@ -1644,12 +1646,12 @@ def test_positive_filtered_errata_status_installable_param(

@pytest.mark.tier3
def test_content_host_errata_search_commands(
session,
target_sat,
module_product,
target_sat,
module_org,
module_ak,
module_cv,
session,
):
"""View a list of affected content hosts for security (RHSA) and bugfix (RHBA) errata,
filtered with errata status and applicable flags. Applicability is calculated using the
Expand Down Expand Up @@ -1677,7 +1679,9 @@ def test_content_host_errata_search_commands(
:BZ: 1707335
"""
yum_9_repo = target_sat.api.Repository(url=CUSTOM_REPO_URL, product=module_product).create()
yum_6_repo = target_sat.api.Repository(url=settings.repos.yum_6.url, product=module_product).create()
yum_6_repo = target_sat.api.Repository(
url=settings.repos.yum_6.url, product=module_product
).create()
yum_9_repo.sync()
yum_6_repo.sync()
module_cv.repository = [yum_6_repo, yum_9_repo]
Expand All @@ -1699,8 +1703,10 @@ def test_content_host_errata_search_commands(
assert client.subscribed
# Install pkg walrus-0.71-1.noarch to create need for RHSA on client 1
assert clients[0].execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0
assert clients[0].execute('subscription-manager repos').status == 0
# Install pkg kangaroo-0.1-1.noarch to create need for RHBA on client 2
assert clients[1].execute(f'yum install -y {FAKE_4_CUSTOM_PACKAGE}').status == 0
assert clients[1].execute('subscription-manager repos').status == 0

with session:
session.location.select(loc_name=DEFAULT_LOC)
Expand Down Expand Up @@ -1744,3 +1750,27 @@ def test_content_host_errata_search_commands(
)
result = [item['Name'] for item in result]
assert clients[1].hostname in result


def test_positive_add_content_to_empty_host():
"""Using a registered host with no synced content and no available repositories,
add some new repositories with content, sync and enable them.
find and install some of the newly synced content on the host.
Setup:
1. Register a host to no content and no available repositories.
2. Add new repositories to the activation key, override enabled.
3. Add another new repo to the content-view, publish and promote.
Steps:
1. Sync the two repositories, enable all repos on host client.
2. Find the newly added content from both repos synced to the host.
3. install some outdated packages, try to apply some errata.
Expected Results:
1. We can enable the new repositories for host through activation-key,
or content-view-version, sync and they are reported by subscription-manager.
2. We can see the newly synced content on the previously empty host.
3. We can install packages, and install any applicable erratum.
"""

0 comments on commit d9710b9

Please sign in to comment.