diff --git a/airgun/entities/host_new.py b/airgun/entities/host_new.py index f7b8267e6..67bfa2197 100644 --- a/airgun/entities/host_new.py +++ b/airgun/entities/host_new.py @@ -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""" @@ -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 diff --git a/airgun/entities/hostgroup.py b/airgun/entities/hostgroup.py index d3311b44b..72362890f 100644 --- a/airgun/entities/hostgroup.py +++ b/airgun/entities/hostgroup.py @@ -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 @@ -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): diff --git a/airgun/views/host_new.py b/airgun/views/host_new.py index 6a65c9cf5..50a43a20d 100644 --- a/airgun/views/host_new.py +++ b/airgun/views/host_new.py @@ -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') diff --git a/airgun/views/hostgroup.py b/airgun/views/hostgroup.py index 868deb4e2..f2125ff49 100644 --- a/airgun/views/hostgroup.py +++ b/airgun/views/hostgroup.py @@ -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"]')