@@ -93,10 +93,10 @@ def test_rayjob_init_validation_both_provided(mocker):
93
93
"""Test that providing both cluster_name and cluster_config raises error."""
94
94
# Mock kubernetes config loading
95
95
mocker .patch ("kubernetes.config.load_kube_config" )
96
-
96
+
97
97
# Mock the RayjobApi class entirely
98
98
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
99
-
99
+
100
100
cluster_config = ClusterConfiguration (name = "test-cluster" , namespace = "test" )
101
101
102
102
with pytest .raises (
@@ -114,10 +114,10 @@ def test_rayjob_init_validation_neither_provided(mocker):
114
114
"""Test that providing neither cluster_name nor cluster_config raises error."""
115
115
# Mock kubernetes config loading (though this should fail before reaching it)
116
116
mocker .patch ("kubernetes.config.load_kube_config" )
117
-
117
+
118
118
# Mock the RayjobApi class entirely (though this should fail before reaching it)
119
119
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
120
-
120
+
121
121
with pytest .raises (
122
122
ValueError , match = "Either cluster_name or cluster_config must be provided"
123
123
):
@@ -128,10 +128,10 @@ def test_rayjob_init_with_cluster_config(mocker):
128
128
"""Test RayJob initialization with cluster configuration for auto-creation."""
129
129
# Mock kubernetes config loading
130
130
mocker .patch ("kubernetes.config.load_kube_config" )
131
-
131
+
132
132
# Mock the RayjobApi class entirely
133
133
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
134
-
134
+
135
135
cluster_config = ClusterConfiguration (
136
136
name = "auto-cluster" , namespace = "test-namespace" , num_workers = 2
137
137
)
@@ -152,10 +152,10 @@ def test_rayjob_cluster_name_generation(mocker):
152
152
"""Test that cluster names are generated when config has empty name."""
153
153
# Mock kubernetes config loading
154
154
mocker .patch ("kubernetes.config.load_kube_config" )
155
-
155
+
156
156
# Mock the RayjobApi class entirely
157
157
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
158
-
158
+
159
159
cluster_config = ClusterConfiguration (
160
160
name = "" , # Empty name should trigger generation
161
161
namespace = "test-namespace" ,
@@ -170,11 +170,77 @@ def test_rayjob_cluster_name_generation(mocker):
170
170
assert cluster_config .name == "my-job-cluster" # Should be updated
171
171
172
172
173
+ def test_rayjob_cluster_config_namespace_none (mocker ):
174
+ """Test that cluster config namespace is set when None."""
175
+ # Mock kubernetes config loading
176
+ mocker .patch ("kubernetes.config.load_kube_config" )
177
+
178
+ # Mock the RayjobApi class entirely
179
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
180
+
181
+ cluster_config = ClusterConfiguration (
182
+ name = "test-cluster" ,
183
+ namespace = None , # This should be set to job namespace
184
+ num_workers = 1 ,
185
+ )
186
+
187
+ rayjob = RayJob (
188
+ job_name = "test-job" ,
189
+ cluster_config = cluster_config ,
190
+ namespace = "job-namespace" ,
191
+ entrypoint = "python script.py"
192
+ )
193
+
194
+ assert cluster_config .namespace == "job-namespace"
195
+ assert rayjob .namespace == "job-namespace"
196
+
197
+
198
+ def test_rayjob_with_active_deadline_seconds (mocker ):
199
+ """Test RayJob CR generation with active deadline seconds."""
200
+ # Mock kubernetes config loading
201
+ mocker .patch ("kubernetes.config.load_kube_config" )
202
+
203
+ # Mock the RayjobApi class entirely
204
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
205
+
206
+ rayjob = RayJob (
207
+ job_name = "test-job" ,
208
+ cluster_name = "test-cluster" ,
209
+ namespace = "test-namespace" ,
210
+ entrypoint = "python main.py" ,
211
+ active_deadline_seconds = 30 ,
212
+ )
213
+
214
+ rayjob_cr = rayjob ._build_rayjob_cr ()
215
+
216
+ assert rayjob_cr ["spec" ]["activeDeadlineSeconds" ] == 30
217
+
218
+
219
+ def test_build_ray_cluster_spec_no_config_error (mocker ):
220
+ """Test _build_ray_cluster_spec raises error when no cluster config."""
221
+ # Mock kubernetes config loading
222
+ mocker .patch ("kubernetes.config.load_kube_config" )
223
+
224
+ # Mock the RayjobApi class entirely
225
+ mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
226
+
227
+ # Create RayJob with cluster_name (no cluster_config)
228
+ rayjob = RayJob (
229
+ job_name = "test-job" ,
230
+ cluster_name = "existing-cluster" ,
231
+ entrypoint = "python script.py" ,
232
+ )
233
+
234
+ # Line 198: Should raise RuntimeError when trying to build spec without config
235
+ with pytest .raises (RuntimeError , match = "No cluster configuration provided" ):
236
+ rayjob ._build_ray_cluster_spec ()
237
+
238
+
173
239
@patch ("codeflare_sdk.ray.rayjobs.rayjob.build_ray_cluster" )
174
240
def test_build_ray_cluster_spec (mock_build_ray_cluster , mocker ):
175
241
"""Test _build_ray_cluster_spec method."""
176
242
mocker .patch ("kubernetes.config.load_kube_config" )
177
-
243
+
178
244
# Mock the RayjobApi class entirely
179
245
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
180
246
@@ -216,7 +282,7 @@ def test_build_ray_cluster_spec(mock_build_ray_cluster, mocker):
216
282
def test_build_rayjob_cr_with_existing_cluster (mocker ):
217
283
"""Test _build_rayjob_cr method with existing cluster."""
218
284
mocker .patch ("kubernetes.config.load_kube_config" )
219
-
285
+
220
286
# Mock the RayjobApi class entirely
221
287
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
222
288
@@ -251,7 +317,7 @@ def test_build_rayjob_cr_with_existing_cluster(mocker):
251
317
def test_build_rayjob_cr_with_auto_cluster (mock_build_ray_cluster , mocker ):
252
318
"""Test _build_rayjob_cr method with auto-created cluster."""
253
319
mocker .patch ("kubernetes.config.load_kube_config" )
254
-
320
+
255
321
# Mock the RayjobApi class entirely
256
322
mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
257
323
@@ -304,9 +370,6 @@ def test_submit_with_auto_cluster(mock_build_ray_cluster, mocker):
304
370
"""Test successful submission with auto-created cluster."""
305
371
mocker .patch ("kubernetes.config.load_kube_config" )
306
372
307
- # Mock the RayjobApi class entirely
308
- mocker .patch ("codeflare_sdk.ray.rayjobs.rayjob.RayjobApi" )
309
-
310
373
mock_ray_cluster = {
311
374
"apiVersion" : "ray.io/v1" ,
312
375
"kind" : "RayCluster" ,
0 commit comments