Skip to content

Commit 9c95d6e

Browse files
Add is_dashboard_ready function + update unit test
1 parent 59f23aa commit 9c95d6e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/codeflare_sdk/cluster/cluster.py

+13-3
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:
@@ -250,27 +251,36 @@ def status(
250251

251252
return status, ready
252253

254+
def is_dashboard_ready(self) -> bool:
255+
response = requests.get(self.cluster_dashboard_uri(), timeout=5)
256+
if response.status_code == 200:
257+
return True
258+
else:
259+
return False
260+
253261
def wait_ready(self, timeout: Optional[int] = None):
254262
"""
255263
Waits for requested cluster to be ready, up to an optional timeout (s).
256264
Checks every five seconds.
257265
"""
258266
print("Waiting for requested resources to be set up...")
259267
ready = False
268+
dashboard_ready = False
260269
status = None
261270
time = 0
262-
while not ready:
271+
while not ready or not dashboard_ready:
263272
status, ready = self.status(print_to_console=False)
273+
dashboard_ready = self.is_dashboard_ready()
264274
if status == CodeFlareClusterStatus.UNKNOWN:
265275
print(
266276
"WARNING: Current cluster status is unknown, have you run cluster.up yet?"
267277
)
268-
if not ready:
278+
if not ready or not dashboard_ready:
269279
if timeout and time >= timeout:
270280
raise TimeoutError(f"wait() timed out after waiting {timeout}s")
271281
sleep(5)
272282
time += 5
273-
print("Requested cluster up and running!")
283+
print("Requested cluster and dashboard are up and running!")
274284

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

tests/unit_test.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,21 @@ def test_wait_ready(mocker, capsys):
17531753
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
17541754
mocker.patch("codeflare_sdk.cluster.cluster._app_wrapper_status", return_value=None)
17551755
mocker.patch("codeflare_sdk.cluster.cluster._ray_cluster_status", return_value=None)
1756+
mocker.patch.object(
1757+
client.CustomObjectsApi,
1758+
"list_namespaced_custom_object",
1759+
return_value={
1760+
"items": [
1761+
{
1762+
"metadata": {"name": "ray-dashboard-test"},
1763+
"spec": {"host": "mocked-host"},
1764+
}
1765+
]
1766+
},
1767+
)
1768+
mock_response = mocker.Mock()
1769+
mock_response.status_code = 200
1770+
mocker.patch("requests.get", return_value=mock_response)
17561771
cf = Cluster(ClusterConfiguration(name="test", namespace="ns"))
17571772
try:
17581773
cf.wait_ready(timeout=5)
@@ -1773,7 +1788,7 @@ def test_wait_ready(mocker, capsys):
17731788
captured = capsys.readouterr()
17741789
assert (
17751790
captured.out
1776-
== "Waiting for requested resources to be set up...\nRequested cluster up and running!\n"
1791+
== "Waiting for requested resources to be set up...\nRequested cluster and dashboard are up and running!\n"
17771792
)
17781793

17791794

0 commit comments

Comments
 (0)