Skip to content

Commit

Permalink
added properties for hostgroup (#1316)
Browse files Browse the repository at this point in the history
* added properties for hostgroup

* updated airgun entities and views for hostgroup and how_new
  • Loading branch information
amolpati30 authored Jun 4, 2024
1 parent 2a04ce6 commit 23f05ee
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
66 changes: 66 additions & 0 deletions airgun/entities/host_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@
ParameterDeleteDialog,
RemediationView,
)
from airgun.views.hostgroup import HostGroupEditView
from airgun.views.job_invocation import JobInvocationCreateView

global available_param_types
available_param_types = ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json']


def navigate_to_edit_view(func):
def _decorator(self, entity_name=None, role_name=None):
view = self.navigate_to(self, 'NewDetails', entity_name=entity_name, role=role_name)
view.wait_displayed()
self.browser.plugin.ensure_page_safe()
view.overview.details.edit.click()
self.browser.switch_to_window(self.browser.window_handles[1])
host_group_view = HostGroupEditView(self.browser)
func(self, entity_name, role_name)
host_group_view.ansible_roles.submit.click()
self.browser.switch_to_window(self.browser.window_handles[0])
self.browser.close_window(self.browser.window_handles[1])

return _decorator


class NewHostEntity(HostEntity):
def create(self, values):
"""Create new host entity"""
Expand All @@ -47,6 +64,55 @@ def get_details(self, entity_name, widget_names=None):
view.read(widget_names=widget_names)
return view.read(widget_names=widget_names)

@navigate_to_edit_view
def assign_role_to_hostgroup(self, entity_name, role_name):
"""Assign a single Ansible role from the host group based on user input
Args:
entity_name: Name of the host
role_name: Name of the ansible role
"""
host_group_view = HostGroupEditView(self.browser)
host_group_view.ansible_roles.more_item.click()
host_group_view.ansible_roles.select_pages.click()
role_list = self.browser.elements(host_group_view.ansible_roles.available_role, parent=self)
for single_role in role_list[1:]:
if single_role.text.split(". ")[1] == role_name:
single_role.click()

@navigate_to_edit_view
def remove_hostgroup_role(self, entity_name, role_name):
"""Remove a single Ansible role from the host group based on user input
Args:
entity_name: Name of the host
role_name: Name of the ansible role
"""
host_group_view = HostGroupEditView(self.browser)
role_list = self.browser.elements(host_group_view.ansible_roles.assigned_role, parent=self)
for single_role in role_list[1:]:
if single_role.text.split(". ")[1] == role_name:
single_role.click()

@navigate_to_edit_view
def assign_all_role_to_hostgroup(self, entity_name, role_name=None):
"""Assign all Ansible roles from the host group"""
host_group_view = HostGroupEditView(self.browser)
host_group_view.ansible_roles.more_item.click()
host_group_view.ansible_roles.select_pages.click()
role_list = self.browser.elements(host_group_view.ansible_roles.available_role, parent=self)
for single_role in role_list:
single_role.click()

@navigate_to_edit_view
def remove_all_role_from_hostgroup(self, entity_name, role_name=None):
"""Remove all Ansible roles from the host group"""
host_group_view = HostGroupEditView(self.browser)
host_group_view.ansible_roles.click()
role_list = self.browser.elements(host_group_view.ansible_roles.assigned_role, parent=self)
for single_role in role_list:
single_role.click()

def get_host_statuses(self, entity_name):
"""Read host statuses from Host Details page
Expand Down
9 changes: 9 additions & 0 deletions airgun/entities/hostgroup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from navmazing import NavigateToSibling
from wait_for import wait_for
from widgetastic.exceptions import NoSuchElementException

from airgun.entities.base import BaseEntity
Expand Down Expand Up @@ -65,6 +66,14 @@ def update(self, entity_name, values):
view.flash.assert_no_error()
view.flash.dismiss()

def total_no_of_assigned_role(self, entity_name):
"""Count of assigned role to the host group"""
view = self.navigate_to(self, 'Edit', entity_name=entity_name)
view.ansible_roles.click()
role_list = self.browser.elements(view.ansible_roles.assigned_ansible_role, parent=self)
wait_for(lambda: int(role_list[-1].text.split(". ")[0]), timeout=30)
return int(role_list[-1].text.split(". ")[0])


@navigator.register(HostGroupEntity, 'All')
class ShowAllHostGroups(NavigateStep):
Expand Down
2 changes: 1 addition & 1 deletion airgun/views/host_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class overview(Tab):
@View.nested
class details(Card):
ROOT = './/article[.//div[text()="Details"]]'

edit = Text('.//div[@class="pf-c-description-list__group"]/dd//div[2]')
details = HostDetailsCard()

power_operations = OUIAButton('power-status-dropdown-toggle')
Expand Down
11 changes: 11 additions & 0 deletions airgun/views/hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ def is_displayed(self):
and self.breadcrumb.locations[0] == 'Host Groups'
and self.breadcrumb.read().startswith('Edit ')
)

@View.nested
class ansible_roles(SatTab):
TAB_NAME = 'Ansible Roles'
more_item = Text('//span[@class="pf-c-options-menu__toggle-button-icon"]')
select_pages = Text('//ul[@class="pf-c-options-menu__menu"]/li[6]/button')
available_role = '//div[@class="available-roles-container col-sm-6"]/div[2]/div'
assigned_role = '//div[@class="assigned-roles-container col-sm-6"]/div[2]/div'
assigned_ansible_role = '//div[@class="assigned-roles-container col-sm-6"]/div[2]/div'
no_of_available_role = Text('//span[@class="pf-c-options-menu__toggle-text"]//b[2]')
submit = Text('//input[@name="commit"]')

0 comments on commit 23f05ee

Please sign in to comment.