33from navmazing import NavigateToSibling
44from wait_for import wait_for
55
6+ from airgun .entities .all_hosts import AllHostsEntity
67from airgun .entities .host import HostEntity
78from airgun .navigation import NavigateStepWithWait as NavigateStep , navigator
9+ from airgun .views .all_hosts import AllHostsTableView
810from airgun .views .cloud_insights import RemediateSummary
911from airgun .views .fact import HostFactView
10- from airgun .views .host import HostsView as LegacyHostsView
12+ from airgun .views .host import HostsJobInvocationStatusView , HostsView as LegacyHostsView
1113from airgun .views .host_new import (
1214 AllAssignedRolesView ,
1315 ContainerfileInstallCommandView ,
1416 EditAnsibleRolesView ,
1517 EditSystemPurposeView ,
1618 EnableTracerView ,
17- HostsView ,
1819 InstallPackagesView ,
1920 ManageHostCollectionModal ,
2021 ManageHostStatusesView ,
@@ -349,6 +350,72 @@ def schedule_job(self, entity_name, values):
349350 view .fill (values )
350351 view .submit .click ()
351352
353+ def schedule_remote_job (self , entities_list , values , timeout = 60 , wait_for_results = True ):
354+ """Apply Schedule Remote Job action to the hosts names in entities_list using PF5 UI.
355+
356+ For multiple hosts, uses AllHostsEntity helper to select checkboxes, then clicks
357+ "Schedule a job" button which opens the wizard with hosts pre-selected.
358+
359+ :param entities_list: The host names to apply the remote job.
360+ :param values: the values to fill The Job invocation view.
361+ :param timeout: The time to wait for the job to finish.
362+ :param wait_for_results: Whether to wait for the job to finish execution.
363+
364+ :returns: The job invocation status view values
365+ """
366+ if len (entities_list ) == 1 :
367+ # Single host - use the host details page approach
368+ entity_name = entities_list [0 ]
369+ details_view = self .navigate_to (self , 'NewDetails' , entity_name = entity_name )
370+ self .browser .plugin .ensure_page_safe ()
371+ details_view .wait_displayed ()
372+ # Click the Schedule a job dropdown
373+ self .browser .wait_for_element (details_view .schedule_job , exception = False )
374+ details_view .schedule_job .fill ('Schedule a job' )
375+ # The job invocation form appears in the same browser context
376+ view = JobInvocationCreateView (self .browser )
377+ self .browser .plugin .ensure_page_safe ()
378+ else :
379+ # Multiple hosts - use AllHostsEntity helper to navigate and select hosts
380+ # This helper handles: clearing previous selections, searching, selecting checkboxes
381+ # and returns AllHostsTableView with selected hosts
382+ hosts_view = AllHostsEntity .all_hosts_navigate_and_select_hosts_helper (
383+ self , host_names = entities_list
384+ )
385+
386+ # After selecting hosts, click the "Schedule a job" button
387+ # This button appears dynamically after hosts are selected
388+ schedule_button_locator = ".//button[contains(., 'Schedule a job') or @data-ouia-component-id='schedule-a-job-dropdown']"
389+ wait_for (
390+ lambda : hosts_view .browser .element (schedule_button_locator , check_visibility = True ),
391+ timeout = 10 ,
392+ delay = 0.5 ,
393+ handle_exception = True ,
394+ )
395+ schedule_button = hosts_view .browser .element (schedule_button_locator )
396+ hosts_view .browser .click (schedule_button )
397+
398+ # The job invocation form should now open with hosts pre-selected
399+ view = JobInvocationCreateView (self .browser )
400+ self .browser .plugin .ensure_page_safe ()
401+ # Wait for the wizard to be displayed
402+ view .wait_displayed ()
403+
404+ # Fill the form with provided values
405+ view .fill (values )
406+ # Wait for form to be fully filled and ready for submission
407+ self .browser .plugin .ensure_page_safe ()
408+ view .submit .click ()
409+ view .flash .assert_no_error ()
410+ view .flash .dismiss ()
411+ # Wait for status view to appear after job submission
412+ status_view = HostsJobInvocationStatusView (self .browser )
413+ self .browser .plugin .ensure_page_safe ()
414+ status_view .wait_displayed ()
415+ if wait_for_results :
416+ status_view .wait_for_result (timeout = timeout )
417+ return status_view .read ()
418+
352419 def run_job (self , entity_name ):
353420 """Run a job on selected host"""
354421 view = self .navigate_to (self , 'NewDetails' , entity_name = entity_name )
@@ -1231,7 +1298,7 @@ def get_content_view_envs(self, entity_name):
12311298class ShowAllHosts (NavigateStep ):
12321299 """Navigate to new UI All Hosts page"""
12331300
1234- VIEW = HostsView
1301+ VIEW = AllHostsTableView
12351302
12361303 def step (self , * args , ** kwargs ):
12371304 self .view .menu .select ('Hosts' , 'All Hosts' )
@@ -1252,6 +1319,7 @@ def prerequisite(self, *args, **kwargs):
12521319
12531320 def step (self , * args , ** kwargs ):
12541321 entity_name = kwargs .get ('entity_name' )
1322+
12551323 self .parent .search (entity_name )
12561324 self .parent .table .row (name = entity_name )['Name' ].widget .click ()
12571325
0 commit comments