Skip to content

Commit 926e7db

Browse files
Add is_dashboard_ready function + update unit test
1 parent 61d7f3b commit 926e7db

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from kubernetes import client, config
3939
import yaml
4040
import os
41+
import requests
4142

4243

4344
class Cluster:
@@ -258,27 +259,36 @@ def status(
258259

259260
return status, ready
260261

262+
def is_dashboard_ready(self) -> bool:
263+
response = requests.get(self.cluster_dashboard_uri(), timeout=5)
264+
if response.status_code == 200:
265+
return True
266+
else:
267+
return False
268+
261269
def wait_ready(self, timeout: Optional[int] = None):
262270
"""
263271
Waits for requested cluster to be ready, up to an optional timeout (s).
264272
Checks every five seconds.
265273
"""
266274
print("Waiting for requested resources to be set up...")
267275
ready = False
276+
dashboard_ready = False
268277
status = None
269278
time = 0
270-
while not ready:
279+
while not ready or not dashboard_ready:
271280
status, ready = self.status(print_to_console=False)
281+
dashboard_ready = self.is_dashboard_ready()
272282
if status == CodeFlareClusterStatus.UNKNOWN:
273283
print(
274284
"WARNING: Current cluster status is unknown, have you run cluster.up yet?"
275285
)
276-
if not ready:
286+
if not ready or not dashboard_ready:
277287
if timeout and time >= timeout:
278288
raise TimeoutError(f"wait() timed out after waiting {timeout}s")
279289
sleep(5)
280290
time += 5
281-
print("Requested cluster up and running!")
291+
print("Requested cluster and dashboard are up and running!")
282292

283293
def details(self, print_to_console: bool = True) -> RayCluster:
284294
cluster = _copy_to_ray(self)

tests/unit_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,21 @@ def test_wait_ready(mocker, capsys):
17361736
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
17371737
mocker.patch("codeflare_sdk.cluster.cluster._app_wrapper_status", return_value=None)
17381738
mocker.patch("codeflare_sdk.cluster.cluster._ray_cluster_status", return_value=None)
1739+
mocker.patch.object(
1740+
client.CustomObjectsApi,
1741+
"list_namespaced_custom_object",
1742+
return_value={
1743+
"items": [
1744+
{
1745+
"metadata": {"name": "ray-dashboard-test"},
1746+
"spec": {"host": "mocked-host"},
1747+
}
1748+
]
1749+
},
1750+
)
1751+
mock_response = mocker.Mock()
1752+
mock_response.status_code = 200
1753+
mocker.patch("requests.get", return_value=mock_response)
17391754
cf = Cluster(ClusterConfiguration(name="test", namespace="ns"))
17401755
try:
17411756
cf.wait_ready(timeout=5)
@@ -1756,7 +1771,7 @@ def test_wait_ready(mocker, capsys):
17561771
captured = capsys.readouterr()
17571772
assert (
17581773
captured.out
1759-
== "Waiting for requested resources to be set up...\nRequested cluster up and running!\n"
1774+
== "Waiting for requested resources to be set up...\nRequested cluster and dashboard are up and running!\n"
17601775
)
17611776

17621777

0 commit comments

Comments
 (0)