Skip to content

Commit 6ecaa99

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

File tree

2 files changed

+84
-10
lines changed

2 files changed

+84
-10
lines changed

tests/e2e/mnist_raycluster_sdk_kind_test.py

Lines changed: 42 additions & 5 deletions
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
@@ -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,
@@ -68,6 +66,10 @@ def run_mnist_raycluster_sdk_kind(
6866

6967
self.assert_jobsubmit_withoutlogin_kind(cluster, accelerator, number_of_gpus)
7068

69+
self.assert_get_cluster_and_jobsubmit(
70+
"mnist", self.namespace, accelerator, number_of_gpus
71+
)
72+
7173
# Assertions
7274

7375
def assert_jobsubmit_withoutlogin_kind(self, cluster, accelerator, number_of_gpus):
@@ -105,12 +107,47 @@ def assert_jobsubmit_withoutlogin_kind(self, cluster, accelerator, number_of_gpu
105107

106108
client.delete_job(submission_id)
107109

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

tests/e2e/mnist_raycluster_sdk_oauth_test.py

Lines changed: 42 additions & 5 deletions
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)