Skip to content

Commit

Permalink
Support for Bulk Hostgroup actions in All Hosts (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
sambible authored Aug 21, 2024
1 parent a8368e7 commit b37d162
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 deletions airgun/entities/all_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BuildManagementDialog,
BulkHostDeleteDialog,
HostDeleteDialog,
HostgroupDialog,
ManageCVEModal,
ManagePackagesModal,
)
Expand Down Expand Up @@ -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:
Expand Down
32 changes: 30 additions & 2 deletions airgun/views/all_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b37d162

Please sign in to comment.