Skip to content

Commit b176c71

Browse files
luca3rdnmiculinic
authored andcommitted
Add 'health checks' when cluster is in same status
1 parent 43a39cf commit b176c71

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/lightning_app/cli/cmd_clusters.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ def _wait_for_cluster_state(
218218
"""
219219
start = time.time()
220220
elapsed = 0
221-
current_state = V1ClusterState.UNSPECIFIED
222221

223222
while elapsed < max_wait_time:
224223
cluster_resp = api_client.cluster_service_list_clusters()
@@ -228,14 +227,12 @@ def _wait_for_cluster_state(
228227
new_cluster = clust
229228
break
230229
if new_cluster is not None:
231-
if current_state != new_cluster.status.phase:
232-
current_state = new_cluster.status.phase
233-
echo_cluster_status_long(
234-
cluster_id=cluster_id,
235-
current_state=current_state,
236-
current_reason=new_cluster.status.reason,
237-
desired_state=target_state,
238-
)
230+
echo_cluster_status_long(
231+
cluster_id=cluster_id,
232+
current_state=new_cluster.status.phase,
233+
current_reason=new_cluster.status.reason,
234+
desired_state=target_state,
235+
)
239236
if new_cluster.status.phase == target_state:
240237
break
241238
time.sleep(check_timeout)

tests/tests_app/cli/test_cmd_clusters.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ def test_echo_state_change_on_desired_running(self, echo: MagicMock):
150150
]
151151
)
152152
for state, reason in [
153-
(V1ClusterState.UNSPECIFIED, ""),
154153
(V1ClusterState.QUEUED, ""),
155154
(V1ClusterState.PENDING, ""),
155+
(V1ClusterState.PENDING, ""),
156+
(V1ClusterState.PENDING, ""),
156157
(V1ClusterState.FAILED, "some error"),
157158
(V1ClusterState.PENDING, "retrying failure"),
158159
(V1ClusterState.RUNNING, ""),
@@ -168,12 +169,14 @@ def test_echo_state_change_on_desired_running(self, echo: MagicMock):
168169
check_timeout=0.1,
169170
)
170171

171-
assert client.list_call_count == 6
172-
assert echo.call_count == 5
172+
assert client.list_call_count == 7
173+
assert echo.call_count == 7
173174
echo.assert_has_calls(
174175
[
175176
call("Cluster test-cluster is now queued"),
176177
call("Cluster test-cluster is now pending"),
178+
call("Cluster test-cluster is now pending"),
179+
call("Cluster test-cluster is now pending"),
177180
call(
178181
"\n".join(
179182
[
@@ -214,6 +217,8 @@ def test_echo_state_change_on_desired_deleted(self, echo: MagicMock):
214217
]
215218
)
216219
for state in [
220+
V1ClusterState.RUNNING,
221+
V1ClusterState.RUNNING,
217222
V1ClusterState.RUNNING,
218223
V1ClusterState.DELETED,
219224
]
@@ -228,10 +233,12 @@ def test_echo_state_change_on_desired_deleted(self, echo: MagicMock):
228233
check_timeout=0.1,
229234
)
230235

231-
assert client.list_call_count == 2
232-
assert echo.call_count == 2
236+
assert client.list_call_count == 4
237+
assert echo.call_count == 4
233238
echo.assert_has_calls(
234239
[
240+
call("Cluster test-cluster is terminating"),
241+
call("Cluster test-cluster is terminating"),
235242
call("Cluster test-cluster is terminating"),
236243
call("Cluster test-cluster has been deleted."),
237244
]

0 commit comments

Comments
 (0)