Skip to content

Commit

Permalink
wait_for() reload of errata tab, handle pagination exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Jan 23, 2024
1 parent 3b656be commit dea198c
Showing 1 changed file with 76 additions and 55 deletions.
131 changes: 76 additions & 55 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from fauxfactory import gen_string
from manifester import Manifester
import pytest
from selenium.common.exceptions import NoSuchElementException
from wait_for import wait_for

from robottelo.config import settings
Expand Down Expand Up @@ -498,8 +499,8 @@ def test_host_content_errata_tab_pagination(
# Test apply by REX using Select All for BZ#1846670
:setup:
1. rhel8 registered contentehost with custom repos enabled
2. enable and sync rh repository
1. rhel8 registered contenthost with custom repos enabled.
2. enable and sync rh repository.
3. add rh repo to cv for registered host and publish/promote.
:id: 6363eda7-a162-4a4a-b70f-75decbd8202e
Expand All @@ -510,22 +511,20 @@ def test_host_content_errata_tab_pagination(
3. Assert total_pages > 1
4. Change per-page setting to 50
5. Assert table has more than 20 errata
6. Select one avaliable errata and install it
7. Assert total items in table is one less
8. Assert per page count and total pages has not changed
9. Use the selection box on the left to select all on the page.
The following is displayed at the top of the table:
All 20 items on this page, max of 50, are selected. Select all YYY.
10. Click the "Select all" text and assert more than 20 results are selected.
11. Click the drop down arrow to the right of "Apply Selected", and select
"via remote execution"
12. Click Submit
13. Assert Errata are applied as expected
6. Change per-page setting to 5
7. Assert setting changed and more total-pages now
8. Select one available errata and install it
9. Assert total items in table is one less
10. Assert per page count and total pages has not changed
11. Use the selection box on the left to select all on this page and others.
All errata, from all pages, are selected. Select all YYY.
12. Click the drop down arrow to the right of "Apply All", click Submit.
13. Assert All Errata were applied, none are available
14. Assert no pagination on new host UI>content>errata
15. Raise `NoSuchElementException` when looking for a pagination element.
:expectedresults: More than page of errata can be selected and applied using REX while
changing per-page settings.
:expectedresults: More than just the current page of errata can be selected
and applied with changed per-page settings.
:customerscenario: true
Expand Down Expand Up @@ -565,8 +564,8 @@ def test_host_content_errata_tab_pagination(
module_cv,
module_lce,
)
assert registered_contenthost.subscribed
registered_contenthost.add_rex_key(satellite=module_target_sat)
assert registered_contenthost.subscribed
assert registered_contenthost.execute(r'subscription-manager repos --enable \*').status == 0
_chost_name = registered_contenthost.hostname
# Install all YUM 3 packages
Expand All @@ -583,24 +582,32 @@ def test_host_content_errata_tab_pagination(
assert pf4_pagination.current_per_page == 20
# assert total_pages > 1 with default page settings
assert pf4_pagination.total_pages > 1
# Change per-page setting to 50 and assert there is now only one page
assert pf4_pagination.current_page == 1
assert pf4_pagination.total_items == registered_contenthost.applicable_errata_count
# Change per-page setting to 50, and assert there is now only one page
pf4_pagination.set_per_page(50)
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
assert pf4_pagination.current_per_page == 50
assert pf4_pagination.current_page == 1
assert pf4_pagination.total_pages == 1
# assert at least the 28 errata from fake repo are present
assert pf4_pagination.total_items >= 28
_prior_app_count = pf4_pagination.total_items
# Change to a low per-page setting of 5
pf4_pagination.set_per_page(5)
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
assert pf4_pagination.current_per_page == 5
assert pf4_pagination.current_page == 1
assert pf4_pagination.total_pages > 1
_prior_pagination = pf4_pagination.read()

# Install one avaliable errata from UI with REX as default
# Install one available errata from UI with REX as default
errata_id = CUSTOM_REPO_3_ERRATA[1]
session.host_new.apply_erratas(_chost_name, f'errata_id = "{errata_id}"')
session.host_new.apply_erratas(_chost_name, f'errata_id="{errata_id}"')
# find host errata install job and status, timeout is 120s
# may take some time, wait for any not pending
status = module_target_sat.wait_for_tasks(
search_query=(
f'Remote action: Install errata on {_chost_name}' ' and result != pending'
),
search_query=(f'Remote action: Install errata on {_chost_name} and result != pending'),
search_rate=2,
max_tries=60,
)
Expand All @@ -612,7 +619,7 @@ def test_host_content_errata_tab_pagination(
# find bulk applicability task and status
status = module_target_sat.wait_for_tasks(
search_query=(
f'Bulk generate applicability for host {_chost_name}' ' and result != pending'
f'Bulk generate applicability for host {_chost_name} and result != pending'
),
search_rate=2,
max_tries=60,
Expand All @@ -622,35 +629,33 @@ def test_host_content_errata_tab_pagination(
assert task.result == 'success'
assert 'host_ids' in task.input
assert registered_contenthost.nailgun_host.id in task.input['host_ids']
# read pagination after installing one errata
# applicable errata is now one less
assert registered_contenthost.applicable_errata_count == _prior_app_count - 1
# wait for the tab to load with new pagination, with one less total items
# timeout 10s
# wait for the tab to load with updated pagination, timeout 20s.
# lambda: read is not the same as prior pagination read, and is also not empty {}.
_invalid_pagination = ({}, _prior_pagination)
wait_for(
lambda: session.host_new.get_errata_pagination(_chost_name).total_items
!= _prior_app_count,
timeout=10,
delay=1,
lambda: session.host_new.get_errata_pagination(_chost_name).read()
not in _invalid_pagination,
timeout=30,
delay=5,
)
# read on pagination should return empty from now on
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
assert not pf4_pagination.read()
# read updated pagination
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
# per_page and total_pages remained the same
assert pf4_pagination.current_per_page == 50
assert pf4_pagination.total_pages == 1
# assert total_items decreased by one
# assert per_page and total_pages remained the same
assert pf4_pagination.current_per_page == 5
assert pf4_pagination.current_page == 1
assert pf4_pagination.total_pages > 1
# total_items decreased by one
item_count = pf4_pagination.total_items
assert item_count == _prior_app_count - 1

# Install all avaliable errata from UI, we pass a blank ' ' search,
# so that all errata are displayed and selected
session.host_new.apply_erratas(_chost_name, ' ')
# 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 errata install job and status, timeout is 120s
status = module_target_sat.wait_for_tasks(
search_query=(
f'Remote action: Install errata on {_chost_name}' ' and result != pending'
),
search_query=(f'Remote action: Install errata on {_chost_name} and result != pending'),
search_rate=2,
max_tries=60,
)
Expand All @@ -662,7 +667,7 @@ def test_host_content_errata_tab_pagination(
# find bulk applicability task and status
status = module_target_sat.wait_for_tasks(
search_query=(
f'Bulk generate applicability for host {_chost_name}' ' and result != pending'
f'Bulk generate applicability for host {_chost_name} and result != pending'
),
search_rate=2,
max_tries=60,
Expand All @@ -672,18 +677,34 @@ def test_host_content_errata_tab_pagination(
assert task.result == 'success'
assert 'host_ids' in task.input
assert registered_contenthost.nailgun_host.id in task.input['host_ids']

# check that there are no applicable errata left for Chost
assert registered_contenthost.applicable_errata_count == 0
# the errata table is not present when empty, it should not be paginated
# timeout is 10s, for tab loading with no pagination
wait_for(
lambda: session.host_new.get_errata_pagination(_chost_name).read() == {},
timeout=10,
delay=1,
)
# read on pagination should return empty from now on
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
assert not pf4_pagination.read()
# The errata table is not present when empty, it should not be paginated
# timeout is 20s, for tab loading with no pagination {}, on read.
_items = -1
_ex_raised = False
try:
wait_for(
lambda: session.host_new.get_errata_pagination(_chost_name).read() == {},
timeout=20,
delay=5,
)
except NoSuchElementException:
# pagination read raised exception, does not exist
_ex_raised = True
if not _ex_raised:
# pagination exists, reads empty {}, but we expect an
# exception when looking for a pagination element:
pf4_pagination = session.host_new.get_errata_pagination(_chost_name)
# exception trying to find element
with pytest.raises(NoSuchElementException):
_items = pf4_pagination.total_items
# nothing was found to update value
assert _items == -1
# would get failure at pytest.raises if no matching exception
_ex_raised = True
assert _ex_raised, 'Search for pagination did not raise expected `NoSuchElementException`.'


@pytest.mark.tier2
Expand Down

0 comments on commit dea198c

Please sign in to comment.