Skip to content

Commit 1f06166

Browse files
committed
Wait until the nodes are ready
1 parent c35a7ab commit 1f06166

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

benchmark_runner/common/oc/oc.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,32 +457,51 @@ def get_worker_nodes(self):
457457
"""
458458
return self.run(fr""" {self.__cli} get nodes -l node-role.kubernetes.io/worker= -o jsonpath="{{range .items[*]}}{{.metadata.name}}{{'\n'}}{{end}}" """)
459459

460-
@staticmethod
461460
@typechecked
462-
def check_node_status(nodes_list: list):
461+
def wait_for_nodes_ready(self, wait_time: int = None, timeout: int = int(environment_variables.environment_variables_dict['timeout'])):
463462
"""
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.
464+
@param wait_time: wait time between each loop
465+
@param timeout: Maximum wait time in seconds (default set in environment variables)
466+
@return: True if all nodes are in 'Ready' status within the timeout period
467+
@raises: NodeNotReady if one or more nodes are not ready within the timeout
468+
"""
469+
wait_time = wait_time or OC.SHORT_TIMEOUT
470+
all_nodes_ready = None
471+
current_wait_time = 0
472+
while timeout <= 0 or current_wait_time < timeout:
473+
all_nodes_ready = self.check_all_nodes_status()
474+
if all_nodes_ready is True:
475+
return True
476+
logger.info(f"Waiting for node '{all_nodes_ready[0]}' to reach 'Ready' status, current status '{all_nodes_ready[1]}'.")
477+
time.sleep(wait_time)
478+
current_wait_time += wait_time
479+
logger.info(f"oc get nodes:\n{self.run('oc get nodes')}")
480+
raise NodeNotReady(node_name=all_nodes_ready[0], node_status=all_nodes_ready[1])
481+
482+
@typechecked
483+
def check_all_nodes_status(self):
484+
"""
485+
This method checks the status of all nodes in the list.
486+
@return: True if all nodes are in 'Ready' status; otherwise, return (node_name, node_status)
467487
"""
468488
# Check if any node is not in 'Ready' status
469-
for node in nodes_list:
489+
for node in self.get_node_status():
470490
node_name, node_status = node.split()
471491
if node_status != 'Ready':
472-
raise NodeNotReady(node_name, node_status)
492+
return node_name, node_status
473493

474494
# If no nodes are found in a non-ready state
475495
return True
476496

477-
def verify_nodes_ready(self):
497+
def get_node_status(self) -> list:
478498
"""
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
499+
This method returns node status list
500+
@return:
482501
"""
483502
# Get the node name and status for all nodes
484503
nodes_list = self.run(f"{self.__cli} get nodes --no-headers | awk '{{print $1, $2}}'").splitlines()
485-
return self.check_node_status(nodes_list)
504+
return nodes_list
486505

487506
def delete_available_released_pv(self):
488507
"""

benchmark_runner/main/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def upgrade_ocp_bare_metal(step: str):
175175
elif step == 'verify_bare_metal_upgrade_complete':
176176
if bare_metal_operations.is_cluster_upgraded(oc, cnv_version=cnv_version, odf_version=odf_version, lso_version=lso_version):
177177
bare_metal_operations.verify_cluster_is_up(oc)
178-
oc.verify_nodes_ready()
178+
oc.wait_for_nodes_ready()
179179
else:
180180
error_message = f'OCP {upgrade_ocp_version} upgrade failed'
181181
logger.error(error_message)
@@ -200,7 +200,7 @@ def install_resources():
200200
logger.info(f'Start Bare-Metal OpenShift resources installation')
201201
oc = bare_metal_operations.oc_login()
202202
bare_metal_operations.verify_cluster_is_up(oc)
203-
oc.verify_nodes_ready()
203+
oc.wait_for_nodes_ready()
204204
bare_metal_operations.install_ocp_resources(resources=resources)
205205
bare_metal_operations.disconnect_from_provisioner()
206206
logger.info(f'End Bare-Metal OpenShift resources installation')

tests/integration/benchmark_runner/common/oc/test_oc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ def test_collect_prometheus():
234234
assert tarfile.is_tarfile(tarball)
235235

236236

237-
def test_verify_nodes_ready():
237+
def test_wait_for_nodes_ready():
238238
"""
239-
This method test nodes are ready
239+
This method waits till nodes are ready
240240
@return:
241241
"""
242242
oc = OC(kubeadmin_password=test_environment_variable['kubeadmin_password'])
243243
oc.login()
244-
assert oc.verify_nodes_ready()
244+
assert oc.wait_for_nodes_ready()

tests/unittest/benchmark_runner/common/oc/test_oc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
import mock
33
import pytest
4+
from unittest.mock import patch
5+
46
from benchmark_runner.common.oc.oc import OC
57
from benchmark_runner.common.oc.oc_exceptions import YAMLNotExist, LoginFailed, NodeNotReady
68

@@ -51,13 +53,15 @@ def test_short_uuid():
5153

5254
def test_check_node_status_ready():
5355
oc = OC()
54-
result = oc.check_node_status(nodes_list=['node-0 Ready', 'node-1 Ready', 'node-2 Ready'])
55-
assert result
56+
with patch.object(OC, 'get_node_status', return_value=['node-0 Ready', 'node-1 Ready', 'node-2 Ready']):
57+
result = oc.wait_for_nodes_ready()
58+
assert result
5659

5760

5861
def test_check_node_status_not_ready():
5962
oc = OC()
6063
with pytest.raises(NodeNotReady) as exc_info:
61-
oc.check_node_status(nodes_list=['node-0 Ready', 'node-1 NotReady', 'node-2 Ready'])
64+
with patch.object(OC, 'get_node_status', return_value=['node-0 Ready', 'node-1 NotReady', 'node-2 Ready']):
65+
oc.wait_for_nodes_ready(wait_time=3, timeout=10)
6266
# Check that the exception message is as expected
6367
assert str(exc_info.value) == "Node node-1 is not ready. Current status: NotReady"

0 commit comments

Comments
 (0)