From b37d1626699561060a511ba835b429d1a4e1282d Mon Sep 17 00:00:00 2001 From: Samuel Bible Date: Wed, 21 Aug 2024 09:27:48 -0500 Subject: [PATCH] Support for Bulk Hostgroup actions in All Hosts (#1523) --- airgun/entities/all_hosts.py | 12 ++++++++++++ airgun/views/all_hosts.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/airgun/entities/all_hosts.py b/airgun/entities/all_hosts.py index 528dc98d4..7c71a4852 100644 --- a/airgun/entities/all_hosts.py +++ b/airgun/entities/all_hosts.py @@ -9,6 +9,7 @@ BuildManagementDialog, BulkHostDeleteDialog, HostDeleteDialog, + HostgroupDialog, ManageCVEModal, ManagePackagesModal, ) @@ -83,6 +84,17 @@ def build_management(self, reboot=False, rebuild=False): self.browser.wait_for_element(view.alert_message, exception=False) return view.alert_message.read() + def change_hostgroup(self, name): + """Change hostgroup of all hosts to chosen hostgroup""" + view = self.navigate_to(self, 'All') + self.browser.plugin.ensure_page_safe(timeout='5s') + view.wait_displayed() + view.select_all.fill(True) + view.bulk_actions.item_select('Change host group') + view = HostgroupDialog(self.browser) + view.hostgroup_dropdown.item_select(name) + view.save_button.click() + def manage_cve(self, lce=None, cv=None): """Bulk reassign Content View Environments through the All Hosts page args: diff --git a/airgun/views/all_hosts.py b/airgun/views/all_hosts.py index 348be6dbc..0904c7ab8 100644 --- a/airgun/views/all_hosts.py +++ b/airgun/views/all_hosts.py @@ -23,13 +23,23 @@ from airgun.widgets import ItemsList, SearchInput +class AllHostsSelect(Select): + BUTTON_LOCATOR = ".//button[@aria-label='Options menu']" + ITEMS_LOCATOR = ".//ul[contains(@class, 'pf-c-select__menu')]/li[contains(@class, 'pf-c-select__menu-wrapper')]" + ITEM_LOCATOR = ( + '//*[contains(@class, "pf-c-select__menu-item") and contains(normalize-space(.), {})]' + ) + SELECTED_ITEM_LOCATOR = ".//span[contains(@class, 'ins-c-conditional-filter')]" + TEXT_LOCATOR = ".//div[contains(@class, 'pf-c-select') and child::button]" + + class AllHostsMenu(Menu): IS_ALWAYS_OPEN = False BUTTON_LOCATOR = ".//button[contains(@class, 'pf-c-menu-toggle')]" ROOT = f"{BUTTON_LOCATOR}/.." -class AllHostsSelect(Select): +class CVESelect(Select): BUTTON_LOCATOR = ".//button[@aria-label='Options menu']" ITEMS_LOCATOR = ".//ul[contains(@class, 'pf-c-select__menu')]/li" ITEM_LOCATOR = ( @@ -126,6 +136,24 @@ def is_displayed(self): return self.browser.wait_for_element(self.title, exception=False) is not None +class HostgroupDialog(View): + """Dialog for bulk changing Hosts' assigned hostgroup""" + + ROOT = './/div[@id="bulk-reassign-hg-modal"]' + + title = Text("//span[normalize-space(.)='Change host group']") + hostgroup_dropdown = AllHostsSelect( + locator='.//div[contains(@class, "pf-c-select") and @data-ouia-component-id="select-host-group"]' + ) + + save_button = Button(locator='//button[normalize-space(.)="Save"]') + cancel_button = Button(locator='//button[normalize-space(.)="Cancel"]') + + @property + def is_displayed(self): + return self.browser.wait_for_element(self.title, exception=False) is not None + + class AllHostsCheckboxTreeView(PF4CheckboxTreeView): """Small tweaks to work with All Hosts""" @@ -162,7 +190,7 @@ class ManageCVEModal(Modal): title = Text("//span[normalize-space(.)='Edit content view environments']") save_btn = Button(locator='//button[normalize-space(.)="Save"]') cancel_btn = Button(locator='//button[normalize-space(.)="Cancel"]') - content_source_select = AllHostsSelect() + content_source_select = CVESelect() lce_selector = ParametrizedView.nested(PF4LCESelectorGroup) @property