1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
16 import arvados.collection
18 import arvados_cwl.executor
19 import arvados_cwl.runner
22 from .matcher import JsonDiffMatcher, StripYAMLComments
23 from .mock_discovery import get_rootDesc
25 import ruamel.yaml as yaml
30 @functools.wraps(func)
31 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
32 @mock.patch("arvados.collection.KeepClient")
33 @mock.patch("arvados.keep.KeepClient")
34 @mock.patch("arvados.events.subscribe")
35 def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs):
40 stubs.keepdocker = keepdocker
42 def putstub(p, **kwargs):
43 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
44 keep_client1().put.side_effect = putstub
45 keep_client1.put.side_effect = putstub
46 keep_client2().put.side_effect = putstub
47 keep_client2.put.side_effect = putstub
49 stubs.keep_client = keep_client2
50 stubs.docker_images = {
51 "arvados/jobs:"+arvados_cwl.__version__: [("zzzzz-4zz18-zzzzzzzzzzzzzd3", "")],
52 "debian:8": [("zzzzz-4zz18-zzzzzzzzzzzzzd4", "")],
53 "arvados/jobs:123": [("zzzzz-4zz18-zzzzzzzzzzzzzd5", "")],
54 "arvados/jobs:latest": [("zzzzz-4zz18-zzzzzzzzzzzzzd6", "")],
56 def kd(a, b, image_name=None, image_tag=None):
57 return stubs.docker_images.get("%s:%s" % (image_name, image_tag), [])
58 stubs.keepdocker.side_effect = kd
60 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
61 stubs.fake_container_uuid = "zzzzz-dz642-zzzzzzzzzzzzzzz"
63 stubs.api = mock.MagicMock()
64 stubs.api._rootDesc = get_rootDesc()
66 stubs.api.users().current().execute.return_value = {
67 "uuid": stubs.fake_user_uuid,
69 stubs.api.collections().list().execute.return_value = {"items": []}
70 stubs.api.containers().current().execute.return_value = {
71 "uuid": stubs.fake_container_uuid,
74 class CollectionExecute(object):
75 def __init__(self, exe):
77 def execute(self, num_retries=None):
80 def collection_createstub(created_collections, body, ensure_unique_name=None):
81 mt = body["manifest_text"]
82 uuid = "zzzzz-4zz18-zzzzzzzzzzzzzx%d" % len(created_collections)
83 pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt))
84 created_collections[uuid] = {
86 "portable_data_hash": pdh,
89 return CollectionExecute(created_collections[uuid])
91 def collection_getstub(created_collections, uuid):
92 for v in created_collections.itervalues():
93 if uuid in (v["uuid"], v["portable_data_hash"]):
94 return CollectionExecute(v)
96 created_collections = {
97 "99999999999999999999999999999998+99": {
99 "portable_data_hash": "99999999999999999999999999999998+99",
100 "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt"
102 "99999999999999999999999999999994+99": {
104 "portable_data_hash": "99999999999999999999999999999994+99",
105 "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl"
107 "zzzzz-4zz18-zzzzzzzzzzzzzd3": {
108 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd3",
109 "portable_data_hash": "999999999999999999999999999999d3+99",
112 "zzzzz-4zz18-zzzzzzzzzzzzzd4": {
113 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd4",
114 "portable_data_hash": "999999999999999999999999999999d4+99",
117 "zzzzz-4zz18-zzzzzzzzzzzzzd5": {
118 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd5",
119 "portable_data_hash": "999999999999999999999999999999d5+99",
122 "zzzzz-4zz18-zzzzzzzzzzzzzd6": {
123 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd6",
124 "portable_data_hash": "999999999999999999999999999999d6+99",
128 stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections)
129 stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections)
131 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
132 stubs.api.jobs().create().execute.return_value = {
133 "uuid": stubs.expect_job_uuid,
137 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
138 stubs.api.container_requests().create().execute.return_value = {
139 "uuid": stubs.expect_container_request_uuid,
140 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
144 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
145 stubs.api.pipeline_templates().create().execute.return_value = {
146 "uuid": stubs.expect_pipeline_template_uuid,
148 stubs.expect_job_spec = {
149 'runtime_constraints': {
150 'docker_image': '999999999999999999999999999999d3+99',
151 'min_ram_mb_per_node': 1024
153 'script_parameters': {
155 'basename': 'blorp.txt',
156 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
160 'basename': '99999999999999999999999999999998+99',
161 'location': 'keep:99999999999999999999999999999998+99',
165 'basename': 'anonymous',
167 "basename": "renamed.txt",
169 "location": "keep:99999999999999999999999999999998+99/file1.txt",
174 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main'
176 'repository': 'arvados',
177 'script_version': 'master',
178 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
179 'script': 'cwl-runner'
181 stubs.pipeline_component = stubs.expect_job_spec.copy()
182 stubs.expect_pipeline_instance = {
183 'name': 'submit_wf.cwl',
184 'state': 'RunningOnServer',
188 'runtime_constraints': {'docker_image': '999999999999999999999999999999d3+99', 'min_ram_mb_per_node': 1024},
189 'script_parameters': {
190 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}},
192 'basename': 'blorp.txt',
194 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
197 'z': {"value": {'basename': 'anonymous', 'class': 'Directory',
200 'basename': 'renamed.txt',
201 'class': 'File', 'location':
202 'keep:99999999999999999999999999999998+99/file1.txt',
206 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main',
208 'arv:enable_reuse': True,
209 'arv:on_error': 'continue'
211 'repository': 'arvados',
212 'script_version': 'master',
213 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
214 'script': 'cwl-runner',
215 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'}
219 stubs.pipeline_create = copy.deepcopy(stubs.expect_pipeline_instance)
220 stubs.expect_pipeline_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
221 stubs.pipeline_create["uuid"] = stubs.expect_pipeline_uuid
222 stubs.pipeline_with_job = copy.deepcopy(stubs.pipeline_create)
223 stubs.pipeline_with_job["components"]["cwl-runner"]["job"] = {
224 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
227 stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create
228 stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job
230 with open("tests/wf/submit_wf_packed.cwl") as f:
231 expect_packed_workflow = yaml.round_trip_load(f)
233 stubs.expect_container_spec = {
240 '/var/lib/cwl/workflow.json': {
241 'content': expect_packed_workflow,
245 'path': '/var/spool/cwl/cwl.output.json',
248 '/var/lib/cwl/cwl.input.json': {
252 'basename': '99999999999999999999999999999998+99',
253 'location': 'keep:99999999999999999999999999999998+99',
254 'class': 'Directory'},
256 'basename': u'blorp.txt',
258 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
261 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [
262 {'basename': 'renamed.txt',
264 'location': 'keep:99999999999999999999999999999998+99/file1.txt',
273 'state': 'Committed',
274 'command': ['arvados-cwl-runner', '--local', '--api=containers',
275 '--no-log-timestamps', '--disable-validate',
276 '--eval-timeout=20', '--thread-count=1',
277 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
278 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
279 'name': 'submit_wf.cwl',
280 'container_image': '999999999999999999999999999999d3+99',
281 'output_path': '/var/spool/cwl',
282 'cwd': '/var/spool/cwl',
283 'runtime_constraints': {
286 'ram': (1024+256)*1024*1024
288 'use_existing': True,
293 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
294 stubs.api.workflows().create().execute.return_value = {
295 "uuid": stubs.expect_workflow_uuid,
297 def update_mock(**kwargs):
298 stubs.updated_uuid = kwargs.get('uuid')
300 stubs.api.workflows().update.side_effect = update_mock
301 stubs.api.workflows().update().execute.side_effect = lambda **kwargs: {
302 "uuid": stubs.updated_uuid,
305 return func(self, stubs, *args, **kwargs)
309 class TestSubmit(unittest.TestCase):
310 @mock.patch("arvados_cwl.arvdocker.arv_docker_get_image")
311 @mock.patch("time.sleep")
313 def test_submit(self, stubs, tm, arvdock):
314 def get_image(api_client, dockerRequirement, pull_image, project_uuid):
315 if dockerRequirement["dockerPull"] == 'arvados/jobs:'+arvados_cwl.__version__:
316 return '999999999999999999999999999999d3+99'
317 elif dockerRequirement["dockerPull"] == "debian:8":
318 return '999999999999999999999999999999d4+99'
319 arvdock.side_effect = get_image
321 capture_stdout = cStringIO.StringIO()
322 exited = arvados_cwl.main(
323 ["--submit", "--no-wait", "--api=jobs", "--debug",
324 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
325 capture_stdout, sys.stderr, api_client=stubs.api)
326 self.assertEqual(exited, 0)
328 stubs.api.collections().create.assert_has_calls([
329 mock.call(body=JsonDiffMatcher({
331 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
332 'replication_desired': None,
333 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
334 }), ensure_unique_name=False),
335 mock.call(body=JsonDiffMatcher({
337 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
338 'replication_desired': None,
339 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
340 }), ensure_unique_name=False),
341 mock.call(body=JsonDiffMatcher({
343 ". 68089141fbf7e020ac90a9d6a575bc8f+1312 0:1312:workflow.cwl\n",
344 'replication_desired': None,
345 'name': 'submit_wf.cwl',
346 }), ensure_unique_name=True) ])
348 arvdock.assert_has_calls([
349 mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None),
350 mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8", 'http://arvados.org/cwl#dockerCollectionPDH': '999999999999999999999999999999d4+99'}, True, None),
351 mock.call(stubs.api, {'dockerPull': 'arvados/jobs:'+arvados_cwl.__version__}, True, None)
354 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
355 stubs.api.pipeline_instances().create.assert_called_with(
356 body=JsonDiffMatcher(expect_pipeline))
357 self.assertEqual(capture_stdout.getvalue(),
358 stubs.expect_pipeline_uuid + '\n')
361 @mock.patch("time.sleep")
363 def test_submit_no_reuse(self, stubs, tm):
364 capture_stdout = cStringIO.StringIO()
365 exited = arvados_cwl.main(
366 ["--submit", "--no-wait", "--api=jobs", "--debug", "--disable-reuse",
367 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
368 capture_stdout, sys.stderr, api_client=stubs.api)
369 self.assertEqual(exited, 0)
371 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
372 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False}
373 expect_pipeline["properties"] = {"run_options": {"enable_job_reuse": False}}
375 stubs.api.pipeline_instances().create.assert_called_with(
376 body=JsonDiffMatcher(expect_pipeline))
377 self.assertEqual(capture_stdout.getvalue(),
378 stubs.expect_pipeline_uuid + '\n')
381 def test_error_when_multiple_storage_classes_specified(self, stubs):
382 storage_classes = "foo,bar"
383 exited = arvados_cwl.main(
384 ["--debug", "--storage-classes", storage_classes,
385 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
386 sys.stdin, sys.stderr, api_client=stubs.api)
387 self.assertEqual(exited, 1)
389 @mock.patch("time.sleep")
391 def test_submit_on_error(self, stubs, tm):
392 capture_stdout = cStringIO.StringIO()
393 exited = arvados_cwl.main(
394 ["--submit", "--no-wait", "--api=jobs", "--debug", "--on-error=stop",
395 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
396 capture_stdout, sys.stderr, api_client=stubs.api)
397 self.assertEqual(exited, 0)
399 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
400 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop"
402 stubs.api.pipeline_instances().create.assert_called_with(
403 body=JsonDiffMatcher(expect_pipeline))
404 self.assertEqual(capture_stdout.getvalue(),
405 stubs.expect_pipeline_uuid + '\n')
408 @mock.patch("time.sleep")
410 def test_submit_runner_ram(self, stubs, tm):
411 capture_stdout = cStringIO.StringIO()
412 exited = arvados_cwl.main(
413 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=2048",
414 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
415 capture_stdout, sys.stderr, api_client=stubs.api)
416 self.assertEqual(exited, 0)
418 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
419 expect_pipeline["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048
421 stubs.api.pipeline_instances().create.assert_called_with(
422 body=JsonDiffMatcher(expect_pipeline))
423 self.assertEqual(capture_stdout.getvalue(),
424 stubs.expect_pipeline_uuid + '\n')
427 @mock.patch("time.sleep")
429 def test_submit_invalid_runner_ram(self, stubs, tm):
430 capture_stdout = cStringIO.StringIO()
431 exited = arvados_cwl.main(
432 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048",
433 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
434 capture_stdout, sys.stderr, api_client=stubs.api)
435 self.assertEqual(exited, 1)
437 @mock.patch("time.sleep")
439 def test_submit_output_name(self, stubs, tm):
440 output_name = "test_output_name"
442 capture_stdout = cStringIO.StringIO()
443 exited = arvados_cwl.main(
444 ["--submit", "--no-wait", "--debug", "--output-name", output_name,
445 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
446 capture_stdout, sys.stderr, api_client=stubs.api)
447 self.assertEqual(exited, 0)
449 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
450 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name
452 stubs.api.pipeline_instances().create.assert_called_with(
453 body=JsonDiffMatcher(expect_pipeline))
454 self.assertEqual(capture_stdout.getvalue(),
455 stubs.expect_pipeline_uuid + '\n')
458 @mock.patch("time.sleep")
460 def test_submit_pipeline_name(self, stubs, tm):
461 capture_stdout = cStringIO.StringIO()
462 exited = arvados_cwl.main(
463 ["--submit", "--no-wait", "--debug", "--name=hello job 123",
464 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
465 capture_stdout, sys.stderr, api_client=stubs.api)
466 self.assertEqual(exited, 0)
468 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
469 expect_pipeline["name"] = "hello job 123"
471 stubs.api.pipeline_instances().create.assert_called_with(
472 body=JsonDiffMatcher(expect_pipeline))
473 self.assertEqual(capture_stdout.getvalue(),
474 stubs.expect_pipeline_uuid + '\n')
476 @mock.patch("time.sleep")
478 def test_submit_output_tags(self, stubs, tm):
479 output_tags = "tag0,tag1,tag2"
481 capture_stdout = cStringIO.StringIO()
482 exited = arvados_cwl.main(
483 ["--submit", "--no-wait", "--debug", "--output-tags", output_tags,
484 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
485 capture_stdout, sys.stderr, api_client=stubs.api)
486 self.assertEqual(exited, 0)
488 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
489 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags
491 stubs.api.pipeline_instances().create.assert_called_with(
492 body=JsonDiffMatcher(expect_pipeline))
493 self.assertEqual(capture_stdout.getvalue(),
494 stubs.expect_pipeline_uuid + '\n')
496 @mock.patch("time.sleep")
498 def test_submit_with_project_uuid(self, stubs, tm):
499 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
501 exited = arvados_cwl.main(
502 ["--submit", "--no-wait", "--debug",
503 "--project-uuid", project_uuid,
504 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
505 sys.stdout, sys.stderr, api_client=stubs.api)
506 self.assertEqual(exited, 0)
508 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
509 expect_pipeline["owner_uuid"] = project_uuid
510 stubs.api.pipeline_instances().create.assert_called_with(
511 body=JsonDiffMatcher(expect_pipeline))
514 def test_submit_container(self, stubs):
515 capture_stdout = cStringIO.StringIO()
517 exited = arvados_cwl.main(
518 ["--submit", "--no-wait", "--api=containers", "--debug",
519 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
520 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
521 self.assertEqual(exited, 0)
523 logging.exception("")
525 stubs.api.collections().create.assert_has_calls([
526 mock.call(body=JsonDiffMatcher({
528 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
529 'replication_desired': None,
530 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
531 }), ensure_unique_name=False),
532 mock.call(body=JsonDiffMatcher({
534 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
535 'replication_desired': None,
536 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
537 }), ensure_unique_name=False)])
539 expect_container = copy.deepcopy(stubs.expect_container_spec)
540 stubs.api.container_requests().create.assert_called_with(
541 body=JsonDiffMatcher(expect_container))
542 self.assertEqual(capture_stdout.getvalue(),
543 stubs.expect_container_request_uuid + '\n')
546 def test_submit_container_no_reuse(self, stubs):
547 capture_stdout = cStringIO.StringIO()
549 exited = arvados_cwl.main(
550 ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse",
551 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
552 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
553 self.assertEqual(exited, 0)
555 logging.exception("")
557 expect_container = copy.deepcopy(stubs.expect_container_spec)
558 expect_container["command"] = [
559 'arvados-cwl-runner', '--local', '--api=containers',
560 '--no-log-timestamps', '--disable-validate',
561 '--eval-timeout=20', '--thread-count=1',
562 '--disable-reuse', "--collection-cache-size=256",
563 '--debug', '--on-error=continue',
564 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
565 expect_container["use_existing"] = False
567 stubs.api.container_requests().create.assert_called_with(
568 body=JsonDiffMatcher(expect_container))
569 self.assertEqual(capture_stdout.getvalue(),
570 stubs.expect_container_request_uuid + '\n')
574 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
575 capture_stdout = cStringIO.StringIO()
577 exited = arvados_cwl.main(
578 ["--submit", "--no-wait", "--api=containers", "--debug",
579 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
580 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
581 self.assertEqual(exited, 0)
583 expect_container = copy.deepcopy(stubs.expect_container_spec)
584 expect_container["command"] = [
585 'arvados-cwl-runner', '--local', '--api=containers',
586 '--no-log-timestamps', '--disable-validate',
587 '--eval-timeout=20', '--thread-count=1',
588 '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
589 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
590 expect_container["use_existing"] = False
591 expect_container["name"] = "submit_wf_no_reuse.cwl"
592 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
594 "class": "http://arvados.org/cwl#ReuseRequirement",
595 "enableReuse": False,
598 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
599 "arv": "http://arvados.org/cwl#",
600 "cwltool": "http://commonwl.org/cwltool#"
603 stubs.api.container_requests().create.assert_called_with(
604 body=JsonDiffMatcher(expect_container))
605 self.assertEqual(capture_stdout.getvalue(),
606 stubs.expect_container_request_uuid + '\n')
610 def test_submit_container_on_error(self, stubs):
611 capture_stdout = cStringIO.StringIO()
613 exited = arvados_cwl.main(
614 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
615 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
616 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
617 self.assertEqual(exited, 0)
619 logging.exception("")
621 expect_container = copy.deepcopy(stubs.expect_container_spec)
622 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
623 '--no-log-timestamps', '--disable-validate',
624 '--eval-timeout=20', '--thread-count=1',
625 '--enable-reuse', "--collection-cache-size=256",
626 '--debug', '--on-error=stop',
627 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
629 stubs.api.container_requests().create.assert_called_with(
630 body=JsonDiffMatcher(expect_container))
631 self.assertEqual(capture_stdout.getvalue(),
632 stubs.expect_container_request_uuid + '\n')
635 def test_submit_container_output_name(self, stubs):
636 output_name = "test_output_name"
638 capture_stdout = cStringIO.StringIO()
640 exited = arvados_cwl.main(
641 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
642 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
643 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
644 self.assertEqual(exited, 0)
646 logging.exception("")
648 expect_container = copy.deepcopy(stubs.expect_container_spec)
649 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
650 '--no-log-timestamps', '--disable-validate',
651 '--eval-timeout=20', '--thread-count=1',
652 '--enable-reuse', "--collection-cache-size=256",
653 "--output-name="+output_name, '--debug', '--on-error=continue',
654 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
655 expect_container["output_name"] = output_name
657 stubs.api.container_requests().create.assert_called_with(
658 body=JsonDiffMatcher(expect_container))
659 self.assertEqual(capture_stdout.getvalue(),
660 stubs.expect_container_request_uuid + '\n')
663 def test_submit_storage_classes(self, stubs):
664 capture_stdout = cStringIO.StringIO()
666 exited = arvados_cwl.main(
667 ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo",
668 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
669 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
670 self.assertEqual(exited, 0)
672 logging.exception("")
674 expect_container = copy.deepcopy(stubs.expect_container_spec)
675 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
676 '--no-log-timestamps', '--disable-validate',
677 '--eval-timeout=20', '--thread-count=1',
678 '--enable-reuse', "--collection-cache-size=256", "--debug",
679 "--storage-classes=foo", '--on-error=continue',
680 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
682 stubs.api.container_requests().create.assert_called_with(
683 body=JsonDiffMatcher(expect_container))
684 self.assertEqual(capture_stdout.getvalue(),
685 stubs.expect_container_request_uuid + '\n')
687 @mock.patch("arvados_cwl.task_queue.TaskQueue")
688 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
689 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
691 def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
692 def set_final_output(job_order, output_callback, runtimeContext):
693 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
695 job.side_effect = set_final_output
698 exited = arvados_cwl.main(
699 ["--debug", "--local", "--storage-classes=foo",
700 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
701 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
702 self.assertEqual(exited, 0)
704 logging.exception("")
706 make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
708 @mock.patch("arvados_cwl.task_queue.TaskQueue")
709 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
710 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
712 def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
713 def set_final_output(job_order, output_callback, runtimeContext):
714 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
716 job.side_effect = set_final_output
719 exited = arvados_cwl.main(
720 ["--debug", "--local",
721 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
722 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
723 self.assertEqual(exited, 0)
725 logging.exception("")
727 make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
730 def test_submit_container_output_ttl(self, stubs):
731 capture_stdout = cStringIO.StringIO()
733 exited = arvados_cwl.main(
734 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
735 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
736 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
737 self.assertEqual(exited, 0)
739 logging.exception("")
741 expect_container = copy.deepcopy(stubs.expect_container_spec)
742 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
743 '--no-log-timestamps', '--disable-validate',
744 '--eval-timeout=20', '--thread-count=1',
745 '--enable-reuse', "--collection-cache-size=256", '--debug',
746 '--on-error=continue',
747 "--intermediate-output-ttl=3600",
748 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
750 stubs.api.container_requests().create.assert_called_with(
751 body=JsonDiffMatcher(expect_container))
752 self.assertEqual(capture_stdout.getvalue(),
753 stubs.expect_container_request_uuid + '\n')
756 def test_submit_container_trash_intermediate(self, stubs):
757 capture_stdout = cStringIO.StringIO()
759 exited = arvados_cwl.main(
760 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
761 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
762 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
763 self.assertEqual(exited, 0)
765 logging.exception("")
767 expect_container = copy.deepcopy(stubs.expect_container_spec)
768 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
769 '--no-log-timestamps', '--disable-validate',
770 '--eval-timeout=20', '--thread-count=1',
771 '--enable-reuse', "--collection-cache-size=256",
772 '--debug', '--on-error=continue',
773 "--trash-intermediate",
774 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
776 stubs.api.container_requests().create.assert_called_with(
777 body=JsonDiffMatcher(expect_container))
778 self.assertEqual(capture_stdout.getvalue(),
779 stubs.expect_container_request_uuid + '\n')
782 def test_submit_container_output_tags(self, stubs):
783 output_tags = "tag0,tag1,tag2"
785 capture_stdout = cStringIO.StringIO()
787 exited = arvados_cwl.main(
788 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
789 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
790 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
791 self.assertEqual(exited, 0)
793 logging.exception("")
795 expect_container = copy.deepcopy(stubs.expect_container_spec)
796 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
797 '--no-log-timestamps', '--disable-validate',
798 '--eval-timeout=20', '--thread-count=1',
799 '--enable-reuse', "--collection-cache-size=256",
800 "--output-tags="+output_tags, '--debug', '--on-error=continue',
801 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
803 stubs.api.container_requests().create.assert_called_with(
804 body=JsonDiffMatcher(expect_container))
805 self.assertEqual(capture_stdout.getvalue(),
806 stubs.expect_container_request_uuid + '\n')
809 def test_submit_container_runner_ram(self, stubs):
810 capture_stdout = cStringIO.StringIO()
812 exited = arvados_cwl.main(
813 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
814 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
815 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
816 self.assertEqual(exited, 0)
818 logging.exception("")
820 expect_container = copy.deepcopy(stubs.expect_container_spec)
821 expect_container["runtime_constraints"]["ram"] = (2048+256)*1024*1024
823 stubs.api.container_requests().create.assert_called_with(
824 body=JsonDiffMatcher(expect_container))
825 self.assertEqual(capture_stdout.getvalue(),
826 stubs.expect_container_request_uuid + '\n')
828 @mock.patch("arvados.collection.CollectionReader")
829 @mock.patch("time.sleep")
831 def test_submit_file_keepref(self, stubs, tm, collectionReader):
832 capture_stdout = cStringIO.StringIO()
833 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt")
834 exited = arvados_cwl.main(
835 ["--submit", "--no-wait", "--api=containers", "--debug",
836 "tests/wf/submit_keepref_wf.cwl"],
837 capture_stdout, sys.stderr, api_client=stubs.api)
838 self.assertEqual(exited, 0)
841 @mock.patch("arvados.collection.CollectionReader")
842 @mock.patch("time.sleep")
844 def test_submit_keepref(self, stubs, tm, reader):
845 capture_stdout = cStringIO.StringIO()
847 with open("tests/wf/expect_arvworkflow.cwl") as f:
848 reader().open().__enter__().read.return_value = f.read()
850 exited = arvados_cwl.main(
851 ["--submit", "--no-wait", "--api=containers", "--debug",
852 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
853 capture_stdout, sys.stderr, api_client=stubs.api)
854 self.assertEqual(exited, 0)
864 'path': '/var/spool/cwl/cwl.output.json',
867 '/var/lib/cwl/workflow': {
868 'portable_data_hash': '99999999999999999999999999999994+99',
871 '/var/lib/cwl/cwl.input.json': {
877 }, 'state': 'Committed',
878 'output_path': '/var/spool/cwl',
879 'name': 'expect_arvworkflow.cwl#main',
880 'container_image': '999999999999999999999999999999d3+99',
881 'command': ['arvados-cwl-runner', '--local', '--api=containers',
882 '--no-log-timestamps', '--disable-validate',
883 '--eval-timeout=20', '--thread-count=1',
884 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
885 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
886 'cwd': '/var/spool/cwl',
887 'runtime_constraints': {
892 'use_existing': True,
897 stubs.api.container_requests().create.assert_called_with(
898 body=JsonDiffMatcher(expect_container))
899 self.assertEqual(capture_stdout.getvalue(),
900 stubs.expect_container_request_uuid + '\n')
903 @mock.patch("arvados.collection.CollectionReader")
904 @mock.patch("time.sleep")
906 def test_submit_jobs_keepref(self, stubs, tm, reader):
907 capture_stdout = cStringIO.StringIO()
909 with open("tests/wf/expect_arvworkflow.cwl") as f:
910 reader().open().__enter__().read.return_value = f.read()
912 exited = arvados_cwl.main(
913 ["--submit", "--no-wait", "--api=jobs", "--debug",
914 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
915 capture_stdout, sys.stderr, api_client=stubs.api)
916 self.assertEqual(exited, 0)
918 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
919 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX"
920 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"]
921 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"]
922 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main"
923 expect_pipeline["name"] = "expect_arvworkflow.cwl#main"
924 stubs.api.pipeline_instances().create.assert_called_with(
925 body=JsonDiffMatcher(expect_pipeline))
927 @mock.patch("time.sleep")
929 def test_submit_arvworkflow(self, stubs, tm):
930 capture_stdout = cStringIO.StringIO()
932 with open("tests/wf/expect_arvworkflow.cwl") as f:
933 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
935 exited = arvados_cwl.main(
936 ["--submit", "--no-wait", "--api=containers", "--debug",
937 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
938 capture_stdout, sys.stderr, api_client=stubs.api)
939 self.assertEqual(exited, 0)
949 'path': '/var/spool/cwl/cwl.output.json',
952 '/var/lib/cwl/workflow.json': {
955 'cwlVersion': 'v1.0',
960 {'type': 'string', 'id': '#main/x'}
963 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
964 'run': '#submit_tool.cwl',
974 'inputBinding': {'position': 1},
976 'id': '#submit_tool.cwl/x'}
980 'dockerPull': 'debian:8',
981 'class': 'DockerRequirement',
982 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
985 'id': '#submit_tool.cwl',
987 'baseCommand': 'cat',
988 'class': 'CommandLineTool'
993 '/var/lib/cwl/cwl.input.json': {
999 }, 'state': 'Committed',
1000 'output_path': '/var/spool/cwl',
1001 'name': 'a test workflow',
1002 'container_image': "999999999999999999999999999999d3+99",
1003 'command': ['arvados-cwl-runner', '--local', '--api=containers',
1004 '--no-log-timestamps', '--disable-validate',
1005 '--eval-timeout=20', '--thread-count=1',
1006 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
1007 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
1008 'cwd': '/var/spool/cwl',
1009 'runtime_constraints': {
1014 'use_existing': True,
1016 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
1021 stubs.api.container_requests().create.assert_called_with(
1022 body=JsonDiffMatcher(expect_container))
1023 self.assertEqual(capture_stdout.getvalue(),
1024 stubs.expect_container_request_uuid + '\n')
1028 def test_submit_container_name(self, stubs):
1029 capture_stdout = cStringIO.StringIO()
1031 exited = arvados_cwl.main(
1032 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
1033 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1034 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1035 self.assertEqual(exited, 0)
1037 logging.exception("")
1039 expect_container = copy.deepcopy(stubs.expect_container_spec)
1040 expect_container["name"] = "hello container 123"
1042 stubs.api.container_requests().create.assert_called_with(
1043 body=JsonDiffMatcher(expect_container))
1044 self.assertEqual(capture_stdout.getvalue(),
1045 stubs.expect_container_request_uuid + '\n')
1049 def test_submit_container_project(self, stubs):
1050 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1051 capture_stdout = cStringIO.StringIO()
1053 exited = arvados_cwl.main(
1054 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
1055 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1056 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1057 self.assertEqual(exited, 0)
1059 logging.exception("")
1061 expect_container = copy.deepcopy(stubs.expect_container_spec)
1062 expect_container["owner_uuid"] = project_uuid
1063 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1064 '--no-log-timestamps', '--disable-validate',
1065 "--eval-timeout=20", "--thread-count=1",
1066 '--enable-reuse', "--collection-cache-size=256", '--debug',
1067 '--on-error=continue',
1068 '--project-uuid='+project_uuid,
1069 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1071 stubs.api.container_requests().create.assert_called_with(
1072 body=JsonDiffMatcher(expect_container))
1073 self.assertEqual(capture_stdout.getvalue(),
1074 stubs.expect_container_request_uuid + '\n')
1077 def test_submit_container_eval_timeout(self, stubs):
1078 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1079 capture_stdout = cStringIO.StringIO()
1081 exited = arvados_cwl.main(
1082 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
1083 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1084 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1085 self.assertEqual(exited, 0)
1087 logging.exception("")
1089 expect_container = copy.deepcopy(stubs.expect_container_spec)
1090 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1091 '--no-log-timestamps', '--disable-validate',
1092 '--eval-timeout=60.0', '--thread-count=1',
1093 '--enable-reuse', "--collection-cache-size=256",
1094 '--debug', '--on-error=continue',
1095 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1097 stubs.api.container_requests().create.assert_called_with(
1098 body=JsonDiffMatcher(expect_container))
1099 self.assertEqual(capture_stdout.getvalue(),
1100 stubs.expect_container_request_uuid + '\n')
1103 def test_submit_container_collection_cache(self, stubs):
1104 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1105 capture_stdout = cStringIO.StringIO()
1107 exited = arvados_cwl.main(
1108 ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500",
1109 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1110 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1111 self.assertEqual(exited, 0)
1113 logging.exception("")
1115 expect_container = copy.deepcopy(stubs.expect_container_spec)
1116 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1117 '--no-log-timestamps', '--disable-validate',
1118 '--eval-timeout=20', '--thread-count=1',
1119 '--enable-reuse', "--collection-cache-size=500",
1120 '--debug', '--on-error=continue',
1121 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1122 expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024
1124 stubs.api.container_requests().create.assert_called_with(
1125 body=JsonDiffMatcher(expect_container))
1126 self.assertEqual(capture_stdout.getvalue(),
1127 stubs.expect_container_request_uuid + '\n')
1131 def test_submit_container_thread_count(self, stubs):
1132 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1133 capture_stdout = cStringIO.StringIO()
1135 exited = arvados_cwl.main(
1136 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
1137 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1138 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1139 self.assertEqual(exited, 0)
1141 logging.exception("")
1143 expect_container = copy.deepcopy(stubs.expect_container_spec)
1144 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1145 '--no-log-timestamps', '--disable-validate',
1146 '--eval-timeout=20', '--thread-count=20',
1147 '--enable-reuse', "--collection-cache-size=256",
1148 '--debug', '--on-error=continue',
1149 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1151 stubs.api.container_requests().create.assert_called_with(
1152 body=JsonDiffMatcher(expect_container))
1153 self.assertEqual(capture_stdout.getvalue(),
1154 stubs.expect_container_request_uuid + '\n')
1158 def test_submit_job_runner_image(self, stubs):
1159 capture_stdout = cStringIO.StringIO()
1161 exited = arvados_cwl.main(
1162 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
1163 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1164 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1165 self.assertEqual(exited, 0)
1167 logging.exception("")
1169 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99"
1171 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
1172 stubs.api.pipeline_instances().create.assert_called_with(
1173 body=JsonDiffMatcher(expect_pipeline))
1174 self.assertEqual(capture_stdout.getvalue(),
1175 stubs.expect_pipeline_uuid + '\n')
1178 def test_submit_container_runner_image(self, stubs):
1179 capture_stdout = cStringIO.StringIO()
1181 exited = arvados_cwl.main(
1182 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
1183 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1184 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1185 self.assertEqual(exited, 0)
1187 logging.exception("")
1189 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
1191 expect_container = copy.deepcopy(stubs.expect_container_spec)
1192 stubs.api.container_requests().create.assert_called_with(
1193 body=JsonDiffMatcher(expect_container))
1194 self.assertEqual(capture_stdout.getvalue(),
1195 stubs.expect_container_request_uuid + '\n')
1198 def test_submit_priority(self, stubs):
1199 capture_stdout = cStringIO.StringIO()
1201 exited = arvados_cwl.main(
1202 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
1203 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1204 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1205 self.assertEqual(exited, 0)
1207 logging.exception("")
1209 stubs.expect_container_spec["priority"] = 669
1211 expect_container = copy.deepcopy(stubs.expect_container_spec)
1212 stubs.api.container_requests().create.assert_called_with(
1213 body=JsonDiffMatcher(expect_container))
1214 self.assertEqual(capture_stdout.getvalue(),
1215 stubs.expect_container_request_uuid + '\n')
1219 def test_submit_wf_runner_resources(self, stubs):
1220 capture_stdout = cStringIO.StringIO()
1222 exited = arvados_cwl.main(
1223 ["--submit", "--no-wait", "--api=containers", "--debug",
1224 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
1225 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1226 self.assertEqual(exited, 0)
1228 logging.exception("")
1230 expect_container = copy.deepcopy(stubs.expect_container_spec)
1231 expect_container["runtime_constraints"] = {
1234 "ram": (2000+512) * 2**20
1236 expect_container["name"] = "submit_wf_runner_resources.cwl"
1237 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
1239 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
1245 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
1246 "arv": "http://arvados.org/cwl#",
1248 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
1249 '--no-log-timestamps', '--disable-validate',
1250 '--eval-timeout=20', '--thread-count=1',
1251 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
1252 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1254 stubs.api.container_requests().create.assert_called_with(
1255 body=JsonDiffMatcher(expect_container))
1256 self.assertEqual(capture_stdout.getvalue(),
1257 stubs.expect_container_request_uuid + '\n')
1260 arvados_cwl.arvdocker.arv_docker_clear_cache()
1262 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1263 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1264 @mock.patch("arvados.api")
1265 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1266 arvados_cwl.arvdocker.arv_docker_clear_cache()
1268 arvrunner = mock.MagicMock()
1269 arvrunner.project_uuid = ""
1270 api.return_value = mock.MagicMock()
1271 arvrunner.api = api.return_value
1272 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1273 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1274 "link_class": "docker_image_repo+tag",
1275 "name": "arvados/jobs:"+arvados_cwl.__version__,
1277 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1278 {"items": [{"created_at": "",
1280 "link_class": "docker_image_hash",
1283 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1285 find_one_image_hash.return_value = "123456"
1287 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1289 "manifest_text": "",
1291 }], "items_available": 1, "offset": 0},)
1292 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1293 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1294 "portable_data_hash": "9999999999999999999999999999999b+99"}
1295 self.assertEqual("9999999999999999999999999999999b+99",
1296 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1300 def test_submit_secrets(self, stubs):
1301 capture_stdout = cStringIO.StringIO()
1303 exited = arvados_cwl.main(
1304 ["--submit", "--no-wait", "--api=containers", "--debug",
1305 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1306 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1307 self.assertEqual(exited, 0)
1309 logging.exception("")
1312 expect_container = {
1314 "arvados-cwl-runner",
1317 "--no-log-timestamps",
1318 "--disable-validate",
1319 "--eval-timeout=20",
1322 "--collection-cache-size=256",
1324 "--on-error=continue",
1325 "/var/lib/cwl/workflow.json#main",
1326 "/var/lib/cwl/cwl.input.json"
1328 "container_image": "999999999999999999999999999999d3+99",
1329 "cwd": "/var/spool/cwl",
1331 "/var/lib/cwl/cwl.input.json": {
1334 "$include": "/secrets/s0"
1339 "/var/lib/cwl/workflow.json": {
1344 "cwltool": "http://commonwl.org/cwltool#"
1350 "class": "CommandLineTool",
1353 "class": "http://commonwl.org/cwltool#Secrets",
1355 "#secret_job.cwl/pw"
1359 "id": "#secret_job.cwl",
1362 "id": "#secret_job.cwl/pw",
1368 "id": "#secret_job.cwl/out",
1372 "stdout": "hashed_example.txt",
1375 "class": "InitialWorkDirRequirement",
1378 "entry": "username: user\npassword: $(inputs.pw)\n",
1379 "entryname": "example.conf"
1386 "class": "Workflow",
1389 "class": "DockerRequirement",
1390 "dockerPull": "debian:8",
1391 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1394 "class": "http://commonwl.org/cwltool#Secrets",
1410 "outputSource": "#main/step1/out",
1416 "id": "#main/step1",
1419 "id": "#main/step1/pw",
1420 "source": "#main/pw"
1426 "run": "#secret_job.cwl"
1431 "cwlVersion": "v1.0"
1436 "kind": "collection",
1441 "path": "/var/spool/cwl/cwl.output.json"
1444 "name": "secret_wf.cwl",
1445 "output_path": "/var/spool/cwl",
1448 "runtime_constraints": {
1459 "state": "Committed",
1460 "use_existing": True
1463 stubs.api.container_requests().create.assert_called_with(
1464 body=JsonDiffMatcher(expect_container))
1465 self.assertEqual(capture_stdout.getvalue(),
1466 stubs.expect_container_request_uuid + '\n')
1469 def test_submit_request_uuid(self, stubs):
1470 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1472 stubs.api.container_requests().update().execute.return_value = {
1473 "uuid": stubs.expect_container_request_uuid,
1474 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1478 capture_stdout = cStringIO.StringIO()
1480 exited = arvados_cwl.main(
1481 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1482 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1483 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1484 self.assertEqual(exited, 0)
1486 logging.exception("")
1488 stubs.api.container_requests().update.assert_called_with(
1489 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz")
1490 self.assertEqual(capture_stdout.getvalue(),
1491 stubs.expect_container_request_uuid + '\n')
1494 def test_submit_container_cluster_id(self, stubs):
1495 capture_stdout = cStringIO.StringIO()
1496 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1498 exited = arvados_cwl.main(
1499 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1500 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1501 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1502 self.assertEqual(exited, 0)
1504 logging.exception("")
1506 expect_container = copy.deepcopy(stubs.expect_container_spec)
1508 stubs.api.container_requests().create.assert_called_with(
1509 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1510 self.assertEqual(capture_stdout.getvalue(),
1511 stubs.expect_container_request_uuid + '\n')
1515 def test_submit_validate_cluster_id(self, stubs):
1516 capture_stdout = cStringIO.StringIO()
1517 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1518 exited = arvados_cwl.main(
1519 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1520 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1521 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1522 self.assertEqual(exited, 1)
1525 class TestCreateTemplate(unittest.TestCase):
1526 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1528 def _adjust_script_params(self, expect_component):
1529 expect_component['script_parameters']['x'] = {
1530 'dataclass': 'File',
1533 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1535 expect_component['script_parameters']['y'] = {
1536 'dataclass': 'Collection',
1538 'type': 'Directory',
1539 'value': '99999999999999999999999999999998+99',
1541 expect_component['script_parameters']['z'] = {
1542 'dataclass': 'Collection',
1544 'type': 'Directory',
1548 def test_create(self, stubs):
1549 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1551 capture_stdout = cStringIO.StringIO()
1553 exited = arvados_cwl.main(
1554 ["--create-workflow", "--debug",
1556 "--project-uuid", project_uuid,
1557 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1558 capture_stdout, sys.stderr, api_client=stubs.api)
1559 self.assertEqual(exited, 0)
1561 stubs.api.pipeline_instances().create.refute_called()
1562 stubs.api.jobs().create.refute_called()
1564 expect_component = copy.deepcopy(stubs.expect_job_spec)
1565 self._adjust_script_params(expect_component)
1568 "submit_wf.cwl": expect_component,
1570 "name": "submit_wf.cwl",
1571 "owner_uuid": project_uuid,
1573 stubs.api.pipeline_templates().create.assert_called_with(
1574 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1576 self.assertEqual(capture_stdout.getvalue(),
1577 stubs.expect_pipeline_template_uuid + '\n')
1581 def test_create_name(self, stubs):
1582 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1584 capture_stdout = cStringIO.StringIO()
1586 exited = arvados_cwl.main(
1587 ["--create-workflow", "--debug",
1588 "--project-uuid", project_uuid,
1590 "--name", "testing 123",
1591 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1592 capture_stdout, sys.stderr, api_client=stubs.api)
1593 self.assertEqual(exited, 0)
1595 stubs.api.pipeline_instances().create.refute_called()
1596 stubs.api.jobs().create.refute_called()
1598 expect_component = copy.deepcopy(stubs.expect_job_spec)
1599 self._adjust_script_params(expect_component)
1602 "testing 123": expect_component,
1604 "name": "testing 123",
1605 "owner_uuid": project_uuid,
1607 stubs.api.pipeline_templates().create.assert_called_with(
1608 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1610 self.assertEqual(capture_stdout.getvalue(),
1611 stubs.expect_pipeline_template_uuid + '\n')
1615 def test_update_name(self, stubs):
1616 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1618 capture_stdout = cStringIO.StringIO()
1620 exited = arvados_cwl.main(
1621 ["--update-workflow", self.existing_template_uuid,
1623 "--project-uuid", project_uuid,
1625 "--name", "testing 123",
1626 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1627 capture_stdout, sys.stderr, api_client=stubs.api)
1628 self.assertEqual(exited, 0)
1630 stubs.api.pipeline_instances().create.refute_called()
1631 stubs.api.jobs().create.refute_called()
1633 expect_component = copy.deepcopy(stubs.expect_job_spec)
1634 self._adjust_script_params(expect_component)
1637 "testing 123": expect_component,
1639 "name": "testing 123",
1640 "owner_uuid": project_uuid,
1642 stubs.api.pipeline_templates().create.refute_called()
1643 stubs.api.pipeline_templates().update.assert_called_with(
1644 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1646 self.assertEqual(capture_stdout.getvalue(),
1647 self.existing_template_uuid + '\n')
1650 class TestCreateWorkflow(unittest.TestCase):
1651 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1652 expect_workflow = StripYAMLComments(
1653 open("tests/wf/expect_packed.cwl").read())
1656 def test_create(self, stubs):
1657 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1659 capture_stdout = cStringIO.StringIO()
1661 exited = arvados_cwl.main(
1662 ["--create-workflow", "--debug",
1664 "--project-uuid", project_uuid,
1665 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1666 capture_stdout, sys.stderr, api_client=stubs.api)
1667 self.assertEqual(exited, 0)
1669 stubs.api.pipeline_templates().create.refute_called()
1670 stubs.api.container_requests().create.refute_called()
1674 "owner_uuid": project_uuid,
1675 "name": "submit_wf.cwl",
1677 "definition": self.expect_workflow,
1680 stubs.api.workflows().create.assert_called_with(
1681 body=JsonDiffMatcher(body))
1683 self.assertEqual(capture_stdout.getvalue(),
1684 stubs.expect_workflow_uuid + '\n')
1688 def test_create_name(self, stubs):
1689 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1691 capture_stdout = cStringIO.StringIO()
1693 exited = arvados_cwl.main(
1694 ["--create-workflow", "--debug",
1696 "--project-uuid", project_uuid,
1697 "--name", "testing 123",
1698 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1699 capture_stdout, sys.stderr, api_client=stubs.api)
1700 self.assertEqual(exited, 0)
1702 stubs.api.pipeline_templates().create.refute_called()
1703 stubs.api.container_requests().create.refute_called()
1707 "owner_uuid": project_uuid,
1708 "name": "testing 123",
1710 "definition": self.expect_workflow,
1713 stubs.api.workflows().create.assert_called_with(
1714 body=JsonDiffMatcher(body))
1716 self.assertEqual(capture_stdout.getvalue(),
1717 stubs.expect_workflow_uuid + '\n')
1720 def test_incompatible_api(self, stubs):
1721 capture_stderr = cStringIO.StringIO()
1722 logging.getLogger('arvados.cwl-runner').addHandler(
1723 logging.StreamHandler(capture_stderr))
1725 exited = arvados_cwl.main(
1726 ["--update-workflow", self.existing_workflow_uuid,
1729 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1730 sys.stderr, sys.stderr, api_client=stubs.api)
1731 self.assertEqual(exited, 1)
1732 self.assertRegexpMatches(
1733 capture_stderr.getvalue(),
1734 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1737 def test_update(self, stubs):
1738 capture_stdout = cStringIO.StringIO()
1740 exited = arvados_cwl.main(
1741 ["--update-workflow", self.existing_workflow_uuid,
1743 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1744 capture_stdout, sys.stderr, api_client=stubs.api)
1745 self.assertEqual(exited, 0)
1749 "name": "submit_wf.cwl",
1751 "definition": self.expect_workflow,
1754 stubs.api.workflows().update.assert_called_with(
1755 uuid=self.existing_workflow_uuid,
1756 body=JsonDiffMatcher(body))
1757 self.assertEqual(capture_stdout.getvalue(),
1758 self.existing_workflow_uuid + '\n')
1762 def test_update_name(self, stubs):
1763 capture_stdout = cStringIO.StringIO()
1765 exited = arvados_cwl.main(
1766 ["--update-workflow", self.existing_workflow_uuid,
1767 "--debug", "--name", "testing 123",
1768 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1769 capture_stdout, sys.stderr, api_client=stubs.api)
1770 self.assertEqual(exited, 0)
1774 "name": "testing 123",
1776 "definition": self.expect_workflow,
1779 stubs.api.workflows().update.assert_called_with(
1780 uuid=self.existing_workflow_uuid,
1781 body=JsonDiffMatcher(body))
1782 self.assertEqual(capture_stdout.getvalue(),
1783 self.existing_workflow_uuid + '\n')
1787 def test_create_collection_per_tool(self, stubs):
1788 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1790 capture_stdout = cStringIO.StringIO()
1792 exited = arvados_cwl.main(
1793 ["--create-workflow", "--debug",
1795 "--project-uuid", project_uuid,
1796 "tests/collection_per_tool/collection_per_tool.cwl"],
1797 capture_stdout, sys.stderr, api_client=stubs.api)
1798 self.assertEqual(exited, 0)
1800 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1801 expect_workflow = StripYAMLComments(open(toolfile).read())
1805 "owner_uuid": project_uuid,
1806 "name": "collection_per_tool.cwl",
1808 "definition": expect_workflow,
1811 stubs.api.workflows().create.assert_called_with(
1812 body=JsonDiffMatcher(body))
1814 self.assertEqual(capture_stdout.getvalue(),
1815 stubs.expect_workflow_uuid + '\n')
1817 class TestTemplateInputs(unittest.TestCase):
1820 "inputs_test.cwl": {
1821 'runtime_constraints': {
1822 'docker_image': '999999999999999999999999999999d3+99',
1823 'min_ram_mb_per_node': 1024
1825 'script_parameters': {
1827 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main',
1828 'optionalFloatInput': None,
1831 'dataclass': 'File',
1833 'title': "It's a file; we expect to find some characters in it.",
1834 'description': 'If there were anything further to say, it would be said here,\nor here.'
1838 'dataclass': 'number',
1840 'title': 'Floats like a duck',
1844 'optionalFloatInput': {
1845 'type': ['null', 'float'],
1846 'dataclass': 'number',
1851 'dataclass': 'boolean',
1853 'title': 'True or false?',
1856 'repository': 'arvados',
1857 'script_version': 'master',
1858 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1859 'script': 'cwl-runner',
1862 "name": "inputs_test.cwl",
1866 def test_inputs_empty(self, stubs):
1867 exited = arvados_cwl.main(
1868 ["--create-template",
1869 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1870 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1871 self.assertEqual(exited, 0)
1873 stubs.api.pipeline_templates().create.assert_called_with(
1874 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1877 def test_inputs(self, stubs):
1878 exited = arvados_cwl.main(
1879 ["--create-template",
1880 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1881 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1882 self.assertEqual(exited, 0)
1884 expect_template = copy.deepcopy(self.expect_template)
1885 params = expect_template[
1886 "components"]["inputs_test.cwl"]["script_parameters"]
1887 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1888 params["cwl:tool"] = 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main'
1889 params["floatInput"]["value"] = 1.234
1890 params["boolInput"]["value"] = True
1892 stubs.api.pipeline_templates().create.assert_called_with(
1893 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)