Skip to content

Commit 60b07f8

Browse files
committed
Add test coverage to validate the functionality of the get_cluster method
1 parent 97cd6ea commit 60b07f8

3 files changed

+84
-10
lines changed

tests/e2e/mnist_raycluster_sdk_aw_kind_test.py

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def run_mnist_raycluster_sdk_kind(
4444
num_workers=1,
4545
head_cpu_requests="500m",
4646
head_cpu_limits="500m",
47-
head_memory_requests=2,
48-
head_memory_limits=2,
4947
worker_cpu_requests="500m",
5048
worker_cpu_limits=1,
5149
worker_memory_requests=1,

tests/e2e/mnist_raycluster_sdk_kind_test.py

+42-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from time import sleep
44

5-
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
5+
from codeflare_sdk import Cluster, ClusterConfiguration, get_cluster
66
from codeflare_sdk.ray.client import RayJobClient
77

88
import pytest
@@ -68,6 +68,10 @@ def run_mnist_raycluster_sdk_kind(
6868

6969
self.assert_jobsubmit_withoutlogin_kind(cluster, accelerator, number_of_gpus)
7070

71+
self.assert_get_cluster_and_jobsubmit(
72+
"mnist", self.namespace, accelerator, number_of_gpus
73+
)
74+
7175
# Assertions
7276

7377
def assert_jobsubmit_withoutlogin_kind(self, cluster, accelerator, number_of_gpus):
@@ -105,12 +109,47 @@ def assert_jobsubmit_withoutlogin_kind(self, cluster, accelerator, number_of_gpu
105109

106110
client.delete_job(submission_id)
107111

108-
cluster.down()
109-
110112
def assert_job_completion(self, status):
111113
if status == "SUCCEEDED":
112114
print(f"Job has completed: '{status}'")
113115
assert True
114116
else:
115117
print(f"Job has completed: '{status}'")
116118
assert False
119+
120+
def assert_get_cluster_and_jobsubmit(
121+
self, cluster_name, namespace, accelerator, number_of_gpus
122+
):
123+
# Retrieve the cluster
124+
cluster = get_cluster(cluster_name, namespace)
125+
126+
cluster.details()
127+
128+
cluster.config.verify_tls = False
129+
130+
# Initialize the job client
131+
client = cluster.job_client
132+
133+
# Submit a job and get the submission ID
134+
submission_id = client.submit_job(
135+
entrypoint="python mnist.py",
136+
runtime_env={
137+
"working_dir": "./tests/e2e/",
138+
"pip": "./tests/e2e/mnist_pip_requirements.txt",
139+
"env_vars": get_setup_env_variables(ACCELERATOR=accelerator),
140+
},
141+
entrypoint_num_gpus=number_of_gpus,
142+
)
143+
print(f"Submitted job with ID: {submission_id}")
144+
145+
# Fetch the list of jobs and validate
146+
job_list = client.list_jobs()
147+
print(f"List of Jobs: {job_list}")
148+
149+
# Validate the number of jobs in the list
150+
assert len(job_list) == 1
151+
152+
# Validate the submission ID matches
153+
assert job_list[0].submission_id == submission_id
154+
155+
cluster.down()

tests/e2e/mnist_raycluster_sdk_oauth_test.py

+42-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
from time import sleep
44

5-
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
5+
from codeflare_sdk import (
6+
Cluster,
7+
ClusterConfiguration,
8+
TokenAuthentication,
9+
get_cluster,
10+
)
611
from codeflare_sdk.ray.client import RayJobClient
712

813
import pytest
@@ -44,8 +49,6 @@ def run_mnist_raycluster_sdk_oauth(self):
4449
num_workers=1,
4550
head_cpu_requests="500m",
4651
head_cpu_limits="500m",
47-
head_memory_requests=4,
48-
head_memory_limits=4,
4952
worker_cpu_requests=1,
5053
worker_cpu_limits=1,
5154
worker_memory_requests=1,
@@ -68,6 +71,7 @@ def run_mnist_raycluster_sdk_oauth(self):
6871

6972
self.assert_jobsubmit_withoutLogin(cluster)
7073
self.assert_jobsubmit_withlogin(cluster)
74+
self.assert_get_cluster_and_jobsubmit("mnist", self.namespace)
7175

7276
# Assertions
7377

@@ -132,12 +136,45 @@ def assert_jobsubmit_withlogin(self, cluster):
132136

133137
client.delete_job(submission_id)
134138

135-
cluster.down()
136-
137139
def assert_job_completion(self, status):
138140
if status == "SUCCEEDED":
139141
print(f"Job has completed: '{status}'")
140142
assert True
141143
else:
142144
print(f"Job has completed: '{status}'")
143145
assert False
146+
147+
def assert_get_cluster_and_jobsubmit(self, cluster_name, namespace):
148+
# Retrieve the cluster
149+
cluster = get_cluster(cluster_name, namespace)
150+
151+
cluster.details()
152+
153+
cluster.config.verify_tls = False
154+
155+
# Initialize the job client
156+
client = cluster.job_client
157+
158+
# Submit a job and get the submission ID
159+
submission_id = client.submit_job(
160+
entrypoint="python mnist.py",
161+
runtime_env={
162+
"working_dir": "./tests/e2e/",
163+
"pip": "./tests/e2e/mnist_pip_requirements.txt",
164+
"env_vars": get_setup_env_variables(),
165+
},
166+
entrypoint_num_cpus=1,
167+
)
168+
print(f"Submitted job with ID: {submission_id}")
169+
170+
# Fetch the list of jobs and validate
171+
job_list = client.list_jobs()
172+
print(f"List of Jobs: {job_list}")
173+
174+
# Validate the number of jobs in the list
175+
assert len(job_list) == 1
176+
177+
# Validate the submission ID matches
178+
assert job_list[0].submission_id == submission_id
179+
180+
cluster.down()

0 commit comments

Comments
 (0)