1
+ import re
1
2
from pathlib import Path
2
3
from typing import Dict , Iterator
3
4
from unittest import mock
@@ -275,13 +276,21 @@ def create_namespaced_job(self, namespace: str, body: kubernetes.client.V1Job):
275
276
def read_namespaced_job (self , name : str , namespace : str ):
276
277
assert name in self .jobs
277
278
assert self .jobs [name ].metadata .namespace == namespace
278
- return kubernetes .client .V1Job (
279
- metadata = self .jobs [name ].metadata ,
280
- status = kubernetes .client .V1JobStatus (
281
- # TODO: way to specify timeline of job conditions?
282
- conditions = [kubernetes .client .V1JobCondition (type = "Complete" , status = "True" )]
283
- ),
284
- )
279
+ if "instant-fail" in name :
280
+ return kubernetes .client .V1Job (
281
+ metadata = self .jobs [name ].metadata ,
282
+ status = kubernetes .client .V1JobStatus (
283
+ failed = 1 ,
284
+ ),
285
+ )
286
+ else :
287
+ return kubernetes .client .V1Job (
288
+ metadata = self .jobs [name ].metadata ,
289
+ status = kubernetes .client .V1JobStatus (
290
+ # TODO: way to specify timeline of job conditions?
291
+ conditions = [kubernetes .client .V1JobCondition (type = "Complete" , status = "True" )]
292
+ ),
293
+ )
285
294
286
295
with mock .patch ("kubernetes.client.BatchV1Api" , new = BatchV1Api ):
287
296
yield
@@ -296,6 +305,14 @@ def test_launch_job_and_wait_basic(self, k8s_batch_api, caplog):
296
305
297
306
assert caplog .messages [- 1 ] == dirty_equals .IsStr (regex = ".*job_name='cal-123'.*final_status='complete'.*" )
298
307
308
+ def test_launch_job_and_wait_fail (self , k8s_batch_api , caplog ):
309
+ launcher = CalrissianJobLauncher (namespace = self .NAMESPACE , name_base = "r-456" )
310
+ job_manifest = kubernetes .client .V1Job (
311
+ metadata = kubernetes .client .V1ObjectMeta (name = "cal-123-instant-fail" , namespace = self .NAMESPACE )
312
+ )
313
+ with pytest .raises (RuntimeError , match = re .compile (r"CWL Job.*" )) as e_info :
314
+ launcher .launch_job_and_wait (manifest = job_manifest )
315
+
299
316
def test_run_cwl_workflow_basic (
300
317
self , k8_pvc_api , k8s_batch_api , generate_unique_id_mock , caplog , s3_calrissian_bucket
301
318
):
0 commit comments