Skip to content

Commit f397cca

Browse files
Add is_dashboard_ready function + update unit test
1 parent fb34ba4 commit f397cca

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 16 additions & 4 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:
@@ -217,27 +218,38 @@ def status(
217218

218219
return status, ready
219220

221+
def is_dashboard_ready(self) -> bool:
222+
try:
223+
response = requests.get(self.cluster_dashboard_uri(), timeout=5)
224+
if response.status_code == 200:
225+
return True
226+
except requests.RequestException:
227+
pass
228+
return False
229+
220230
def wait_ready(self, timeout: Optional[int] = None):
221231
"""
222232
Waits for requested cluster to be ready, up to an optional timeout (s).
223233
Checks every five seconds.
224234
"""
225235
print("Waiting for requested resources to be set up...")
226236
ready = False
237+
dashboard_ready = False
227238
status = None
228239
time = 0
229-
while not ready:
240+
while not ready or not dashboard_ready:
230241
status, ready = self.status(print_to_console=False)
242+
dashboard_ready = self.is_dashboard_ready()
231243
if status == CodeFlareClusterStatus.UNKNOWN:
232244
print(
233245
"WARNING: Current cluster status is unknown, have you run cluster.up yet?"
234-
)
235-
if not ready:
246+
)
247+
if not ready or not dashboard_ready:
236248
if timeout and time >= timeout:
237249
raise TimeoutError(f"wait() timed out after waiting {timeout}s")
238250
sleep(5)
239251
time += 5
240-
print("Requested cluster up and running!")
252+
print("Requested cluster dashboard are up and running!")
241253

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

tests/unit_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,10 @@ def test_wait_ready(mocker, capsys):
16931693
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
16941694
mocker.patch("codeflare_sdk.cluster.cluster._app_wrapper_status", return_value=None)
16951695
mocker.patch("codeflare_sdk.cluster.cluster._ray_cluster_status", return_value=None)
1696+
mocker.patch.object(client.CustomObjectsApi, 'list_namespaced_custom_object', return_value={"items": [{"metadata": {"name": "ray-dashboard-test"}, "spec": {"host": "mocked-host"}}]})
1697+
mock_response = mocker.Mock()
1698+
mock_response.status_code = 200
1699+
mocker.patch('requests.get', return_value=mock_response)
16961700
cf = Cluster(ClusterConfiguration(name="test", namespace="ns"))
16971701
try:
16981702
cf.wait_ready(timeout=5)
@@ -1713,7 +1717,7 @@ def test_wait_ready(mocker, capsys):
17131717
captured = capsys.readouterr()
17141718
assert (
17151719
captured.out
1716-
== "Waiting for requested resources to be set up...\nRequested cluster up and running!\n"
1720+
== "Waiting for requested resources to be set up...\nRequested cluster dashboard are up and running!\n"
17171721
)
17181722

17191723

0 commit comments

Comments
 (0)