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
23 from io import BytesIO
25 # StringIO.StringIO and io.StringIO have different behavior write() is
26 # called with both python2 (byte) strings and unicode strings
27 # (specifically there's some logging in cwltool that causes trouble).
28 # This isn't a problem on python3 because all string are unicode.
29 if sys.version_info[0] < 3:
30 from StringIO import StringIO
32 from io import StringIO
35 import arvados.collection
37 import arvados_cwl.executor
38 import arvados_cwl.runner
41 from .matcher import JsonDiffMatcher, StripYAMLComments
42 from .mock_discovery import get_rootDesc
44 import ruamel.yaml as yaml
49 @functools.wraps(func)
50 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
51 @mock.patch("arvados.collection.KeepClient")
52 @mock.patch("arvados.keep.KeepClient")
53 @mock.patch("arvados.events.subscribe")
54 def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs):
59 stubs.keepdocker = keepdocker
61 def putstub(p, **kwargs):
62 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
63 keep_client1().put.side_effect = putstub
64 keep_client1.put.side_effect = putstub
65 keep_client2().put.side_effect = putstub
66 keep_client2.put.side_effect = putstub
68 stubs.keep_client = keep_client2
69 stubs.docker_images = {
70 "arvados/jobs:"+arvados_cwl.__version__: [("zzzzz-4zz18-zzzzzzzzzzzzzd3", "")],
71 "debian:buster-slim": [("zzzzz-4zz18-zzzzzzzzzzzzzd4", "")],
72 "arvados/jobs:123": [("zzzzz-4zz18-zzzzzzzzzzzzzd5", "")],
73 "arvados/jobs:latest": [("zzzzz-4zz18-zzzzzzzzzzzzzd6", "")],
75 def kd(a, b, image_name=None, image_tag=None):
76 return stubs.docker_images.get("%s:%s" % (image_name, image_tag), [])
77 stubs.keepdocker.side_effect = kd
79 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
80 stubs.fake_container_uuid = "zzzzz-dz642-zzzzzzzzzzzzzzz"
82 if sys.version_info[0] < 3:
83 stubs.capture_stdout = BytesIO()
85 stubs.capture_stdout = StringIO()
87 stubs.api = mock.MagicMock()
88 stubs.api._rootDesc = get_rootDesc()
89 stubs.api._rootDesc["uuidPrefix"] = "zzzzz"
91 stubs.api.users().current().execute.return_value = {
92 "uuid": stubs.fake_user_uuid,
94 stubs.api.collections().list().execute.return_value = {"items": []}
95 stubs.api.containers().current().execute.return_value = {
96 "uuid": stubs.fake_container_uuid,
99 class CollectionExecute(object):
100 def __init__(self, exe):
102 def execute(self, num_retries=None):
105 def collection_createstub(created_collections, body, ensure_unique_name=None):
106 mt = body["manifest_text"].encode('utf-8')
107 uuid = "zzzzz-4zz18-zzzzzzzzzzzzzx%d" % len(created_collections)
108 pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt))
109 created_collections[uuid] = {
111 "portable_data_hash": pdh,
112 "manifest_text": mt.decode('utf-8')
114 return CollectionExecute(created_collections[uuid])
116 def collection_getstub(created_collections, uuid):
117 for v in viewvalues(created_collections):
118 if uuid in (v["uuid"], v["portable_data_hash"]):
119 return CollectionExecute(v)
121 created_collections = {
122 "99999999999999999999999999999998+99": {
124 "portable_data_hash": "99999999999999999999999999999998+99",
125 "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt"
127 "99999999999999999999999999999997+99": {
129 "portable_data_hash": "99999999999999999999999999999997+99",
130 "manifest_text": ". 99999999999999999999999999999997+99 0:0:file1.txt"
132 "99999999999999999999999999999994+99": {
134 "portable_data_hash": "99999999999999999999999999999994+99",
135 "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl"
137 "zzzzz-4zz18-zzzzzzzzzzzzzd3": {
138 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd3",
139 "portable_data_hash": "999999999999999999999999999999d3+99",
142 "zzzzz-4zz18-zzzzzzzzzzzzzd4": {
143 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd4",
144 "portable_data_hash": "999999999999999999999999999999d4+99",
147 "zzzzz-4zz18-zzzzzzzzzzzzzd5": {
148 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd5",
149 "portable_data_hash": "999999999999999999999999999999d5+99",
152 "zzzzz-4zz18-zzzzzzzzzzzzzd6": {
153 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd6",
154 "portable_data_hash": "999999999999999999999999999999d6+99",
158 stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections)
159 stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections)
161 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
162 stubs.api.jobs().create().execute.return_value = {
163 "uuid": stubs.expect_job_uuid,
167 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
168 stubs.api.container_requests().create().execute.return_value = {
169 "uuid": stubs.expect_container_request_uuid,
170 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
174 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
175 stubs.api.pipeline_templates().create().execute.return_value = {
176 "uuid": stubs.expect_pipeline_template_uuid,
178 stubs.expect_job_spec = {
179 'runtime_constraints': {
180 'docker_image': '999999999999999999999999999999d3+99',
181 'min_ram_mb_per_node': 1024
183 'script_parameters': {
185 'basename': 'blorp.txt',
186 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
190 'basename': '99999999999999999999999999999998+99',
191 'location': 'keep:99999999999999999999999999999998+99',
195 'basename': 'anonymous',
197 "basename": "renamed.txt",
199 "location": "keep:99999999999999999999999999999998+99/file1.txt",
204 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main'
206 'repository': 'arvados',
207 'script_version': 'master',
208 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
209 'script': 'cwl-runner'
211 stubs.pipeline_component = stubs.expect_job_spec.copy()
212 stubs.expect_pipeline_instance = {
213 'name': 'submit_wf.cwl',
214 'state': 'RunningOnServer',
218 'runtime_constraints': {'docker_image': '999999999999999999999999999999d3+99', 'min_ram_mb_per_node': 1024},
219 'script_parameters': {
220 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}},
222 'basename': 'blorp.txt',
224 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
227 'z': {"value": {'basename': 'anonymous', 'class': 'Directory',
230 'basename': 'renamed.txt',
231 'class': 'File', 'location':
232 'keep:99999999999999999999999999999998+99/file1.txt',
236 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main',
238 'arv:enable_reuse': True,
239 'arv:on_error': 'continue'
241 'repository': 'arvados',
242 'script_version': 'master',
243 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
244 'script': 'cwl-runner',
245 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'}
249 stubs.pipeline_create = copy.deepcopy(stubs.expect_pipeline_instance)
250 stubs.expect_pipeline_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
251 stubs.pipeline_create["uuid"] = stubs.expect_pipeline_uuid
252 stubs.pipeline_with_job = copy.deepcopy(stubs.pipeline_create)
253 stubs.pipeline_with_job["components"]["cwl-runner"]["job"] = {
254 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
257 stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create
258 stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job
260 with open("tests/wf/submit_wf_packed.cwl") as f:
261 expect_packed_workflow = yaml.round_trip_load(f)
263 stubs.expect_container_spec = {
270 '/var/lib/cwl/workflow.json': {
271 'content': expect_packed_workflow,
275 'path': '/var/spool/cwl/cwl.output.json',
278 '/var/lib/cwl/cwl.input.json': {
282 'basename': '99999999999999999999999999999998+99',
283 'location': 'keep:99999999999999999999999999999998+99',
284 'class': 'Directory'},
286 'basename': u'blorp.txt',
288 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
291 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [
292 {'basename': 'renamed.txt',
294 'location': 'keep:99999999999999999999999999999998+99/file1.txt',
303 'state': 'Committed',
304 'command': ['arvados-cwl-runner', '--local', '--api=containers',
305 '--no-log-timestamps', '--disable-validate', '--disable-color',
306 '--eval-timeout=20', '--thread-count=0',
307 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
308 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
309 'name': 'submit_wf.cwl',
310 'container_image': '999999999999999999999999999999d3+99',
311 'output_path': '/var/spool/cwl',
312 'cwd': '/var/spool/cwl',
313 'runtime_constraints': {
316 'ram': (1024+256)*1024*1024
318 'use_existing': False,
323 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
324 stubs.api.workflows().create().execute.return_value = {
325 "uuid": stubs.expect_workflow_uuid,
327 def update_mock(**kwargs):
328 stubs.updated_uuid = kwargs.get('uuid')
330 stubs.api.workflows().update.side_effect = update_mock
331 stubs.api.workflows().update().execute.side_effect = lambda **kwargs: {
332 "uuid": stubs.updated_uuid,
335 return func(self, stubs, *args, **kwargs)
339 class TestSubmit(unittest.TestCase):
342 cwltool.process._names = set()
343 arvados_cwl.arvdocker.arv_docker_clear_cache()
346 def test_error_when_multiple_storage_classes_specified(self, stubs):
347 storage_classes = "foo,bar"
348 exited = arvados_cwl.main(
349 ["--debug", "--storage-classes", storage_classes,
350 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
351 sys.stdin, sys.stderr, api_client=stubs.api)
352 self.assertEqual(exited, 1)
354 @mock.patch("time.sleep")
356 def test_submit_invalid_runner_ram(self, stubs, tm):
357 exited = arvados_cwl.main(
358 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048",
359 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
360 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
361 self.assertEqual(exited, 1)
365 def test_submit_container(self, stubs):
366 exited = arvados_cwl.main(
367 ["--submit", "--no-wait", "--api=containers", "--debug",
368 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
369 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
371 stubs.api.collections().create.assert_has_calls([
372 mock.call(body=JsonDiffMatcher({
374 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
375 'replication_desired': None,
376 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
377 }), ensure_unique_name=False),
378 mock.call(body=JsonDiffMatcher({
380 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
381 'replication_desired': None,
382 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
383 }), ensure_unique_name=False),
386 expect_container = copy.deepcopy(stubs.expect_container_spec)
387 stubs.api.container_requests().create.assert_called_with(
388 body=JsonDiffMatcher(expect_container))
389 self.assertEqual(stubs.capture_stdout.getvalue(),
390 stubs.expect_container_request_uuid + '\n')
391 self.assertEqual(exited, 0)
395 def test_submit_container_tool(self, stubs):
396 # test for issue #16139
397 exited = arvados_cwl.main(
398 ["--submit", "--no-wait", "--api=containers", "--debug",
399 "tests/tool/tool_with_sf.cwl", "tests/tool/tool_with_sf.yml"],
400 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
402 self.assertEqual(stubs.capture_stdout.getvalue(),
403 stubs.expect_container_request_uuid + '\n')
404 self.assertEqual(exited, 0)
407 def test_submit_container_no_reuse(self, stubs):
408 exited = arvados_cwl.main(
409 ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse",
410 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
411 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
413 expect_container = copy.deepcopy(stubs.expect_container_spec)
414 expect_container["command"] = [
415 'arvados-cwl-runner', '--local', '--api=containers',
416 '--no-log-timestamps', '--disable-validate', '--disable-color',
417 '--eval-timeout=20', '--thread-count=0',
418 '--disable-reuse', "--collection-cache-size=256",
419 '--debug', '--on-error=continue',
420 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
421 expect_container["use_existing"] = False
423 stubs.api.container_requests().create.assert_called_with(
424 body=JsonDiffMatcher(expect_container))
425 self.assertEqual(stubs.capture_stdout.getvalue(),
426 stubs.expect_container_request_uuid + '\n')
427 self.assertEqual(exited, 0)
430 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
431 exited = arvados_cwl.main(
432 ["--submit", "--no-wait", "--api=containers", "--debug",
433 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
434 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
435 self.assertEqual(exited, 0)
437 expect_container = copy.deepcopy(stubs.expect_container_spec)
438 expect_container["command"] = [
439 'arvados-cwl-runner', '--local', '--api=containers',
440 '--no-log-timestamps', '--disable-validate', '--disable-color',
441 '--eval-timeout=20', '--thread-count=0',
442 '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
443 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
444 expect_container["use_existing"] = False
445 expect_container["name"] = "submit_wf_no_reuse.cwl"
446 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
448 "class": "http://arvados.org/cwl#ReuseRequirement",
449 "enableReuse": False,
452 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
453 "arv": "http://arvados.org/cwl#",
454 "cwltool": "http://commonwl.org/cwltool#"
457 stubs.api.container_requests().create.assert_called_with(
458 body=JsonDiffMatcher(expect_container))
459 self.assertEqual(stubs.capture_stdout.getvalue(),
460 stubs.expect_container_request_uuid + '\n')
464 def test_submit_container_on_error(self, stubs):
465 exited = arvados_cwl.main(
466 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
467 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
468 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
470 expect_container = copy.deepcopy(stubs.expect_container_spec)
471 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
472 '--no-log-timestamps', '--disable-validate', '--disable-color',
473 '--eval-timeout=20', '--thread-count=0',
474 '--enable-reuse', "--collection-cache-size=256",
475 '--debug', '--on-error=stop',
476 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
478 stubs.api.container_requests().create.assert_called_with(
479 body=JsonDiffMatcher(expect_container))
480 self.assertEqual(stubs.capture_stdout.getvalue(),
481 stubs.expect_container_request_uuid + '\n')
482 self.assertEqual(exited, 0)
485 def test_submit_container_output_name(self, stubs):
486 output_name = "test_output_name"
488 exited = arvados_cwl.main(
489 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
490 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
491 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
493 expect_container = copy.deepcopy(stubs.expect_container_spec)
494 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
495 '--no-log-timestamps', '--disable-validate', '--disable-color',
496 '--eval-timeout=20', '--thread-count=0',
497 '--enable-reuse', "--collection-cache-size=256",
498 "--output-name="+output_name, '--debug', '--on-error=continue',
499 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
500 expect_container["output_name"] = output_name
502 stubs.api.container_requests().create.assert_called_with(
503 body=JsonDiffMatcher(expect_container))
504 self.assertEqual(stubs.capture_stdout.getvalue(),
505 stubs.expect_container_request_uuid + '\n')
506 self.assertEqual(exited, 0)
509 def test_submit_storage_classes(self, stubs):
510 exited = arvados_cwl.main(
511 ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo",
512 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
513 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
515 expect_container = copy.deepcopy(stubs.expect_container_spec)
516 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
517 '--no-log-timestamps', '--disable-validate', '--disable-color',
518 '--eval-timeout=20', '--thread-count=0',
519 '--enable-reuse', "--collection-cache-size=256", "--debug",
520 "--storage-classes=foo", '--on-error=continue',
521 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
523 stubs.api.container_requests().create.assert_called_with(
524 body=JsonDiffMatcher(expect_container))
525 self.assertEqual(stubs.capture_stdout.getvalue(),
526 stubs.expect_container_request_uuid + '\n')
527 self.assertEqual(exited, 0)
529 @mock.patch("cwltool.task_queue.TaskQueue")
530 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
531 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection")
533 def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
534 final_output_c = arvados.collection.Collection()
535 make_output.return_value = ({},final_output_c)
537 def set_final_output(job_order, output_callback, runtimeContext):
538 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
540 job.side_effect = set_final_output
542 exited = arvados_cwl.main(
543 ["--debug", "--local", "--storage-classes=foo",
544 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
545 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
547 make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
548 self.assertEqual(exited, 0)
550 @mock.patch("cwltool.task_queue.TaskQueue")
551 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
552 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection")
554 def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
555 final_output_c = arvados.collection.Collection()
556 make_output.return_value = ({},final_output_c)
558 def set_final_output(job_order, output_callback, runtimeContext):
559 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
561 job.side_effect = set_final_output
563 exited = arvados_cwl.main(
564 ["--debug", "--local",
565 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
566 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
568 make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
569 self.assertEqual(exited, 0)
572 def test_submit_container_output_ttl(self, stubs):
573 exited = arvados_cwl.main(
574 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
575 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
576 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
578 expect_container = copy.deepcopy(stubs.expect_container_spec)
579 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
580 '--no-log-timestamps', '--disable-validate', '--disable-color',
581 '--eval-timeout=20', '--thread-count=0',
582 '--enable-reuse', "--collection-cache-size=256", '--debug',
583 '--on-error=continue',
584 "--intermediate-output-ttl=3600",
585 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
587 stubs.api.container_requests().create.assert_called_with(
588 body=JsonDiffMatcher(expect_container))
589 self.assertEqual(stubs.capture_stdout.getvalue(),
590 stubs.expect_container_request_uuid + '\n')
591 self.assertEqual(exited, 0)
594 def test_submit_container_trash_intermediate(self, stubs):
595 exited = arvados_cwl.main(
596 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
597 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
598 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
601 expect_container = copy.deepcopy(stubs.expect_container_spec)
602 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
603 '--no-log-timestamps', '--disable-validate', '--disable-color',
604 '--eval-timeout=20', '--thread-count=0',
605 '--enable-reuse', "--collection-cache-size=256",
606 '--debug', '--on-error=continue',
607 "--trash-intermediate",
608 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
610 stubs.api.container_requests().create.assert_called_with(
611 body=JsonDiffMatcher(expect_container))
612 self.assertEqual(stubs.capture_stdout.getvalue(),
613 stubs.expect_container_request_uuid + '\n')
614 self.assertEqual(exited, 0)
617 def test_submit_container_output_tags(self, stubs):
618 output_tags = "tag0,tag1,tag2"
620 exited = arvados_cwl.main(
621 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
622 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
623 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
625 expect_container = copy.deepcopy(stubs.expect_container_spec)
626 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
627 '--no-log-timestamps', '--disable-validate', '--disable-color',
628 '--eval-timeout=20', '--thread-count=0',
629 '--enable-reuse', "--collection-cache-size=256",
630 "--output-tags="+output_tags, '--debug', '--on-error=continue',
631 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
633 stubs.api.container_requests().create.assert_called_with(
634 body=JsonDiffMatcher(expect_container))
635 self.assertEqual(stubs.capture_stdout.getvalue(),
636 stubs.expect_container_request_uuid + '\n')
637 self.assertEqual(exited, 0)
640 def test_submit_container_runner_ram(self, stubs):
641 exited = arvados_cwl.main(
642 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
643 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
644 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
646 expect_container = copy.deepcopy(stubs.expect_container_spec)
647 expect_container["runtime_constraints"]["ram"] = (2048+256)*1024*1024
649 stubs.api.container_requests().create.assert_called_with(
650 body=JsonDiffMatcher(expect_container))
651 self.assertEqual(stubs.capture_stdout.getvalue(),
652 stubs.expect_container_request_uuid + '\n')
653 self.assertEqual(exited, 0)
655 @mock.patch("arvados.collection.CollectionReader")
656 @mock.patch("time.sleep")
658 def test_submit_file_keepref(self, stubs, tm, collectionReader):
659 collectionReader().exists.return_value = True
660 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt")
661 exited = arvados_cwl.main(
662 ["--submit", "--no-wait", "--api=containers", "--debug",
663 "tests/wf/submit_keepref_wf.cwl"],
664 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
665 self.assertEqual(exited, 0)
667 @mock.patch("arvados.collection.CollectionReader")
668 @mock.patch("time.sleep")
670 def test_submit_keepref(self, stubs, tm, reader):
671 with open("tests/wf/expect_arvworkflow.cwl") as f:
672 reader().open().__enter__().read.return_value = f.read()
674 exited = arvados_cwl.main(
675 ["--submit", "--no-wait", "--api=containers", "--debug",
676 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
677 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
687 'path': '/var/spool/cwl/cwl.output.json',
690 '/var/lib/cwl/workflow': {
691 'portable_data_hash': '99999999999999999999999999999994+99',
694 '/var/lib/cwl/cwl.input.json': {
700 }, 'state': 'Committed',
701 'output_path': '/var/spool/cwl',
702 'name': 'expect_arvworkflow.cwl#main',
703 'container_image': '999999999999999999999999999999d3+99',
704 'command': ['arvados-cwl-runner', '--local', '--api=containers',
705 '--no-log-timestamps', '--disable-validate', '--disable-color',
706 '--eval-timeout=20', '--thread-count=0',
707 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
708 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
709 'cwd': '/var/spool/cwl',
710 'runtime_constraints': {
715 'use_existing': False,
720 stubs.api.container_requests().create.assert_called_with(
721 body=JsonDiffMatcher(expect_container))
722 self.assertEqual(stubs.capture_stdout.getvalue(),
723 stubs.expect_container_request_uuid + '\n')
724 self.assertEqual(exited, 0)
726 @mock.patch("time.sleep")
728 def test_submit_arvworkflow(self, stubs, tm):
729 with open("tests/wf/expect_arvworkflow.cwl") as f:
730 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
732 exited = arvados_cwl.main(
733 ["--submit", "--no-wait", "--api=containers", "--debug",
734 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
735 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
745 'path': '/var/spool/cwl/cwl.output.json',
748 '/var/lib/cwl/workflow.json': {
751 'cwlVersion': 'v1.0',
756 {'type': 'string', 'id': '#main/x'}
759 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
760 'run': '#submit_tool.cwl',
770 'inputBinding': {'position': 1},
772 'id': '#submit_tool.cwl/x'}
776 'dockerPull': 'debian:buster-slim',
777 'class': 'DockerRequirement',
778 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
781 'id': '#submit_tool.cwl',
783 'baseCommand': 'cat',
784 'class': 'CommandLineTool'
789 '/var/lib/cwl/cwl.input.json': {
795 }, 'state': 'Committed',
796 'output_path': '/var/spool/cwl',
797 'name': 'a test workflow',
798 'container_image': "999999999999999999999999999999d3+99",
799 'command': ['arvados-cwl-runner', '--local', '--api=containers',
800 '--no-log-timestamps', '--disable-validate', '--disable-color',
801 '--eval-timeout=20', '--thread-count=0',
802 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
803 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
804 'cwd': '/var/spool/cwl',
805 'runtime_constraints': {
810 'use_existing': False,
812 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
817 stubs.api.container_requests().create.assert_called_with(
818 body=JsonDiffMatcher(expect_container))
819 self.assertEqual(stubs.capture_stdout.getvalue(),
820 stubs.expect_container_request_uuid + '\n')
821 self.assertEqual(exited, 0)
824 def test_submit_container_name(self, stubs):
825 exited = arvados_cwl.main(
826 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
827 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
828 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
830 expect_container = copy.deepcopy(stubs.expect_container_spec)
831 expect_container["name"] = "hello container 123"
833 stubs.api.container_requests().create.assert_called_with(
834 body=JsonDiffMatcher(expect_container))
835 self.assertEqual(stubs.capture_stdout.getvalue(),
836 stubs.expect_container_request_uuid + '\n')
837 self.assertEqual(exited, 0)
840 def test_submit_missing_input(self, stubs):
841 exited = arvados_cwl.main(
842 ["--submit", "--no-wait", "--api=containers", "--debug",
843 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
844 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
845 self.assertEqual(exited, 0)
847 exited = arvados_cwl.main(
848 ["--submit", "--no-wait", "--api=containers", "--debug",
849 "tests/wf/submit_wf.cwl", "tests/submit_test_job_missing.json"],
850 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
851 self.assertEqual(exited, 1)
854 def test_submit_container_project(self, stubs):
855 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
856 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
857 exited = arvados_cwl.main(
858 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
859 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
860 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
862 expect_container = copy.deepcopy(stubs.expect_container_spec)
863 expect_container["owner_uuid"] = project_uuid
864 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
865 '--no-log-timestamps', '--disable-validate', '--disable-color',
866 "--eval-timeout=20", "--thread-count=0",
867 '--enable-reuse', "--collection-cache-size=256", '--debug',
868 '--on-error=continue',
869 '--project-uuid='+project_uuid,
870 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
872 stubs.api.container_requests().create.assert_called_with(
873 body=JsonDiffMatcher(expect_container))
874 self.assertEqual(stubs.capture_stdout.getvalue(),
875 stubs.expect_container_request_uuid + '\n')
876 self.assertEqual(exited, 0)
879 def test_submit_container_eval_timeout(self, stubs):
880 exited = arvados_cwl.main(
881 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
882 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
883 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
885 expect_container = copy.deepcopy(stubs.expect_container_spec)
886 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
887 '--no-log-timestamps', '--disable-validate', '--disable-color',
888 '--eval-timeout=60.0', '--thread-count=0',
889 '--enable-reuse', "--collection-cache-size=256",
890 '--debug', '--on-error=continue',
891 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
893 stubs.api.container_requests().create.assert_called_with(
894 body=JsonDiffMatcher(expect_container))
895 self.assertEqual(stubs.capture_stdout.getvalue(),
896 stubs.expect_container_request_uuid + '\n')
897 self.assertEqual(exited, 0)
900 def test_submit_container_collection_cache(self, stubs):
901 exited = arvados_cwl.main(
902 ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500",
903 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
904 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
906 expect_container = copy.deepcopy(stubs.expect_container_spec)
907 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
908 '--no-log-timestamps', '--disable-validate', '--disable-color',
909 '--eval-timeout=20', '--thread-count=0',
910 '--enable-reuse', "--collection-cache-size=500",
911 '--debug', '--on-error=continue',
912 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
913 expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024
915 stubs.api.container_requests().create.assert_called_with(
916 body=JsonDiffMatcher(expect_container))
917 self.assertEqual(stubs.capture_stdout.getvalue(),
918 stubs.expect_container_request_uuid + '\n')
919 self.assertEqual(exited, 0)
922 def test_submit_container_thread_count(self, stubs):
923 exited = arvados_cwl.main(
924 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
925 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
926 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
928 expect_container = copy.deepcopy(stubs.expect_container_spec)
929 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
930 '--no-log-timestamps', '--disable-validate', '--disable-color',
931 '--eval-timeout=20', '--thread-count=20',
932 '--enable-reuse', "--collection-cache-size=256",
933 '--debug', '--on-error=continue',
934 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
936 stubs.api.container_requests().create.assert_called_with(
937 body=JsonDiffMatcher(expect_container))
938 self.assertEqual(stubs.capture_stdout.getvalue(),
939 stubs.expect_container_request_uuid + '\n')
940 self.assertEqual(exited, 0)
943 def test_submit_container_runner_image(self, stubs):
944 exited = arvados_cwl.main(
945 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
946 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
947 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
949 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
951 expect_container = copy.deepcopy(stubs.expect_container_spec)
952 stubs.api.container_requests().create.assert_called_with(
953 body=JsonDiffMatcher(expect_container))
954 self.assertEqual(stubs.capture_stdout.getvalue(),
955 stubs.expect_container_request_uuid + '\n')
956 self.assertEqual(exited, 0)
959 def test_submit_priority(self, stubs):
960 exited = arvados_cwl.main(
961 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
962 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
963 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
965 stubs.expect_container_spec["priority"] = 669
967 expect_container = copy.deepcopy(stubs.expect_container_spec)
968 stubs.api.container_requests().create.assert_called_with(
969 body=JsonDiffMatcher(expect_container))
970 self.assertEqual(stubs.capture_stdout.getvalue(),
971 stubs.expect_container_request_uuid + '\n')
972 self.assertEqual(exited, 0)
975 def test_submit_wf_runner_resources(self, stubs):
976 exited = arvados_cwl.main(
977 ["--submit", "--no-wait", "--api=containers", "--debug",
978 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
979 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
981 expect_container = copy.deepcopy(stubs.expect_container_spec)
982 expect_container["runtime_constraints"] = {
985 "ram": (2000+512) * 2**20
987 expect_container["name"] = "submit_wf_runner_resources.cwl"
988 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
990 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
996 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
997 "arv": "http://arvados.org/cwl#",
999 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
1000 '--no-log-timestamps', '--disable-validate', '--disable-color',
1001 '--eval-timeout=20', '--thread-count=0',
1002 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
1003 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1005 stubs.api.container_requests().create.assert_called_with(
1006 body=JsonDiffMatcher(expect_container))
1007 self.assertEqual(stubs.capture_stdout.getvalue(),
1008 stubs.expect_container_request_uuid + '\n')
1009 self.assertEqual(exited, 0)
1012 arvados_cwl.arvdocker.arv_docker_clear_cache()
1014 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1015 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1016 @mock.patch("arvados.api")
1017 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1018 arvados_cwl.arvdocker.arv_docker_clear_cache()
1020 arvrunner = mock.MagicMock()
1021 arvrunner.project_uuid = ""
1022 api.return_value = mock.MagicMock()
1023 arvrunner.api = api.return_value
1024 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1025 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1026 "link_class": "docker_image_repo+tag",
1027 "name": "arvados/jobs:"+arvados_cwl.__version__,
1029 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1030 {"items": [{"created_at": "",
1032 "link_class": "docker_image_hash",
1035 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1037 find_one_image_hash.return_value = "123456"
1039 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1041 "manifest_text": "",
1043 }], "items_available": 1, "offset": 0},)
1044 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1045 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1046 "portable_data_hash": "9999999999999999999999999999999b+99"}
1047 self.assertEqual("9999999999999999999999999999999b+99",
1048 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1052 def test_submit_secrets(self, stubs):
1053 exited = arvados_cwl.main(
1054 ["--submit", "--no-wait", "--api=containers", "--debug",
1055 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1056 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1058 expect_container = {
1060 "arvados-cwl-runner",
1063 "--no-log-timestamps",
1064 "--disable-validate",
1066 "--eval-timeout=20",
1069 "--collection-cache-size=256",
1071 "--on-error=continue",
1072 "/var/lib/cwl/workflow.json#main",
1073 "/var/lib/cwl/cwl.input.json"
1075 "container_image": "999999999999999999999999999999d3+99",
1076 "cwd": "/var/spool/cwl",
1078 "/var/lib/cwl/cwl.input.json": {
1081 "$include": "/secrets/s0"
1086 "/var/lib/cwl/workflow.json": {
1091 "cwltool": "http://commonwl.org/cwltool#"
1097 "class": "CommandLineTool",
1100 "class": "http://commonwl.org/cwltool#Secrets",
1102 "#secret_job.cwl/pw"
1106 "id": "#secret_job.cwl",
1109 "id": "#secret_job.cwl/pw",
1115 "id": "#secret_job.cwl/out",
1118 "glob": "hashed_example.txt"
1122 "stdout": "hashed_example.txt",
1125 "class": "InitialWorkDirRequirement",
1128 "entry": "username: user\npassword: $(inputs.pw)\n",
1129 "entryname": "example.conf"
1136 "class": "Workflow",
1139 "class": "DockerRequirement",
1140 "dockerPull": "debian:buster-slim",
1141 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1144 "class": "http://commonwl.org/cwltool#Secrets",
1160 "outputSource": "#main/step1/out",
1166 "id": "#main/step1",
1169 "id": "#main/step1/pw",
1170 "source": "#main/pw"
1176 "run": "#secret_job.cwl"
1181 "cwlVersion": "v1.0"
1186 "kind": "collection",
1191 "path": "/var/spool/cwl/cwl.output.json"
1194 "name": "secret_wf.cwl",
1195 "output_path": "/var/spool/cwl",
1198 "runtime_constraints": {
1209 "state": "Committed",
1210 "use_existing": False
1213 stubs.api.container_requests().create.assert_called_with(
1214 body=JsonDiffMatcher(expect_container))
1215 self.assertEqual(stubs.capture_stdout.getvalue(),
1216 stubs.expect_container_request_uuid + '\n')
1217 self.assertEqual(exited, 0)
1220 def test_submit_request_uuid(self, stubs):
1221 stubs.api._rootDesc["remoteHosts"]["zzzzz"] = "123"
1222 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1224 stubs.api.container_requests().update().execute.return_value = {
1225 "uuid": stubs.expect_container_request_uuid,
1226 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1230 exited = arvados_cwl.main(
1231 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1232 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1233 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1235 stubs.api.container_requests().update.assert_called_with(
1236 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec))
1237 self.assertEqual(stubs.capture_stdout.getvalue(),
1238 stubs.expect_container_request_uuid + '\n')
1239 self.assertEqual(exited, 0)
1242 def test_submit_container_cluster_id(self, stubs):
1243 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1245 exited = arvados_cwl.main(
1246 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1247 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1248 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1250 expect_container = copy.deepcopy(stubs.expect_container_spec)
1252 stubs.api.container_requests().create.assert_called_with(
1253 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1254 self.assertEqual(stubs.capture_stdout.getvalue(),
1255 stubs.expect_container_request_uuid + '\n')
1256 self.assertEqual(exited, 0)
1259 def test_submit_validate_cluster_id(self, stubs):
1260 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1261 exited = arvados_cwl.main(
1262 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1263 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1264 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1265 self.assertEqual(exited, 1)
1268 def test_submit_validate_project_uuid(self, stubs):
1269 # Fails with bad cluster prefix
1270 exited = arvados_cwl.main(
1271 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid=zzzzb-j7d0g-zzzzzzzzzzzzzzz",
1272 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1273 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1274 self.assertEqual(exited, 1)
1276 # Project lookup fails
1277 stubs.api.groups().get().execute.side_effect = Exception("Bad project")
1278 exited = arvados_cwl.main(
1279 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid=zzzzz-j7d0g-zzzzzzzzzzzzzzx",
1280 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1281 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1282 self.assertEqual(exited, 1)
1284 # It should work this time because it is looking up a user (and only group is stubbed out to fail)
1285 exited = arvados_cwl.main(
1286 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid=zzzzz-tpzed-zzzzzzzzzzzzzzx",
1287 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1288 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1289 self.assertEqual(exited, 0)
1292 @mock.patch("arvados.collection.CollectionReader")
1294 def test_submit_uuid_inputs(self, stubs, collectionReader):
1295 collectionReader().exists.return_value = True
1296 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt")
1297 def list_side_effect(**kwargs):
1298 m = mock.MagicMock()
1299 if "count" in kwargs:
1300 m.execute.return_value = {"items": [
1301 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999998+99"}
1304 m.execute.return_value = {"items": []}
1306 stubs.api.collections().list.side_effect = list_side_effect
1308 exited = arvados_cwl.main(
1309 ["--submit", "--no-wait", "--api=containers", "--debug",
1310 "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"],
1311 stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1313 expect_container = copy.deepcopy(stubs.expect_container_spec)
1314 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['basename'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1315 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1316 expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['z']['listing'][0]['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz'
1318 stubs.api.collections().list.assert_has_calls([
1319 mock.call(count='none',
1320 filters=[['uuid', 'in', ['zzzzz-4zz18-zzzzzzzzzzzzzzz']]],
1321 select=['uuid', 'portable_data_hash'])])
1322 stubs.api.container_requests().create.assert_called_with(
1323 body=JsonDiffMatcher(expect_container))
1324 self.assertEqual(stubs.capture_stdout.getvalue(),
1325 stubs.expect_container_request_uuid + '\n')
1326 self.assertEqual(exited, 0)
1329 def test_submit_mismatched_uuid_inputs(self, stubs):
1330 def list_side_effect(**kwargs):
1331 m = mock.MagicMock()
1332 if "count" in kwargs:
1333 m.execute.return_value = {"items": [
1334 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999997+99"}
1337 m.execute.return_value = {"items": []}
1339 stubs.api.collections().list.side_effect = list_side_effect
1341 for infile in ("tests/submit_test_job_with_mismatched_uuids.json", "tests/submit_test_job_with_inconsistent_uuids.json"):
1342 capture_stderr = StringIO()
1343 cwltool_logger = logging.getLogger('cwltool')
1344 stderr_logger = logging.StreamHandler(capture_stderr)
1345 cwltool_logger.addHandler(stderr_logger)
1348 exited = arvados_cwl.main(
1349 ["--submit", "--no-wait", "--api=containers", "--debug",
1350 "tests/wf/submit_wf.cwl", infile],
1351 stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1353 self.assertEqual(exited, 1)
1355 re.sub(r'[ \n]+', ' ', capture_stderr.getvalue()),
1356 r"Expected collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz to be 99999999999999999999999999999998\+99 but API server reported 99999999999999999999999999999997\+99")
1358 cwltool_logger.removeHandler(stderr_logger)
1360 @mock.patch("arvados.collection.CollectionReader")
1362 def test_submit_unknown_uuid_inputs(self, stubs, collectionReader):
1363 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt")
1364 capture_stderr = StringIO()
1366 cwltool_logger = logging.getLogger('cwltool')
1367 stderr_logger = logging.StreamHandler(capture_stderr)
1368 cwltool_logger.addHandler(stderr_logger)
1370 exited = arvados_cwl.main(
1371 ["--submit", "--no-wait", "--api=containers", "--debug",
1372 "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"],
1373 stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1376 self.assertEqual(exited, 1)
1378 capture_stderr.getvalue(),
1379 r"Collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz not found")
1381 cwltool_logger.removeHandler(stderr_logger)
1384 class TestCreateWorkflow(unittest.TestCase):
1385 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1386 expect_workflow = StripYAMLComments(
1387 open("tests/wf/expect_upload_packed.cwl").read().rstrip())
1390 cwltool.process._names = set()
1391 arvados_cwl.arvdocker.arv_docker_clear_cache()
1394 def test_create(self, stubs):
1395 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1396 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
1398 exited = arvados_cwl.main(
1399 ["--create-workflow", "--debug",
1401 "--project-uuid", project_uuid,
1402 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1403 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1405 stubs.api.pipeline_templates().create.refute_called()
1406 stubs.api.container_requests().create.refute_called()
1410 "owner_uuid": project_uuid,
1411 "name": "submit_wf.cwl",
1413 "definition": self.expect_workflow,
1416 stubs.api.workflows().create.assert_called_with(
1417 body=JsonDiffMatcher(body))
1419 self.assertEqual(stubs.capture_stdout.getvalue(),
1420 stubs.expect_workflow_uuid + '\n')
1421 self.assertEqual(exited, 0)
1424 def test_create_name(self, stubs):
1425 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1426 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
1428 exited = arvados_cwl.main(
1429 ["--create-workflow", "--debug",
1431 "--project-uuid", project_uuid,
1432 "--name", "testing 123",
1433 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1434 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1436 stubs.api.pipeline_templates().create.refute_called()
1437 stubs.api.container_requests().create.refute_called()
1441 "owner_uuid": project_uuid,
1442 "name": "testing 123",
1444 "definition": self.expect_workflow,
1447 stubs.api.workflows().create.assert_called_with(
1448 body=JsonDiffMatcher(body))
1450 self.assertEqual(stubs.capture_stdout.getvalue(),
1451 stubs.expect_workflow_uuid + '\n')
1452 self.assertEqual(exited, 0)
1456 def test_update(self, stubs):
1457 exited = arvados_cwl.main(
1458 ["--update-workflow", self.existing_workflow_uuid,
1460 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1461 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1465 "name": "submit_wf.cwl",
1467 "definition": self.expect_workflow,
1470 stubs.api.workflows().update.assert_called_with(
1471 uuid=self.existing_workflow_uuid,
1472 body=JsonDiffMatcher(body))
1473 self.assertEqual(stubs.capture_stdout.getvalue(),
1474 self.existing_workflow_uuid + '\n')
1475 self.assertEqual(exited, 0)
1478 def test_update_name(self, stubs):
1479 exited = arvados_cwl.main(
1480 ["--update-workflow", self.existing_workflow_uuid,
1481 "--debug", "--name", "testing 123",
1482 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1483 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1487 "name": "testing 123",
1489 "definition": self.expect_workflow,
1492 stubs.api.workflows().update.assert_called_with(
1493 uuid=self.existing_workflow_uuid,
1494 body=JsonDiffMatcher(body))
1495 self.assertEqual(stubs.capture_stdout.getvalue(),
1496 self.existing_workflow_uuid + '\n')
1497 self.assertEqual(exited, 0)
1500 def test_create_collection_per_tool(self, stubs):
1501 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1502 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
1504 exited = arvados_cwl.main(
1505 ["--create-workflow", "--debug",
1507 "--project-uuid", project_uuid,
1508 "tests/collection_per_tool/collection_per_tool.cwl"],
1509 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1511 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1512 expect_workflow = StripYAMLComments(open(toolfile).read().rstrip())
1516 "owner_uuid": project_uuid,
1517 "name": "collection_per_tool.cwl",
1519 "definition": expect_workflow,
1522 stubs.api.workflows().create.assert_called_with(
1523 body=JsonDiffMatcher(body))
1525 self.assertEqual(stubs.capture_stdout.getvalue(),
1526 stubs.expect_workflow_uuid + '\n')
1527 self.assertEqual(exited, 0)
1530 def test_create_with_imports(self, stubs):
1531 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1532 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
1534 exited = arvados_cwl.main(
1535 ["--create-workflow", "--debug",
1537 "--project-uuid", project_uuid,
1538 "tests/wf/feddemo/feddemo.cwl"],
1539 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1541 stubs.api.pipeline_templates().create.refute_called()
1542 stubs.api.container_requests().create.refute_called()
1544 self.assertEqual(stubs.capture_stdout.getvalue(),
1545 stubs.expect_workflow_uuid + '\n')
1546 self.assertEqual(exited, 0)
1549 def test_create_with_no_input(self, stubs):
1550 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1551 stubs.api.groups().get().execute.return_value = {"group_class": "project"}
1553 exited = arvados_cwl.main(
1554 ["--create-workflow", "--debug",
1556 "--project-uuid", project_uuid,
1557 "tests/wf/revsort/revsort.cwl"],
1558 stubs.capture_stdout, sys.stderr, api_client=stubs.api)
1560 stubs.api.pipeline_templates().create.refute_called()
1561 stubs.api.container_requests().create.refute_called()
1563 self.assertEqual(stubs.capture_stdout.getvalue(),
1564 stubs.expect_workflow_uuid + '\n')
1565 self.assertEqual(exited, 0)