1212 AllHostsTableView ,
1313 BuildManagementDialog ,
1414 BulkHostDeleteDialog ,
15+ ChangeHostsOwnerModal ,
16+ ChangeLocationModal ,
17+ ChangeOrganizationModal ,
1518 DisassociateHostsModal ,
1619 HostDeleteDialog ,
1720 HostgroupDialog ,
@@ -49,10 +52,7 @@ def read_table(self):
4952
5053 def delete (self , host_name ):
5154 """Delete host through table dropdown"""
52- view = self .navigate_to (self , 'All' )
53- self .browser .plugin .ensure_page_safe (timeout = '5s' )
54- view .wait_displayed ()
55- view .search (host_name )
55+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names = host_name )
5656 view .table [0 ][2 ].widget .item_select ('Delete' )
5757 delete_modal = HostDeleteDialog (self .browser )
5858 if delete_modal .is_displayed :
@@ -67,10 +67,7 @@ def delete(self, host_name):
6767
6868 def bulk_delete_all (self ):
6969 """Delete multiple hosts through bulk action dropdown"""
70- view = self .navigate_to (self , 'All' )
71- self .browser .plugin .ensure_page_safe (timeout = '5s' )
72- view .wait_displayed ()
73- view .select_all .fill (True )
70+ view = self .all_hosts_navigate_and_select_hosts_helper (select_all_hosts = True )
7471 view .bulk_actions_kebab .click ()
7572 view .bulk_actions_menu .item_select ('Delete' )
7673 delete_modal = BulkHostDeleteDialog (self .browser )
@@ -84,10 +81,7 @@ def bulk_delete_all(self):
8481
8582 def build_management (self , reboot = False , rebuild = False ):
8683 """Build or rebuild hosts through build management popup"""
87- view = self .navigate_to (self , 'All' )
88- self .browser .plugin .ensure_page_safe (timeout = '5s' )
89- view .wait_displayed ()
90- view .select_all .fill (True )
84+ view = self .all_hosts_navigate_and_select_hosts_helper (select_all_hosts = True )
9185 view .bulk_actions_kebab .click ()
9286 view .bulk_actions_menu .item_select ('Build management' )
9387 build_management_modal = BuildManagementDialog (self .browser )
@@ -102,10 +96,7 @@ def build_management(self, reboot=False, rebuild=False):
10296
10397 def change_hostgroup (self , name ):
10498 """Change hostgroup of all hosts to chosen hostgroup"""
105- view = self .navigate_to (self , 'All' )
106- self .browser .plugin .ensure_page_safe (timeout = '5s' )
107- view .wait_displayed ()
108- view .select_all .fill (True )
99+ view = self .all_hosts_navigate_and_select_hosts_helper (select_all_hosts = True )
109100 view .bulk_actions .item_select ('Change host group' )
110101 view = HostgroupDialog (self .browser )
111102 view .hostgroup_dropdown .item_select (name )
@@ -203,9 +194,6 @@ def manage_packages(
203194 manage_by_customized_rex (bool): manage by customized rex flag
204195 """
205196
206- # Check validity of user input
207- if select_all_hosts and host_names :
208- raise ValueError ("Cannot select all and specify host names at the same time!" )
209197 if sum ([upgrade_packages , install_packages , remove_packages ]) != 1 :
210198 raise ValueError (
211199 "Only one of the options can be selected: upgrade_packages, install_packages, remove_packages!"
@@ -223,21 +211,7 @@ def manage_packages(
223211 "Exactly one of the options must be selected: packages_to_upgrade, packages_to_install, packages_to_remove!"
224212 )
225213
226- # Navigate to All Hosts
227- view = self .navigate_to (self , 'All' )
228- self .browser .plugin .ensure_page_safe (timeout = '5s' )
229- view .wait_displayed ()
230-
231- # Select all hosts from the table
232- if select_all_hosts :
233- view .select_all .fill (True )
234- # Select user-specified hosts
235- else :
236- if not isinstance (host_names , list ):
237- host_names = [host_names ]
238- for host_name in host_names :
239- view .search (host_name )
240- view .table [0 ][0 ].widget .fill (True )
214+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
241215
242216 # Open Manage Packages modal
243217 view .bulk_actions_kebab .click ()
@@ -345,10 +319,6 @@ def manage_errata(
345319 manage_by_customized_rex (bool): manage by customized rex flag
346320 """
347321
348- # Check validity of user input
349- if select_all_hosts and host_names :
350- raise ValueError ("Cannot select all and specify host names at the same time!" )
351-
352322 # if both erratas_to_apply_by_id and individual_search_queries are specified, raise an error
353323 if erratas_to_apply_by_id is not None and individual_search_queries is not None :
354324 raise ValueError (
@@ -359,21 +329,7 @@ def manage_errata(
359329 if erratas_to_apply_by_id is not None and not isinstance (erratas_to_apply_by_id , list ):
360330 erratas_to_apply_by_id = [erratas_to_apply_by_id ]
361331
362- # Navigate to All Hosts
363- view = self .navigate_to (self , 'All' )
364- self .browser .plugin .ensure_page_safe (timeout = '5s' )
365- view .wait_displayed ()
366-
367- # Select all hosts from the table
368- if select_all_hosts :
369- view .select_all .fill (True )
370- # Select user-specified hosts
371- else :
372- if not isinstance (host_names , list ):
373- host_names = [host_names ]
374- for host_name in host_names :
375- view .search (host_name )
376- view .table [0 ][0 ].widget .fill (True )
332+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
377333
378334 # Open Manage Erratas modal
379335 view .bulk_actions_kebab .click ()
@@ -429,10 +385,6 @@ def manage_repository_sets(
429385 individual_search_queries (list): list of string of search queries for each repo
430386 """
431387
432- # Check validity of user input
433- if select_all_hosts and host_names :
434- raise ValueError ('Cannot select all and specify host names at the same time!' )
435-
436388 # if both repository_names and individual_search_queries are specified, raise an error
437389 if repository_names is not None and individual_search_queries is not None :
438390 raise ValueError (
@@ -445,21 +397,7 @@ def manage_repository_sets(
445397 'Value of status_to_change should not be "No change", it will not allow to move next page'
446398 )
447399
448- # Navigate to All Hosts
449- view = self .navigate_to (self , 'All' )
450- self .browser .plugin .ensure_page_safe (timeout = '5s' )
451- view .wait_displayed ()
452-
453- # Select all hosts from the table
454- if select_all_hosts :
455- view .select_all .fill (True )
456- # Select user-specified hosts
457- else :
458- if not isinstance (host_names , list ):
459- host_names = [host_names ]
460- for host_name in host_names :
461- view .search (host_name )
462- view .table [0 ][0 ].widget .fill (True )
400+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
463401
464402 # Open Manage Repository sets modal
465403 view .bulk_actions_kebab .click ()
@@ -525,8 +463,31 @@ def disassociate_hosts(self, host_names, select_all_hosts=False):
525463 :param select_all_hosts: If True, all hosts will be selected for disassociation.
526464 """
527465
466+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
467+
468+ view .bulk_actions_kebab .click ()
469+ view .bulk_actions_menu .item_select ('Disassociate hosts' )
470+
471+ view = DisassociateHostsModal (self .browser )
472+ view .confirm_btn .click ()
473+
474+ def all_hosts_navigate_and_select_hosts_helper (self , host_names = None , select_all_hosts = False ):
475+ """
476+ Helper function to navigate to All Hosts and select specified hosts or all hosts.
477+ This function is used to avoid code duplication in methods that require host selection.
478+
479+ :param host_names: str with one host or list of hosts to select
480+ :param select_all_hosts: bool, if True, all hosts will be selected
481+
482+ :raises ValueError: if both or neither select_all_hosts and host_names are specified
483+
484+ :return: view (AllHostsTableView)
485+ """
486+
528487 if select_all_hosts and host_names :
529488 raise ValueError ('Cannot select all and specify host names at the same time!' )
489+ if not select_all_hosts and not host_names :
490+ raise ValueError ('Must specify either host_names or select_all_hosts.' )
530491
531492 view = self .navigate_to (self , 'All' )
532493 self .browser .plugin .ensure_page_safe (timeout = '5s' )
@@ -541,12 +502,96 @@ def disassociate_hosts(self, host_names, select_all_hosts=False):
541502 view .search (host_name )
542503 view .table [0 ][0 ].widget .fill (True )
543504
505+ return view
506+
507+ def change_hosts_owner (self , host_names , new_owner_name , select_all_hosts = False ):
508+ """
509+ Change owner of selected hosts.
510+
511+ :param host_names: str with one host or list of hosts to select
512+ :param new_owner_name: str with new owner name
513+ :param select_all_hosts: bool, if True, all hosts will be selected
514+ """
515+
516+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
517+
544518 view .bulk_actions_kebab .click ()
545- view .bulk_actions_menu .item_select ('Disassociate hosts ' )
519+ view .bulk_actions_menu .item_select ('Change owner ' )
546520
547- view = DisassociateHostsModal (self .browser )
521+ view = ChangeHostsOwnerModal (self .browser )
522+ view .owner_select .item_select (new_owner_name )
548523 view .confirm_btn .click ()
549524
525+ def change_associations_organization (
526+ self ,
527+ host_names = None ,
528+ new_organization = None ,
529+ select_all_hosts = False ,
530+ option = "Fix on mismatch" ,
531+ ):
532+ """
533+ Navigate to change organization modal after selecting number of hosts,
534+ select desired organization, select one of the options and apply changes.
535+
536+ :param host_names: str with one host or list of hosts to select
537+ :param new_organization: str organization name which will be selected
538+ :param select_all_hosts: bool select all hosts flag
539+ :param option: str options either 'Fix on mismatch' or 'Fail on mismatch'
540+ """
541+
542+ if new_organization is None :
543+ raise ValueError ('new_organization argument is None, it will not allow to Save changes' )
544+
545+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
546+
547+ view .bulk_actions_kebab .click ()
548+ self .browser .move_to_element (view .bulk_actions_menu .item_element ('Change associations' ))
549+ view .bulk_actions_change_associations_menu .item_select ('Organization' )
550+
551+ view = ChangeOrganizationModal (self .browser )
552+ view .organization_menu .item_select (new_organization )
553+
554+ if option == "Fix on mismatch" :
555+ view .organization_fix_on_mismatch .fill (True )
556+ view .save_button .click ()
557+
558+ elif option == "Fail on mismatch" :
559+ view .organization_fail_on_mismatch .fill (True )
560+ view .save_button .click ()
561+
562+ def change_associations_location (
563+ self , host_names = None , new_location = None , select_all_hosts = False , option = "Fix on mismatch"
564+ ):
565+ """
566+ Navigate to change location modal after selecting number of hosts,
567+ select desired location, select one of the options and apply changes.
568+
569+ :param host_names: str with one host or list of hosts to select
570+ :param new_location: str location name which will be selected
571+ :param select_all_hosts: select all hosts flag
572+ :param option: str options either 'Fix on mismatch' or 'Fail on mismatch'
573+ """
574+
575+ if new_location is None :
576+ raise ValueError ('new_location argument is None, it will not allow to Save changes' )
577+
578+ view = self .all_hosts_navigate_and_select_hosts_helper (host_names , select_all_hosts )
579+
580+ view .bulk_actions_kebab .click ()
581+ self .browser .move_to_element (view .bulk_actions_menu .item_element ('Change associations' ))
582+
583+ view .bulk_actions_change_associations_menu .item_select ('Location' )
584+ view = ChangeLocationModal (self .browser )
585+ view .location_menu .item_select (new_location )
586+
587+ if option == "Fix on mismatch" :
588+ view .location_fix_on_mismatch .fill (True )
589+ view .save_button .click ()
590+
591+ elif option == "Fail on mismatch" :
592+ view .location_fail_on_mismatch .fill (True )
593+ view .save_button .click ()
594+
550595
551596@navigator .register (AllHostsEntity , 'All' )
552597class ShowAllHostsScreen (NavigateStep ):
0 commit comments