Skip to content

Commit 7440579

Browse files
authored
[Cherry-pick][Test][RayCluster] Test redis cleanup job in the e2e compatibility test (#2026) (#2034)
1 parent 9c4768f commit 7440579

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

tests/compatibility-test.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
)
1313

1414
from framework.utils import (
15+
delete_all_cr,
1516
get_head_pod,
1617
get_pod,
1718
pod_exec_command,
@@ -86,8 +87,9 @@ class RayFTTestCase(unittest.TestCase):
8687
cluster_template = CONST.REPO_ROOT.joinpath("tests/config/ray-cluster.ray-ft.yaml.template")
8788
ray_cluster_ns = "default"
8889

89-
@classmethod
90-
def setUpClass(cls):
90+
# We need to delete the RayCluster at the end of each test case to test cleanup_redis,
91+
# therefore, we use setUp, instead of setUpClass, here to re-create RayCluster for each test case.
92+
def setUp(self):
9193
if not utils.is_feature_supported(ray_version, CONST.RAY_FT):
9294
raise unittest.SkipTest(f"{CONST.RAY_FT} is not supported")
9395
K8S_CLUSTER_MANAGER.cleanup()
@@ -96,6 +98,13 @@ def setUpClass(cls):
9698
operator_manager.prepare_operator()
9799
utils.create_ray_cluster(RayFTTestCase.cluster_template, ray_version, ray_image)
98100

101+
def cleanup_redis(self):
102+
delete_all_cr(CONST.RAY_CLUSTER_CRD, RayFTTestCase.ray_cluster_ns)
103+
utils.wait_for_condition(
104+
lambda: shell_subprocess_run("test $(kubectl exec deploy/redis -- redis-cli --no-auth-warning -a 5241590000000000 DBSIZE) = '0'") == 0,
105+
timeout=300, retry_interval_ms=1000,
106+
)
107+
99108
def test_ray_serve(self):
100109
"""Kill GCS process on the head Pod and then test a deployed Ray Serve model."""
101110
if not utils.is_feature_supported(ray_version, CONST.RAY_SERVE_FT):
@@ -153,6 +162,8 @@ def test_ray_serve(self):
153162
show_cluster_info(RayFTTestCase.ray_cluster_ns)
154163
self.fail(f"Fail to execute test_ray_serve_2.py. The exit code is {exit_code}.")
155164

165+
self.cleanup_redis()
166+
156167
@unittest.skipIf(
157168
ray_version == '2.8.0',
158169
'test_detached_actor is too flaky with Ray 2.8.0 due to '
@@ -233,6 +244,8 @@ def test_detached_actor(self):
233244
show_cluster_info(RayFTTestCase.ray_cluster_ns)
234245
self.fail(f"Fail to execute test_detached_actor_2.py. The exit code is {exit_code}.")
235246

247+
self.cleanup_redis()
248+
236249
class KubeRayHealthCheckTestCase(unittest.TestCase):
237250
"""Test KubeRay health check"""
238251
cluster_template = CONST.REPO_ROOT.joinpath("tests/config/ray-cluster.sidecar.yaml.template")

tests/framework/prototype.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,6 @@ def clean_up(self):
424424
show_cluster_info(self.namespace)
425425
raise Exception("RayClusterAddCREvent clean_up() timeout")
426426

427-
"""Make sure the external redis has been cleaned"""
428-
if search_path(self.custom_resource_object, ['metadata', 'annotations', 'ray.io/ft-enabled']) == 'true':
429-
if shell_subprocess_run("test $(kubectl exec deploy/redis -- redis-cli --no-auth-warning -a $(kubectl get secret redis-password-secret -o jsonpath='{.data.password}' | base64 --decode) DBSIZE) = '0'") != 0:
430-
raise Exception("The external redis is not cleaned")
431-
432427
"""Delete other resources in the yaml"""
433428
if self.filepath:
434429
logger.info("Delete other resources in the YAML")

tests/framework/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ def pod_exec_command(pod_name, namespace, exec_command, check=True):
412412
f"kubectl exec {pod_name} -n {namespace} -- {exec_command}", check
413413
)
414414

415+
def delete_all_cr(crd_name, namespace, check=True):
416+
return shell_subprocess_run(
417+
f"kubectl delete {crd_name} --all -n {namespace}", check
418+
)
419+
415420

416421
def start_curl_pod(name: str, namespace: str, timeout_s: int = -1):
417422
shell_subprocess_run(

0 commit comments

Comments
 (0)