1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from future import standard_library
6 standard_library.install_aliases()
7 from builtins import object
8 from builtins import str
9 from future.utils import viewvalues
20 import cwltool.process
22 from io import BytesIO
24 # StringIO.StringIO and io.StringIO have different behavior write() is
25 # called with both python2 (byte) strings and unicode strings
26 # (specifically there's some logging in cwltool that causes trouble).
27 # This isn't a problem on python3 because all string are unicode.
28 if sys.version_info[0] < 3:
29 from StringIO import StringIO
31 from io import StringIO
34 import arvados.collection
36 import arvados_cwl.executor
37 import arvados_cwl.runner
40 from .matcher import JsonDiffMatcher, StripYAMLComments
41 from .mock_discovery import get_rootDesc
43 import ruamel.yaml as yaml
48 @functools.wraps(func)
49 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
50 @mock.patch("arvados.collection.KeepClient")
51 @mock.patch("arvados.keep.KeepClient")
52 @mock.patch("arvados.events.subscribe")
53 def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs):
58 stubs.keepdocker = keepdocker
60 def putstub(p, **kwargs):
61 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
62 keep_client1().put.side_effect = putstub
63 keep_client1.put.side_effect = putstub
64 keep_client2().put.side_effect = putstub
65 keep_client2.put.side_effect = putstub
67 stubs.keep_client = keep_client2
68 stubs.docker_images = {
69 "arvados/jobs:"+arvados_cwl.__version__: [("zzzzz-4zz18-zzzzzzzzzzzzzd3", "")],
70 "debian:8": [("zzzzz-4zz18-zzzzzzzzzzzzzd4", "")],
71 "arvados/jobs:123": [("zzzzz-4zz18-zzzzzzzzzzzzzd5", "")],
72 "arvados/jobs:latest": [("zzzzz-4zz18-zzzzzzzzzzzzzd6", "")],
74 def kd(a, b, image_name=None, image_tag=None):
75 return stubs.docker_images.get("%s:%s" % (image_name, image_tag), [])
76 stubs.keepdocker.side_effect = kd
78 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
79 stubs.fake_container_uuid = "zzzzz-dz642-zzzzzzzzzzzzzzz"
81 if sys.version_info[0] < 3:
82 stubs.capture_stdout = BytesIO()
84 stubs.capture_stdout = StringIO()
86 stubs.api = mock.MagicMock()
87 stubs.api._rootDesc = get_rootDesc()
88 stubs.api._rootDesc["uuidPrefix"] = "zzzzz"
90 stubs.api.users().current().execute.return_value = {
91 "uuid": stubs.fake_user_uuid,
93 stubs.api.collections().list().execute.return_value = {"items": []}
94 stubs.api.containers().current().execute.return_value = {
95 "uuid": stubs.fake_container_uuid,
98 class CollectionExecute(object):
99 def __init__(self, exe):
101 def execute(self, num_retries=None):
104 def collection_createstub(created_collections, body, ensure_unique_name=None):
105 mt = body["manifest_text"].encode('utf-8')
106 uuid = "zzzzz-4zz18-zzzzzzzzzzzzzx%d" % len(created_collections)
107 pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt))
108 created_collections[uuid] = {
110 "portable_data_hash": pdh,
111 "manifest_text": mt.decode('utf-8')
113 return CollectionExecute(created_collections[uuid])
115 def collection_getstub(created_collections, uuid):
116 for v in viewvalues(created_collections):
117 if uuid in (v["uuid"], v["portable_data_hash"]):
118 return CollectionExecute(v)
120 created_collections = {
121 "99999999999999999999999999999998+99": {
123 "portable_data_hash": "99999999999999999999999999999998+99",
124 "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt"
126 "99999999999999999999999999999997+99": {
128 "portable_data_hash": "99999999999999999999999999999997+99",
129 "manifest_text": ". 99999999999999999999999999999997+99 0:0:file1.txt"
131 "99999999999999999999999999999994+99": {
133 "portable_data_hash": "99999999999999999999999999999994+99",
134 "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl"
136 "zzzzz-4zz18-zzzzzzzzzzzzzd3": {
137 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd3",
138 "portable_data_hash": "999999999999999999999999999999d3+99",
141 "zzzzz-4zz18-zzzzzzzzzzzzzd4": {
142 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd4",
143 "portable_data_hash": "999999999999999999999999999999d4+99",
146 "zzzzz-4zz18-zzzzzzzzzzzzzd5": {
147 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd5",
148 "portable_data_hash": "999999999999999999999999999999d5+99",
151 "zzzzz-4zz18-zzzzzzzzzzzzzd6": {
152 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd6",
153 "portable_data_hash": "999999999999999999999999999999d6+99",
157 stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections)
158 stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections)
160 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
161 stubs.api.jobs().create().execute.return_value = {
162 "uuid": stubs.expect_job_uuid,
166 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
167 stubs.api.container_requests().create().execute.return_value = {
168 "uuid": stubs.expect_container_request_uuid,
169 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
173 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
174 stubs.api.pipeline_templates().create().execute.return_value = {
175 "uuid": stubs.expect_pipeline_template_uuid,
177 stubs.expect_job_spec = {
178 'runtime_constraints': {
179 'docker_image': '999999999999999999999999999999d3+99',
180 'min_ram_mb_per_node': 1024
182 'script_parameters': {
184 'basename': 'blorp.txt',
185 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
189 'basename': '99999999999999999999999999999998+99',
190 'location': 'keep:99999999999999999999999999999998+99',
194 'basename': 'anonymous',
196 "basename": "renamed.txt",
198 "location": "keep:99999999999999999999999999999998+99/file1.txt",
203 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main'
205 'repository': 'arvados',
206 'script_version': 'master',
207 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
208 'script': 'cwl-runner'
210 stubs.pipeline_component = stubs.expect_job_spec.copy()
211 stubs.expect_pipeline_instance = {
212 'name': 'submit_wf.cwl',
213 'state': 'RunningOnServer',
217 'runtime_constraints': {'docker_image': '999999999999999999999999999999d3+99', 'min_ram_mb_per_node': 1024},
218 'script_parameters': {
219 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}},
221 'basename': 'blorp.txt',
223 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
226 'z': {"value": {'basename': 'anonymous', 'class': 'Directory',
229 'basename': 'renamed.txt',
230 'class': 'File', 'location':
231 'keep:99999999999999999999999999999998+99/file1.txt',
235 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main',
237 'arv:enable_reuse': True,
238 'arv:on_error': 'continue'
240 'repository': 'arvados',
241 'script_version': 'master',
242 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
243 'script': 'cwl-runner',
244 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'}
248 stubs.pipeline_create = copy.deepcopy(stubs.expect_pipeline_instance)
249 stubs.expect_pipeline_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
250 stubs.pipeline_create["uuid"] = stubs.expect_pipeline_uuid
251 stubs.pipeline_with_job = copy.deepcopy(stubs.pipeline_create)
252 stubs.pipeline_with_job["components"]["cwl-runner"]["job"] = {
253 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
256 stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create
257 stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job
259 with open("tests/wf/submit_wf_packed.cwl") as f:
260 expect_packed_workflow = yaml.round_trip_load(f)
262 stubs.expect_container_spec = {
269 '/var/lib/cwl/workflow.json': {
270 'content': expect_packed_workflow,
274 'path': '/var/spool/cwl/cwl.output.json',
277 '/var/lib/cwl/cwl.input.json': {
281 'basename': '99999999999999999999999999999998+99',
282 'location': 'keep:99999999999999999999999999999998+99',
283 'class': 'Directory'},
285 'basename': u'blorp.txt',
287 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
290 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [
291 {'basename': 'renamed.txt',
293 'location': 'keep:99999999999999999999999999999998+99/file1.txt',
302 'state': 'Committed',
303 'command': ['arvados-cwl-runner', '--local', '--api=containers',
304 '--no-log-timestamps', '--disable-validate',
305 '--eval-timeout=20', '--thread-count=1',
306 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
307 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
308 'name': 'submit_wf.cwl',
309 'container_image': '999999999999999999999999999999d3+99',
310 'output_path': '/var/spool/cwl',
311 'cwd': '/var/spool/cwl',
312 'runtime_constraints': {
315 'ram': (1024+256)*1024*1024
317 'use_existing': False,
322 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
323 stubs.api.workflows().create().execute.return_value = {
324 "uuid": stubs.expect_workflow_uuid,
326 def update_mock(**kwargs):
327 stubs.updated_uuid = kwargs.get('uuid')
329 stubs.api.workflows().update.side_effect = update_mock
330 stubs.api.workflows().update().execute.side_effect = lambda **kwargs: {
331 "uuid": stubs.updated_uuid,
334 return func(self, stubs, *args, **kwargs)
338 class TestSubmit(unittest.TestCase):
341 cwltool.process._names = set()
344 def test_error_when_multiple_storage_classes_specified(self, stubs):
345 storage_classes = "foo,bar"
346 exited = arvados_cwl.main(
347 ["--debug", "--storage-classes", storage_classes,
348 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
349 sys.stdin, sys.stderr, api_client=stubs.api)
350 self.assertEqual(exited, 1)
352 @mock.patch("time.sleep")
354 def test_submit_invalid_runner_ram(self, stubs, tm):
355 exited = arvados_cwl.main(
356 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048",
357 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
358 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
359 self.assertEqual(exited, 1)
363 def test_submit_container(self, stubs):
364 exited = arvados_cwl.main(
365 ["--submit", "--no-wait", "--api=containers", "--debug",
366 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
367 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
369 stubs.api.collections().create.assert_has_calls([
370 mock.call(body=JsonDiffMatcher({
372 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
373 'replication_desired': None,
374 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
375 }), ensure_unique_name=False),
376 mock.call(body=JsonDiffMatcher({
378 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
379 'replication_desired': None,
380 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
381 }), ensure_unique_name=False),
384 expect_container = copy.deepcopy(stubs.expect_container_spec)
385 stubs.api.container_requests().create.assert_called_with(
386 body=JsonDiffMatcher(expect_container))
387 self.assertEqual(stubs.capture_stdout.getvalue(),
388 stubs.expect_container_request_uuid + '\n')
389 self.assertEqual(exited, 0)
393 def test_submit_container_tool(self, stubs):
394 # test for issue #16139
395 exited = arvados_cwl.main(
396 ["--submit", "--no-wait", "--api=containers", "--debug",
397 "tests/tool/tool_with_sf.cwl", "tests/tool/tool_with_sf.yml"],
398 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
400 self.assertEqual(stubs.capture_stdout.getvalue(),
401 stubs.expect_container_request_uuid + '\n')
402 self.assertEqual(exited, 0)
405 def test_submit_container_no_reuse(self, stubs):
406 exited = arvados_cwl.main(
407 ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse",
408 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
409 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
411 expect_container = copy.deepcopy(stubs.expect_container_spec)
412 expect_container["command"] = [
413 'arvados-cwl-runner', '--local', '--api=containers',
414 '--no-log-timestamps', '--disable-validate',
415 '--eval-timeout=20', '--thread-count=1',
416 '--disable-reuse', "--collection-cache-size=256",
417 '--debug', '--on-error=continue',
418 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
419 expect_container["use_existing"] = False
421 stubs.api.container_requests().create.assert_called_with(
422 body=JsonDiffMatcher(expect_container))
423 self.assertEqual(stubs.capture_stdout.getvalue(),
424 stubs.expect_container_request_uuid + '\n')
425 self.assertEqual(exited, 0)
428 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
429 exited = arvados_cwl.main(
430 ["--submit", "--no-wait", "--api=containers", "--debug",
431 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
432 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
433 self.assertEqual(exited, 0)
435 expect_container = copy.deepcopy(stubs.expect_container_spec)
436 expect_container["command"] = [
437 'arvados-cwl-runner', '--local', '--api=containers',
438 '--no-log-timestamps', '--disable-validate',
439 '--eval-timeout=20', '--thread-count=1',
440 '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
441 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
442 expect_container["use_existing"] = False
443 expect_container["name"] = "submit_wf_no_reuse.cwl"
444 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
446 "class": "http://arvados.org/cwl#ReuseRequirement",
447 "enableReuse": False,
450 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
451 "arv": "http://arvados.org/cwl#",
452 "cwltool": "http://commonwl.org/cwltool#"
455 stubs.api.container_requests().create.assert_called_with(
456 body=JsonDiffMatcher(expect_container))
457 self.assertEqual(stubs.capture_stdout.getvalue(),
458 stubs.expect_container_request_uuid + '\n')
462 def test_submit_container_on_error(self, stubs):
463 exited = arvados_cwl.main(
464 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
465 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
466 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
468 expect_container = copy.deepcopy(stubs.expect_container_spec)
469 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
470 '--no-log-timestamps', '--disable-validate',
471 '--eval-timeout=20', '--thread-count=1',
472 '--enable-reuse', "--collection-cache-size=256",
473 '--debug', '--on-error=stop',
474 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
476 stubs.api.container_requests().create.assert_called_with(
477 body=JsonDiffMatcher(expect_container))
478 self.assertEqual(stubs.capture_stdout.getvalue(),
479 stubs.expect_container_request_uuid + '\n')
480 self.assertEqual(exited, 0)
483 def test_submit_container_output_name(self, stubs):
484 output_name = "test_output_name"
486 exited = arvados_cwl.main(
487 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
488 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
489 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
491 expect_container = copy.deepcopy(stubs.expect_container_spec)
492 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
493 '--no-log-timestamps', '--disable-validate',
494 '--eval-timeout=20', '--thread-count=1',
495 '--enable-reuse', "--collection-cache-size=256",
496 "--output-name="+output_name, '--debug', '--on-error=continue',
497 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
498 expect_container["output_name"] = output_name
500 stubs.api.container_requests().create.assert_called_with(
501 body=JsonDiffMatcher(expect_container))
502 self.assertEqual(stubs.capture_stdout.getvalue(),
503 stubs.expect_container_request_uuid + '\n')
504 self.assertEqual(exited, 0)
507 def test_submit_storage_classes(self, stubs):
508 exited = arvados_cwl.main(
509 ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo",
510 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
511 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
513 expect_container = copy.deepcopy(stubs.expect_container_spec)
514 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
515 '--no-log-timestamps', '--disable-validate',
516 '--eval-timeout=20', '--thread-count=1',
517 '--enable-reuse', "--collection-cache-size=256", "--debug",
518 "--storage-classes=foo", '--on-error=continue',
519 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
521 stubs.api.container_requests().create.assert_called_with(
522 body=JsonDiffMatcher(expect_container))
523 self.assertEqual(stubs.capture_stdout.getvalue(),
524 stubs.expect_container_request_uuid + '\n')
525 self.assertEqual(exited, 0)
527 @mock.patch("arvados_cwl.task_queue.TaskQueue")
528 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
529 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
531 def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
532 def set_final_output(job_order, output_callback, runtimeContext):
533 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
535 job.side_effect = set_final_output
537 exited = arvados_cwl.main(
538 ["--debug", "--local", "--storage-classes=foo",
539 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
540 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
542 make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
543 self.assertEqual(exited, 0)
545 @mock.patch("arvados_cwl.task_queue.TaskQueue")
546 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
547 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
549 def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
550 def set_final_output(job_order, output_callback, runtimeContext):
551 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
553 job.side_effect = set_final_output
555 exited = arvados_cwl.main(
556 ["--debug", "--local",
557 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
558 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
560 make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
561 self.assertEqual(exited, 0)
564 def test_submit_container_output_ttl(self, stubs):
565 exited = arvados_cwl.main(
566 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
567 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
568 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
570 expect_container = copy.deepcopy(stubs.expect_container_spec)
571 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
572 '--no-log-timestamps', '--disable-validate',
573 '--eval-timeout=20', '--thread-count=1',
574 '--enable-reuse', "--collection-cache-size=256", '--debug',
575 '--on-error=continue',
576 "--intermediate-output-ttl=3600",
577 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
579 stubs.api.container_requests().create.assert_called_with(
580 body=JsonDiffMatcher(expect_container))
581 self.assertEqual(stubs.capture_stdout.getvalue(),
582 stubs.expect_container_request_uuid + '\n')
583 self.assertEqual(exited, 0)
586 def test_submit_container_trash_intermediate(self, stubs):
587 exited = arvados_cwl.main(
588 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
589 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
590 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
593 expect_container = copy.deepcopy(stubs.expect_container_spec)
594 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
595 '--no-log-timestamps', '--disable-validate',
596 '--eval-timeout=20', '--thread-count=1',
597 '--enable-reuse', "--collection-cache-size=256",
598 '--debug', '--on-error=continue',
599 "--trash-intermediate",
600 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
602 stubs.api.container_requests().create.assert_called_with(
603 body=JsonDiffMatcher(expect_container))
604 self.assertEqual(stubs.capture_stdout.getvalue(),
605 stubs.expect_container_request_uuid + '\n')
606 self.assertEqual(exited, 0)
609 def test_submit_container_output_tags(self, stubs):
610 output_tags = "tag0,tag1,tag2"
612 exited = arvados_cwl.main(
613 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
614 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
615 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
617 expect_container = copy.deepcopy(stubs.expect_container_spec)
618 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
619 '--no-log-timestamps', '--disable-validate',
620 '--eval-timeout=20', '--thread-count=1',
621 '--enable-reuse', "--collection-cache-size=256",
622 "--output-tags="+output_tags, '--debug', '--on-error=continue',
623 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
625 stubs.api.container_requests().create.assert_called_with(
626 body=JsonDiffMatcher(expect_container))
627 self.assertEqual(stubs.capture_stdout.getvalue(),
628 stubs.expect_container_request_uuid + '\n')
629 self.assertEqual(exited, 0)
632 def test_submit_container_runner_ram(self, stubs):
633 exited = arvados_cwl.main(
634 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
635 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
636 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
638 expect_container = copy.deepcopy(stubs.expect_container_spec)
639 expect_container["runtime_constraints"]["ram"] = (2048+256)*1024*1024
641 stubs.api.container_requests().create.assert_called_with(
642 body=JsonDiffMatcher(expect_container))
643 self.assertEqual(stubs.capture_stdout.getvalue(),
644 stubs.expect_container_request_uuid + '\n')
645 self.assertEqual(exited, 0)
647 @mock.patch("arvados.collection.CollectionReader")
648 @mock.patch("time.sleep")
650 def test_submit_file_keepref(self, stubs, tm, collectionReader):
651 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt")
652 exited = arvados_cwl.main(
653 ["--submit", "--no-wait", "--api=containers", "--debug",
654 "tests/wf/submit_keepref_wf.cwl"],
655 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
656 self.assertEqual(exited, 0)
658 @mock.patch("arvados.collection.CollectionReader")
659 @mock.patch("time.sleep")
661 def test_submit_keepref(self, stubs, tm, reader):
662 with open("tests/wf/expect_arvworkflow.cwl") as f:
663 reader().open().__enter__().read.return_value = f.read()
665 exited = arvados_cwl.main(
666 ["--submit", "--no-wait", "--api=containers", "--debug",
667 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
668 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
678 'path': '/var/spool/cwl/cwl.output.json',
681 '/var/lib/cwl/workflow': {
682 'portable_data_hash': '99999999999999999999999999999994+99',
685 '/var/lib/cwl/cwl.input.json': {
691 }, 'state': 'Committed',
692 'output_path': '/var/spool/cwl',
693 'name': 'expect_arvworkflow.cwl#main',
694 'container_image': '999999999999999999999999999999d3+99',
695 'command': ['arvados-cwl-runner', '--local', '--api=containers',
696 '--no-log-timestamps', '--disable-validate',
697 '--eval-timeout=20', '--thread-count=1',
698 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
699 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
700 'cwd': '/var/spool/cwl',
701 'runtime_constraints': {
706 'use_existing': False,
711 stubs.api.container_requests().create.assert_called_with(
712 body=JsonDiffMatcher(expect_container))
713 self.assertEqual(stubs.capture_stdout.getvalue(),
714 stubs.expect_container_request_uuid + '\n')
715 self.assertEqual(exited, 0)
717 @mock.patch("time.sleep")
719 def test_submit_arvworkflow(self, stubs, tm):
720 with open("tests/wf/expect_arvworkflow.cwl") as f:
721 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
723 exited = arvados_cwl.main(
724 ["--submit", "--no-wait", "--api=containers", "--debug",
725 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
726 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
736 'path': '/var/spool/cwl/cwl.output.json',
739 '/var/lib/cwl/workflow.json': {
742 'cwlVersion': 'v1.0',
747 {'type': 'string', 'id': '#main/x'}
750 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
751 'run': '#submit_tool.cwl',
761 'inputBinding': {'position': 1},
763 'id': '#submit_tool.cwl/x'}
767 'dockerPull': 'debian:8',
768 'class': 'DockerRequirement',
769 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
772 'id': '#submit_tool.cwl',
774 'baseCommand': 'cat',
775 'class': 'CommandLineTool'
780 '/var/lib/cwl/cwl.input.json': {
786 }, 'state': 'Committed',
787 'output_path': '/var/spool/cwl',
788 'name': 'a test workflow',
789 'container_image': "999999999999999999999999999999d3+99",
790 'command': ['arvados-cwl-runner', '--local', '--api=containers',
791 '--no-log-timestamps', '--disable-validate',
792 '--eval-timeout=20', '--thread-count=1',
793 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
794 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
795 'cwd': '/var/spool/cwl',
796 'runtime_constraints': {
801 'use_existing': False,
803 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
808 stubs.api.container_requests().create.assert_called_with(
809 body=JsonDiffMatcher(expect_container))
810 self.assertEqual(stubs.capture_stdout.getvalue(),
811 stubs.expect_container_request_uuid + '\n')
812 self.assertEqual(exited, 0)
815 def test_submit_container_name(self, stubs):
816 exited = arvados_cwl.main(
817 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
818 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
819 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
821 expect_container = copy.deepcopy(stubs.expect_container_spec)
822 expect_container["name"] = "hello container 123"
824 stubs.api.container_requests().create.assert_called_with(
825 body=JsonDiffMatcher(expect_container))
826 self.assertEqual(stubs.capture_stdout.getvalue(),
827 stubs.expect_container_request_uuid + '\n')
828 self.assertEqual(exited, 0)
831 def test_submit_missing_input(self, stubs):
832 exited = arvados_cwl.main(
833 ["--submit", "--no-wait", "--api=containers", "--debug",
834 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
835 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
836 self.assertEqual(exited, 0)
838 exited = arvados_cwl.main(
839 ["--submit", "--no-wait", "--api=containers", "--debug",
840 "tests/wf/submit_wf.cwl", "tests/submit_test_job_missing.json"],
841 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
842 self.assertEqual(exited, 1)
845 def test_submit_container_project(self, stubs):
846 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
847 exited = arvados_cwl.main(
848 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
849 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
850 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
852 expect_container = copy.deepcopy(stubs.expect_container_spec)
853 expect_container["owner_uuid"] = project_uuid
854 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
855 '--no-log-timestamps', '--disable-validate',
856 "--eval-timeout=20", "--thread-count=1",
857 '--enable-reuse', "--collection-cache-size=256", '--debug',
858 '--on-error=continue',
859 '--project-uuid='+project_uuid,
860 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
862 stubs.api.container_requests().create.assert_called_with(
863 body=JsonDiffMatcher(expect_container))
864 self.assertEqual(stubs.capture_stdout.getvalue(),
865 stubs.expect_container_request_uuid + '\n')
866 self.assertEqual(exited, 0)
869 def test_submit_container_eval_timeout(self, stubs):
870 exited = arvados_cwl.main(
871 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
872 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
873 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
875 expect_container = copy.deepcopy(stubs.expect_container_spec)
876 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
877 '--no-log-timestamps', '--disable-validate',
878 '--eval-timeout=60.0', '--thread-count=1',
879 '--enable-reuse', "--collection-cache-size=256",
880 '--debug', '--on-error=continue',
881 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
883 stubs.api.container_requests().create.assert_called_with(
884 body=JsonDiffMatcher(expect_container))
885 self.assertEqual(stubs.capture_stdout.getvalue(),
886 stubs.expect_container_request_uuid + '\n')
887 self.assertEqual(exited, 0)
890 def test_submit_container_collection_cache(self, stubs):
891 exited = arvados_cwl.main(
892 ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500",
893 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
894 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
896 expect_container = copy.deepcopy(stubs.expect_container_spec)
897 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
898 '--no-log-timestamps', '--disable-validate',
899 '--eval-timeout=20', '--thread-count=1',
900 '--enable-reuse', "--collection-cache-size=500",
901 '--debug', '--on-error=continue',
902 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
903 expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024
905 stubs.api.container_requests().create.assert_called_with(
906 body=JsonDiffMatcher(expect_container))
907 self.assertEqual(stubs.capture_stdout.getvalue(),
908 stubs.expect_container_request_uuid + '\n')
909 self.assertEqual(exited, 0)
912 def test_submit_container_thread_count(self, stubs):
913 exited = arvados_cwl.main(
914 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
915 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
916 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
918 expect_container = copy.deepcopy(stubs.expect_container_spec)
919 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
920 '--no-log-timestamps', '--disable-validate',
921 '--eval-timeout=20', '--thread-count=20',
922 '--enable-reuse', "--collection-cache-size=256",
923 '--debug', '--on-error=continue',
924 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
926 stubs.api.container_requests().create.assert_called_with(
927 body=JsonDiffMatcher(expect_container))
928 self.assertEqual(stubs.capture_stdout.getvalue(),
929 stubs.expect_container_request_uuid + '\n')
930 self.assertEqual(exited, 0)
933 def test_submit_container_runner_image(self, stubs):
934 exited = arvados_cwl.main(
935 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
936 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
937 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
939 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
941 expect_container = copy.deepcopy(stubs.expect_container_spec)
942 stubs.api.container_requests().create.assert_called_with(
943 body=JsonDiffMatcher(expect_container))
944 self.assertEqual(stubs.capture_stdout.getvalue(),
945 stubs.expect_container_request_uuid + '\n')
946 self.assertEqual(exited, 0)
949 def test_submit_priority(self, stubs):
950 exited = arvados_cwl.main(
951 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
952 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
953 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
955 stubs.expect_container_spec["priority"] = 669
957 expect_container = copy.deepcopy(stubs.expect_container_spec)
958 stubs.api.container_requests().create.assert_called_with(
959 body=JsonDiffMatcher(expect_container))
960 self.assertEqual(stubs.capture_stdout.getvalue(),
961 stubs.expect_container_request_uuid + '\n')
962 self.assertEqual(exited, 0)
965 def test_submit_wf_runner_resources(self, stubs):
966 exited = arvados_cwl.main(
967 ["--submit", "--no-wait", "--api=containers", "--debug",
968 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
969 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
971 expect_container = copy.deepcopy(stubs.expect_container_spec)
972 expect_container["runtime_constraints"] = {
975 "ram": (2000+512) * 2**20
977 expect_container["name"] = "submit_wf_runner_resources.cwl"
978 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
980 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
986 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
987 "arv": "http://arvados.org/cwl#",
989 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
990 '--no-log-timestamps', '--disable-validate',
991 '--eval-timeout=20', '--thread-count=1',
992 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
993 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
995 stubs.api.container_requests().create.assert_called_with(
996 body=JsonDiffMatcher(expect_container))
997 self.assertEqual(stubs.capture_stdout.getvalue(),
998 stubs.expect_container_request_uuid + '\n')
999 self.assertEqual(exited, 0)
1002 arvados_cwl.arvdocker.arv_docker_clear_cache()
1004 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1005 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1006 @mock.patch("arvados.api")
1007 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1008 arvados_cwl.arvdocker.arv_docker_clear_cache()
1010 arvrunner = mock.MagicMock()
1011 arvrunner.project_uuid = ""
1012 api.return_value = mock.MagicMock()
1013 arvrunner.api = api.return_value
1014 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1015 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1016 "link_class": "docker_image_repo+tag",
1017 "name": "arvados/jobs:"+arvados_cwl.__version__,
1019 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1020 {"items": [{"created_at": "",
1022 "link_class": "docker_image_hash",
1025 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1027 find_one_image_hash.return_value = "123456"
1029 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1031 "manifest_text": "",
1033 }], "items_available": 1, "offset": 0},)
1034 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1035 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1036 "portable_data_hash": "9999999999999999999999999999999b+99"}
1037 self.assertEqual("9999999999999999999999999999999b+99",
1038 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1042 def test_submit_secrets(self, stubs):
1043 exited = arvados_cwl.main(
1044 ["--submit", "--no-wait", "--api=containers", "--debug",
1045 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1046 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1048 expect_container = {
1050 "arvados-cwl-runner",
1053 "--no-log-timestamps",
1054 "--disable-validate",
1055 "--eval-timeout=20",
1058 "--collection-cache-size=256",
1060 "--on-error=continue",
1061 "/var/lib/cwl/workflow.json#main",
1062 "/var/lib/cwl/cwl.input.json"
1064 "container_image": "999999999999999999999999999999d3+99",
1065 "cwd": "/var/spool/cwl",
1067 "/var/lib/cwl/cwl.input.json": {
1070 "$include": "/secrets/s0"
1075 "/var/lib/cwl/workflow.json": {
1080 "cwltool": "http://commonwl.org/cwltool#"
1086 "class": "CommandLineTool",
1089 "class": "http://commonwl.org/cwltool#Secrets",
1091 "#secret_job.cwl/pw"
1095 "id": "#secret_job.cwl",
1098 "id": "#secret_job.cwl/pw",
1104 "id": "#secret_job.cwl/out",
1108 "stdout": "hashed_example.txt",
1111 "class": "InitialWorkDirRequirement",
1114 "entry": "username: user\npassword: $(inputs.pw)\n",
1115 "entryname": "example.conf"
1122 "class": "Workflow",
1125 "class": "DockerRequirement",
1126 "dockerPull": "debian:8",
1127 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1130 "class": "http://commonwl.org/cwltool#Secrets",
1146 "outputSource": "#main/step1/out",
1152 "id": "#main/step1",
1155 "id": "#main/step1/pw",
1156 "source": "#main/pw"
1162 "run": "#secret_job.cwl"
1167 "cwlVersion": "v1.0"
1172 "kind": "collection",
1177 "path": "/var/spool/cwl/cwl.output.json"
1180 "name": "secret_wf.cwl",
1181 "output_path": "/var/spool/cwl",
1184 "runtime_constraints": {
1195 "state": "Committed",
1196 "use_existing": False
1199 stubs.api.container_requests().create.assert_called_with(
1200 body=JsonDiffMatcher(expect_container))
1201 self.assertEqual(stubs.capture_stdout.getvalue(),
1202 stubs.expect_container_request_uuid + '\n')
1203 self.assertEqual(exited, 0)
1206 def test_submit_request_uuid(self, stubs):
1207 stubs.api._rootDesc["remoteHosts"]["zzzzz"] = "123"
1208 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1210 stubs.api.container_requests().update().execute.return_value = {
1211 "uuid": stubs.expect_container_request_uuid,
1212 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1216 exited = arvados_cwl.main(
1217 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1218 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1219 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1221 stubs.api.container_requests().update.assert_called_with(
1222 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec))
1223 self.assertEqual(stubs.capture_stdout.getvalue(),
1224 stubs.expect_container_request_uuid + '\n')
1225 self.assertEqual(exited, 0)
1228 def test_submit_container_cluster_id(self, stubs):
1229 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1231 exited = arvados_cwl.main(
1232 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1233 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1234 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1236 expect_container = copy.deepcopy(stubs.expect_container_spec)
1238 stubs.api.container_requests().create.assert_called_with(
1239 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1240 self.assertEqual(stubs.capture_stdout.getvalue(),
1241 stubs.expect_container_request_uuid + '\n')
1242 self.assertEqual(exited, 0)
1245 def test_submit_validate_cluster_id(self, stubs):
1246 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1247 exited = arvados_cwl.main(
1248 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1249 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1250 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1251 self.assertEqual(exited, 1)
1253 @mock.patch("arvados.collection.CollectionReader")
1255 def test_submit_uuid_inputs(self, stubs, collectionReader):
1256 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt")
1257 def list_side_effect(**kwargs):
1258 m = mock.MagicMock()
1259 if "count" in kwargs:
1260 m.execute.return_value = {"items": [
1261 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999998+99"}
1264 m.execute.return_value = {"items": []}
1266 stubs.api.collections().list.side_effect = list_side_effect
1268 exited = arvados_cwl.main(
1269 ["--submit", "--no-wait", "--api=containers", "--debug",
1270 "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"],
1271 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1273 expect_container = copy.deepcopy(stubs.expect_container_spec)
1274 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['basename'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1275 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1276 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['z']['listing'][0]['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1278 stubs.api.collections().list.assert_has_calls([
1279 mock.call(count='none',
1280 filters=[['uuid', 'in', ['zzzzz-4zz18-zzzzzzzzzzzzzzz']]],
1281 select=['uuid', 'portable_data_hash'])])
1282 stubs.api.container_requests().create.assert_called_with(
1283 body=JsonDiffMatcher(expect_container))
1284 self.assertEqual(stubs.capture_stdout.getvalue(),
1285 stubs.expect_container_request_uuid + '\n')
1286 self.assertEqual(exited, 0)
1289 def test_submit_mismatched_uuid_inputs(self, stubs):
1290 def list_side_effect(**kwargs):
1291 m = mock.MagicMock()
1292 if "count" in kwargs:
1293 m.execute.return_value = {"items": [
1294 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999997+99"}
1297 m.execute.return_value = {"items": []}
1299 stubs.api.collections().list.side_effect = list_side_effect
1301 for infile in ("tests/submit_test_job_with_mismatched_uuids.json", "tests/submit_test_job_with_inconsistent_uuids.json"):
1302 capture_stderr = StringIO()
1303 cwltool_logger = logging.getLogger('cwltool')
1304 stderr_logger = logging.StreamHandler(capture_stderr)
1305 cwltool_logger.addHandler(stderr_logger)
1308 exited = arvados_cwl.main(
1309 ["--submit", "--no-wait", "--api=containers", "--debug",
1310 "tests/wf/submit_wf.cwl", infile],
1311 stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1313 self.assertEqual(exited, 1)
1314 self.assertRegexpMatches(
1315 capture_stderr.getvalue(),
1316 r"Expected collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz to be 99999999999999999999999999999998\+99 but API server reported 99999999999999999999999999999997\+99")
1318 cwltool_logger.removeHandler(stderr_logger)
1320 @mock.patch("arvados.collection.CollectionReader")
1322 def test_submit_unknown_uuid_inputs(self, stubs, collectionReader):
1323 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt")
1324 capture_stderr = StringIO()
1326 cwltool_logger = logging.getLogger('cwltool')
1327 stderr_logger = logging.StreamHandler(capture_stderr)
1328 cwltool_logger.addHandler(stderr_logger)
1330 exited = arvados_cwl.main(
1331 ["--submit", "--no-wait", "--api=containers", "--debug",
1332 "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"],
1333 stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1336 self.assertEqual(exited, 1)
1337 self.assertRegexpMatches(
1338 capture_stderr.getvalue(),
1339 r"Collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz not found")
1341 cwltool_logger.removeHandler(stderr_logger)
1344 class TestCreateWorkflow(unittest.TestCase):
1345 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1346 expect_workflow = StripYAMLComments(
1347 open("tests/wf/expect_packed.cwl").read())
1350 def test_create(self, stubs):
1351 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1353 exited = arvados_cwl.main(
1354 ["--create-workflow", "--debug",
1356 "--project-uuid", project_uuid,
1357 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1358 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1360 stubs.api.pipeline_templates().create.refute_called()
1361 stubs.api.container_requests().create.refute_called()
1365 "owner_uuid": project_uuid,
1366 "name": "submit_wf.cwl",
1368 "definition": self.expect_workflow,
1371 stubs.api.workflows().create.assert_called_with(
1372 body=JsonDiffMatcher(body))
1374 self.assertEqual(stubs.capture_stdout.getvalue(),
1375 stubs.expect_workflow_uuid + '\n')
1376 self.assertEqual(exited, 0)
1379 def test_create_name(self, stubs):
1380 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1382 exited = arvados_cwl.main(
1383 ["--create-workflow", "--debug",
1385 "--project-uuid", project_uuid,
1386 "--name", "testing 123",
1387 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1388 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1390 stubs.api.pipeline_templates().create.refute_called()
1391 stubs.api.container_requests().create.refute_called()
1395 "owner_uuid": project_uuid,
1396 "name": "testing 123",
1398 "definition": self.expect_workflow,
1401 stubs.api.workflows().create.assert_called_with(
1402 body=JsonDiffMatcher(body))
1404 self.assertEqual(stubs.capture_stdout.getvalue(),
1405 stubs.expect_workflow_uuid + '\n')
1406 self.assertEqual(exited, 0)
1410 def test_update(self, stubs):
1411 exited = arvados_cwl.main(
1412 ["--update-workflow", self.existing_workflow_uuid,
1414 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1415 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1419 "name": "submit_wf.cwl",
1421 "definition": self.expect_workflow,
1424 stubs.api.workflows().update.assert_called_with(
1425 uuid=self.existing_workflow_uuid,
1426 body=JsonDiffMatcher(body))
1427 self.assertEqual(stubs.capture_stdout.getvalue(),
1428 self.existing_workflow_uuid + '\n')
1429 self.assertEqual(exited, 0)
1432 def test_update_name(self, stubs):
1433 exited = arvados_cwl.main(
1434 ["--update-workflow", self.existing_workflow_uuid,
1435 "--debug", "--name", "testing 123",
1436 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1437 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1441 "name": "testing 123",
1443 "definition": self.expect_workflow,
1446 stubs.api.workflows().update.assert_called_with(
1447 uuid=self.existing_workflow_uuid,
1448 body=JsonDiffMatcher(body))
1449 self.assertEqual(stubs.capture_stdout.getvalue(),
1450 self.existing_workflow_uuid + '\n')
1451 self.assertEqual(exited, 0)
1454 def test_create_collection_per_tool(self, stubs):
1455 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1457 exited = arvados_cwl.main(
1458 ["--create-workflow", "--debug",
1460 "--project-uuid", project_uuid,
1461 "tests/collection_per_tool/collection_per_tool.cwl"],
1462 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1464 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1465 expect_workflow = StripYAMLComments(open(toolfile).read())
1469 "owner_uuid": project_uuid,
1470 "name": "collection_per_tool.cwl",
1472 "definition": expect_workflow,
1475 stubs.api.workflows().create.assert_called_with(
1476 body=JsonDiffMatcher(body))
1478 self.assertEqual(stubs.capture_stdout.getvalue(),
1479 stubs.expect_workflow_uuid + '\n')
1480 self.assertEqual(exited, 0)
1483 def test_create_with_imports(self, stubs):
1484 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1486 exited = arvados_cwl.main(
1487 ["--create-workflow", "--debug",
1489 "--project-uuid", project_uuid,
1490 "tests/wf/feddemo/feddemo.cwl"],
1491 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1493 stubs.api.pipeline_templates().create.refute_called()
1494 stubs.api.container_requests().create.refute_called()
1496 self.assertEqual(stubs.capture_stdout.getvalue(),
1497 stubs.expect_workflow_uuid + '\n')
1498 self.assertEqual(exited, 0)
1501 def test_create_with_no_input(self, stubs):
1502 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1504 exited = arvados_cwl.main(
1505 ["--create-workflow", "--debug",
1507 "--project-uuid", project_uuid,
1508 "tests/wf/revsort/revsort.cwl"],
1509 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1511 stubs.api.pipeline_templates().create.refute_called()
1512 stubs.api.container_requests().create.refute_called()
1514 self.assertEqual(stubs.capture_stdout.getvalue(),
1515 stubs.expect_workflow_uuid + '\n')
1516 self.assertEqual(exited, 0)