From cf797ed6af92fd76301b35c2be1a3d56c8a3bdaa Mon Sep 17 00:00:00 2001 From: David Moore Date: Thu, 18 Jan 2024 12:49:05 -0500 Subject: [PATCH] wait_for() reload of errata tab, handle pagination exceptions --- tests/foreman/ui/test_errata.py | 125 +++++++++++++++++++------------- 1 file changed, 73 insertions(+), 52 deletions(-) diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index 6eecbebf625..5ed91dfa686 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -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 @@ -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 @@ -510,22 +511,21 @@ 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. + 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 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 + 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 are 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 @@ -565,8 +565,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 @@ -583,24 +583,31 @@ 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 + assert pf4_pagination.current_page == 1 # 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 back to a low per-page setting + 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, ) @@ -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, @@ -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=20, + delay=2, ) - # read on pagination should return empty from now on + # read updated pagination pf4_pagination = session.host_new.get_errata_pagination(_chost_name) - assert not pf4_pagination.read() - 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 + # Install all available from errata tab, we pass a blank ' ' search, + # 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, ) @@ -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, @@ -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=2, + ) + 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