@@ -457,32 +457,61 @@ def get_worker_nodes(self):
457
457
"""
458
458
return self .run (fr""" { self .__cli } get nodes -l node-role.kubernetes.io/worker= -o jsonpath="{{range .items[*]}}{{.metadata.name}}{{'\n'}}{{end}}" """ )
459
459
460
- @staticmethod
461
460
@typechecked
462
- def check_node_status ( nodes_list : list ):
461
+ def wait_for_node_ready ( self , node : str = None , wait_time : int = None , timeout : int = int ( environment_variables . environment_variables_dict [ 'timeout' ]) ):
463
462
"""
464
- This method check node status
465
- @param nodes_list:
466
- @return: True when all nodes in ready status
463
+ This method waits until all nodes are in 'Ready' status or specific node
464
+ @param node: wait for specific node to be ready, when None check all nodes
465
+ @param wait_time: wait time between each loop
466
+ @param timeout: Maximum wait time in seconds, negative value means no timeout (default set in environment variables)
467
+ @return: True if all nodes are in 'Ready' status within the timeout period
468
+ @raises: NodeNotReady if one or more nodes are not ready within the timeout
467
469
"""
468
- # Check if any node is not in 'Ready' status
469
- for node in nodes_list :
470
- node_name , node_status = node .split ()
470
+ wait_time = wait_time or OC .SHORT_TIMEOUT
471
+ nodes_status = None
472
+ current_wait_time = 0
473
+ while timeout <= 0 or current_wait_time < timeout :
474
+ nodes_status = self .check_node_status (node = node )
475
+ if nodes_status is True :
476
+ return True
477
+ logger .info (f"Waiting for '{ nodes_status } ' to reach 'Ready' status" )
478
+ time .sleep (wait_time )
479
+ current_wait_time += wait_time
480
+ logger .info (f"oc get nodes:\n { self .run ('oc get nodes' )} " )
481
+ raise NodeNotReady (nodes_status = nodes_status )
482
+
483
+ @typechecked
484
+ def check_node_status (self , node : str = None ):
485
+ """
486
+ This method checks the status of all nodes or a specific node.
487
+ @param node: The name of a specific node to check for "Ready" status; if None, check all nodes.
488
+ @return: True if all nodes are in 'Ready' status, or a dictionary of nodes that are not in 'Ready' status.
489
+ """
490
+ not_ready_nodes = {}
491
+
492
+ for node_state in self .get_node_status ():
493
+ node_name , node_status = node_state .split ()
494
+
495
+ # If a specific node is given, only check that node
496
+ if node and node != node_name :
497
+ continue
498
+
471
499
if node_status != 'Ready' :
472
- raise NodeNotReady (node_name , node_status )
500
+ not_ready_nodes [node_name ] = node_status
501
+ # If checking a specific node and it's not ready, no need to check further
502
+ if node :
503
+ break
473
504
474
- # If no nodes are found in a non-ready state
475
- return True
505
+ return True if not not_ready_nodes else not_ready_nodes
476
506
477
- def verify_nodes_ready (self ):
507
+ def get_node_status (self ) -> list :
478
508
"""
479
- This method verifies that all nodes are in 'Ready' status.
480
- If any node is not ready, it raises an error with the node name and its status.
481
- @return: True is all in 'Ready' status
509
+ This method returns node status list
510
+ @return:
482
511
"""
483
512
# Get the node name and status for all nodes
484
513
nodes_list = self .run (f"{ self .__cli } get nodes --no-headers | awk '{{print $1, $2}}'" ).splitlines ()
485
- return self . check_node_status ( nodes_list )
514
+ return nodes_list
486
515
487
516
def delete_available_released_pv (self ):
488
517
"""
0 commit comments