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_missing_input(self, stubs):
1050 capture_stdout = cStringIO.StringIO()
1051 exited = arvados_cwl.main(
1052 ["--submit", "--no-wait", "--api=containers", "--debug",
1053 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1054 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1055 self.assertEqual(exited, 0)
1057 capture_stdout = cStringIO.StringIO()
1058 exited = arvados_cwl.main(
1059 ["--submit", "--no-wait", "--api=containers", "--debug",
1060 "tests/wf/submit_wf.cwl", "tests/submit_test_job_missing.json"],
1061 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1062 self.assertEqual(exited, 1)
1066 def test_submit_container_project(self, stubs):
1067 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1068 capture_stdout = cStringIO.StringIO()
1070 exited = arvados_cwl.main(
1071 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
1072 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1073 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1074 self.assertEqual(exited, 0)
1076 logging.exception("")
1078 expect_container = copy.deepcopy(stubs.expect_container_spec)
1079 expect_container["owner_uuid"] = project_uuid
1080 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1081 '--no-log-timestamps', '--disable-validate',
1082 "--eval-timeout=20", "--thread-count=1",
1083 '--enable-reuse', "--collection-cache-size=256", '--debug',
1084 '--on-error=continue',
1085 '--project-uuid='+project_uuid,
1086 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1088 stubs.api.container_requests().create.assert_called_with(
1089 body=JsonDiffMatcher(expect_container))
1090 self.assertEqual(capture_stdout.getvalue(),
1091 stubs.expect_container_request_uuid + '\n')
1094 def test_submit_container_eval_timeout(self, stubs):
1095 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1096 capture_stdout = cStringIO.StringIO()
1098 exited = arvados_cwl.main(
1099 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
1100 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1101 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1102 self.assertEqual(exited, 0)
1104 logging.exception("")
1106 expect_container = copy.deepcopy(stubs.expect_container_spec)
1107 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1108 '--no-log-timestamps', '--disable-validate',
1109 '--eval-timeout=60.0', '--thread-count=1',
1110 '--enable-reuse', "--collection-cache-size=256",
1111 '--debug', '--on-error=continue',
1112 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1114 stubs.api.container_requests().create.assert_called_with(
1115 body=JsonDiffMatcher(expect_container))
1116 self.assertEqual(capture_stdout.getvalue(),
1117 stubs.expect_container_request_uuid + '\n')
1120 def test_submit_container_collection_cache(self, stubs):
1121 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1122 capture_stdout = cStringIO.StringIO()
1124 exited = arvados_cwl.main(
1125 ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500",
1126 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1127 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1128 self.assertEqual(exited, 0)
1130 logging.exception("")
1132 expect_container = copy.deepcopy(stubs.expect_container_spec)
1133 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1134 '--no-log-timestamps', '--disable-validate',
1135 '--eval-timeout=20', '--thread-count=1',
1136 '--enable-reuse', "--collection-cache-size=500",
1137 '--debug', '--on-error=continue',
1138 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1139 expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024
1141 stubs.api.container_requests().create.assert_called_with(
1142 body=JsonDiffMatcher(expect_container))
1143 self.assertEqual(capture_stdout.getvalue(),
1144 stubs.expect_container_request_uuid + '\n')
1148 def test_submit_container_thread_count(self, stubs):
1149 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1150 capture_stdout = cStringIO.StringIO()
1152 exited = arvados_cwl.main(
1153 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
1154 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1155 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1156 self.assertEqual(exited, 0)
1158 logging.exception("")
1160 expect_container = copy.deepcopy(stubs.expect_container_spec)
1161 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1162 '--no-log-timestamps', '--disable-validate',
1163 '--eval-timeout=20', '--thread-count=20',
1164 '--enable-reuse', "--collection-cache-size=256",
1165 '--debug', '--on-error=continue',
1166 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1168 stubs.api.container_requests().create.assert_called_with(
1169 body=JsonDiffMatcher(expect_container))
1170 self.assertEqual(capture_stdout.getvalue(),
1171 stubs.expect_container_request_uuid + '\n')
1175 def test_submit_job_runner_image(self, stubs):
1176 capture_stdout = cStringIO.StringIO()
1178 exited = arvados_cwl.main(
1179 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
1180 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1181 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1182 self.assertEqual(exited, 0)
1184 logging.exception("")
1186 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99"
1188 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
1189 stubs.api.pipeline_instances().create.assert_called_with(
1190 body=JsonDiffMatcher(expect_pipeline))
1191 self.assertEqual(capture_stdout.getvalue(),
1192 stubs.expect_pipeline_uuid + '\n')
1195 def test_submit_container_runner_image(self, stubs):
1196 capture_stdout = cStringIO.StringIO()
1198 exited = arvados_cwl.main(
1199 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
1200 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1201 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1202 self.assertEqual(exited, 0)
1204 logging.exception("")
1206 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
1208 expect_container = copy.deepcopy(stubs.expect_container_spec)
1209 stubs.api.container_requests().create.assert_called_with(
1210 body=JsonDiffMatcher(expect_container))
1211 self.assertEqual(capture_stdout.getvalue(),
1212 stubs.expect_container_request_uuid + '\n')
1215 def test_submit_priority(self, stubs):
1216 capture_stdout = cStringIO.StringIO()
1218 exited = arvados_cwl.main(
1219 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
1220 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1221 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1222 self.assertEqual(exited, 0)
1224 logging.exception("")
1226 stubs.expect_container_spec["priority"] = 669
1228 expect_container = copy.deepcopy(stubs.expect_container_spec)
1229 stubs.api.container_requests().create.assert_called_with(
1230 body=JsonDiffMatcher(expect_container))
1231 self.assertEqual(capture_stdout.getvalue(),
1232 stubs.expect_container_request_uuid + '\n')
1236 def test_submit_wf_runner_resources(self, stubs):
1237 capture_stdout = cStringIO.StringIO()
1239 exited = arvados_cwl.main(
1240 ["--submit", "--no-wait", "--api=containers", "--debug",
1241 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
1242 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1243 self.assertEqual(exited, 0)
1245 logging.exception("")
1247 expect_container = copy.deepcopy(stubs.expect_container_spec)
1248 expect_container["runtime_constraints"] = {
1251 "ram": (2000+512) * 2**20
1253 expect_container["name"] = "submit_wf_runner_resources.cwl"
1254 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
1256 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
1262 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
1263 "arv": "http://arvados.org/cwl#",
1265 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
1266 '--no-log-timestamps', '--disable-validate',
1267 '--eval-timeout=20', '--thread-count=1',
1268 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
1269 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1271 stubs.api.container_requests().create.assert_called_with(
1272 body=JsonDiffMatcher(expect_container))
1273 self.assertEqual(capture_stdout.getvalue(),
1274 stubs.expect_container_request_uuid + '\n')
1277 arvados_cwl.arvdocker.arv_docker_clear_cache()
1279 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1280 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1281 @mock.patch("arvados.api")
1282 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1283 arvados_cwl.arvdocker.arv_docker_clear_cache()
1285 arvrunner = mock.MagicMock()
1286 arvrunner.project_uuid = ""
1287 api.return_value = mock.MagicMock()
1288 arvrunner.api = api.return_value
1289 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1290 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1291 "link_class": "docker_image_repo+tag",
1292 "name": "arvados/jobs:"+arvados_cwl.__version__,
1294 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1295 {"items": [{"created_at": "",
1297 "link_class": "docker_image_hash",
1300 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1302 find_one_image_hash.return_value = "123456"
1304 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1306 "manifest_text": "",
1308 }], "items_available": 1, "offset": 0},)
1309 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1310 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1311 "portable_data_hash": "9999999999999999999999999999999b+99"}
1312 self.assertEqual("9999999999999999999999999999999b+99",
1313 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1317 def test_submit_secrets(self, stubs):
1318 capture_stdout = cStringIO.StringIO()
1320 exited = arvados_cwl.main(
1321 ["--submit", "--no-wait", "--api=containers", "--debug",
1322 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1323 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1324 self.assertEqual(exited, 0)
1326 logging.exception("")
1329 expect_container = {
1331 "arvados-cwl-runner",
1334 "--no-log-timestamps",
1335 "--disable-validate",
1336 "--eval-timeout=20",
1339 "--collection-cache-size=256",
1341 "--on-error=continue",
1342 "/var/lib/cwl/workflow.json#main",
1343 "/var/lib/cwl/cwl.input.json"
1345 "container_image": "999999999999999999999999999999d3+99",
1346 "cwd": "/var/spool/cwl",
1348 "/var/lib/cwl/cwl.input.json": {
1351 "$include": "/secrets/s0"
1356 "/var/lib/cwl/workflow.json": {
1361 "cwltool": "http://commonwl.org/cwltool#"
1367 "class": "CommandLineTool",
1370 "class": "http://commonwl.org/cwltool#Secrets",
1372 "#secret_job.cwl/pw"
1376 "id": "#secret_job.cwl",
1379 "id": "#secret_job.cwl/pw",
1385 "id": "#secret_job.cwl/out",
1389 "stdout": "hashed_example.txt",
1392 "class": "InitialWorkDirRequirement",
1395 "entry": "username: user\npassword: $(inputs.pw)\n",
1396 "entryname": "example.conf"
1403 "class": "Workflow",
1406 "class": "DockerRequirement",
1407 "dockerPull": "debian:8",
1408 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1411 "class": "http://commonwl.org/cwltool#Secrets",
1427 "outputSource": "#main/step1/out",
1433 "id": "#main/step1",
1436 "id": "#main/step1/pw",
1437 "source": "#main/pw"
1443 "run": "#secret_job.cwl"
1448 "cwlVersion": "v1.0"
1453 "kind": "collection",
1458 "path": "/var/spool/cwl/cwl.output.json"
1461 "name": "secret_wf.cwl",
1462 "output_path": "/var/spool/cwl",
1465 "runtime_constraints": {
1476 "state": "Committed",
1477 "use_existing": True
1480 stubs.api.container_requests().create.assert_called_with(
1481 body=JsonDiffMatcher(expect_container))
1482 self.assertEqual(capture_stdout.getvalue(),
1483 stubs.expect_container_request_uuid + '\n')
1486 def test_submit_request_uuid(self, stubs):
1487 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1489 stubs.api.container_requests().update().execute.return_value = {
1490 "uuid": stubs.expect_container_request_uuid,
1491 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1495 capture_stdout = cStringIO.StringIO()
1497 exited = arvados_cwl.main(
1498 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1499 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1500 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1501 self.assertEqual(exited, 0)
1503 logging.exception("")
1505 stubs.api.container_requests().update.assert_called_with(
1506 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz")
1507 self.assertEqual(capture_stdout.getvalue(),
1508 stubs.expect_container_request_uuid + '\n')
1511 def test_submit_container_cluster_id(self, stubs):
1512 capture_stdout = cStringIO.StringIO()
1513 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1515 exited = arvados_cwl.main(
1516 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1517 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1518 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1519 self.assertEqual(exited, 0)
1521 logging.exception("")
1523 expect_container = copy.deepcopy(stubs.expect_container_spec)
1525 stubs.api.container_requests().create.assert_called_with(
1526 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1527 self.assertEqual(capture_stdout.getvalue(),
1528 stubs.expect_container_request_uuid + '\n')
1532 def test_submit_validate_cluster_id(self, stubs):
1533 capture_stdout = cStringIO.StringIO()
1534 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1535 exited = arvados_cwl.main(
1536 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1537 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1538 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1539 self.assertEqual(exited, 1)
1542 class TestCreateTemplate(unittest.TestCase):
1543 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1545 def _adjust_script_params(self, expect_component):
1546 expect_component['script_parameters']['x'] = {
1547 'dataclass': 'File',
1550 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1552 expect_component['script_parameters']['y'] = {
1553 'dataclass': 'Collection',
1555 'type': 'Directory',
1556 'value': '99999999999999999999999999999998+99',
1558 expect_component['script_parameters']['z'] = {
1559 'dataclass': 'Collection',
1561 'type': 'Directory',
1565 def test_create(self, stubs):
1566 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1568 capture_stdout = cStringIO.StringIO()
1570 exited = arvados_cwl.main(
1571 ["--create-workflow", "--debug",
1573 "--project-uuid", project_uuid,
1574 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1575 capture_stdout, sys.stderr, api_client=stubs.api)
1576 self.assertEqual(exited, 0)
1578 stubs.api.pipeline_instances().create.refute_called()
1579 stubs.api.jobs().create.refute_called()
1581 expect_component = copy.deepcopy(stubs.expect_job_spec)
1582 self._adjust_script_params(expect_component)
1585 "submit_wf.cwl": expect_component,
1587 "name": "submit_wf.cwl",
1588 "owner_uuid": project_uuid,
1590 stubs.api.pipeline_templates().create.assert_called_with(
1591 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1593 self.assertEqual(capture_stdout.getvalue(),
1594 stubs.expect_pipeline_template_uuid + '\n')
1598 def test_create_name(self, stubs):
1599 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1601 capture_stdout = cStringIO.StringIO()
1603 exited = arvados_cwl.main(
1604 ["--create-workflow", "--debug",
1605 "--project-uuid", project_uuid,
1607 "--name", "testing 123",
1608 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1609 capture_stdout, sys.stderr, api_client=stubs.api)
1610 self.assertEqual(exited, 0)
1612 stubs.api.pipeline_instances().create.refute_called()
1613 stubs.api.jobs().create.refute_called()
1615 expect_component = copy.deepcopy(stubs.expect_job_spec)
1616 self._adjust_script_params(expect_component)
1619 "testing 123": expect_component,
1621 "name": "testing 123",
1622 "owner_uuid": project_uuid,
1624 stubs.api.pipeline_templates().create.assert_called_with(
1625 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1627 self.assertEqual(capture_stdout.getvalue(),
1628 stubs.expect_pipeline_template_uuid + '\n')
1632 def test_update_name(self, stubs):
1633 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1635 capture_stdout = cStringIO.StringIO()
1637 exited = arvados_cwl.main(
1638 ["--update-workflow", self.existing_template_uuid,
1640 "--project-uuid", project_uuid,
1642 "--name", "testing 123",
1643 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1644 capture_stdout, sys.stderr, api_client=stubs.api)
1645 self.assertEqual(exited, 0)
1647 stubs.api.pipeline_instances().create.refute_called()
1648 stubs.api.jobs().create.refute_called()
1650 expect_component = copy.deepcopy(stubs.expect_job_spec)
1651 self._adjust_script_params(expect_component)
1654 "testing 123": expect_component,
1656 "name": "testing 123",
1657 "owner_uuid": project_uuid,
1659 stubs.api.pipeline_templates().create.refute_called()
1660 stubs.api.pipeline_templates().update.assert_called_with(
1661 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1663 self.assertEqual(capture_stdout.getvalue(),
1664 self.existing_template_uuid + '\n')
1667 class TestCreateWorkflow(unittest.TestCase):
1668 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1669 expect_workflow = StripYAMLComments(
1670 open("tests/wf/expect_packed.cwl").read())
1673 def test_create(self, stubs):
1674 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1676 capture_stdout = cStringIO.StringIO()
1678 exited = arvados_cwl.main(
1679 ["--create-workflow", "--debug",
1681 "--project-uuid", project_uuid,
1682 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1683 capture_stdout, sys.stderr, api_client=stubs.api)
1684 self.assertEqual(exited, 0)
1686 stubs.api.pipeline_templates().create.refute_called()
1687 stubs.api.container_requests().create.refute_called()
1691 "owner_uuid": project_uuid,
1692 "name": "submit_wf.cwl",
1694 "definition": self.expect_workflow,
1697 stubs.api.workflows().create.assert_called_with(
1698 body=JsonDiffMatcher(body))
1700 self.assertEqual(capture_stdout.getvalue(),
1701 stubs.expect_workflow_uuid + '\n')
1705 def test_create_name(self, stubs):
1706 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1708 capture_stdout = cStringIO.StringIO()
1710 exited = arvados_cwl.main(
1711 ["--create-workflow", "--debug",
1713 "--project-uuid", project_uuid,
1714 "--name", "testing 123",
1715 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1716 capture_stdout, sys.stderr, api_client=stubs.api)
1717 self.assertEqual(exited, 0)
1719 stubs.api.pipeline_templates().create.refute_called()
1720 stubs.api.container_requests().create.refute_called()
1724 "owner_uuid": project_uuid,
1725 "name": "testing 123",
1727 "definition": self.expect_workflow,
1730 stubs.api.workflows().create.assert_called_with(
1731 body=JsonDiffMatcher(body))
1733 self.assertEqual(capture_stdout.getvalue(),
1734 stubs.expect_workflow_uuid + '\n')
1737 def test_incompatible_api(self, stubs):
1738 capture_stderr = cStringIO.StringIO()
1739 logging.getLogger('arvados.cwl-runner').addHandler(
1740 logging.StreamHandler(capture_stderr))
1742 exited = arvados_cwl.main(
1743 ["--update-workflow", self.existing_workflow_uuid,
1746 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1747 sys.stderr, sys.stderr, api_client=stubs.api)
1748 self.assertEqual(exited, 1)
1749 self.assertRegexpMatches(
1750 capture_stderr.getvalue(),
1751 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1754 def test_update(self, stubs):
1755 capture_stdout = cStringIO.StringIO()
1757 exited = arvados_cwl.main(
1758 ["--update-workflow", self.existing_workflow_uuid,
1760 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1761 capture_stdout, sys.stderr, api_client=stubs.api)
1762 self.assertEqual(exited, 0)
1766 "name": "submit_wf.cwl",
1768 "definition": self.expect_workflow,
1771 stubs.api.workflows().update.assert_called_with(
1772 uuid=self.existing_workflow_uuid,
1773 body=JsonDiffMatcher(body))
1774 self.assertEqual(capture_stdout.getvalue(),
1775 self.existing_workflow_uuid + '\n')
1779 def test_update_name(self, stubs):
1780 capture_stdout = cStringIO.StringIO()
1782 exited = arvados_cwl.main(
1783 ["--update-workflow", self.existing_workflow_uuid,
1784 "--debug", "--name", "testing 123",
1785 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1786 capture_stdout, sys.stderr, api_client=stubs.api)
1787 self.assertEqual(exited, 0)
1791 "name": "testing 123",
1793 "definition": self.expect_workflow,
1796 stubs.api.workflows().update.assert_called_with(
1797 uuid=self.existing_workflow_uuid,
1798 body=JsonDiffMatcher(body))
1799 self.assertEqual(capture_stdout.getvalue(),
1800 self.existing_workflow_uuid + '\n')
1804 def test_create_collection_per_tool(self, stubs):
1805 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1807 capture_stdout = cStringIO.StringIO()
1809 exited = arvados_cwl.main(
1810 ["--create-workflow", "--debug",
1812 "--project-uuid", project_uuid,
1813 "tests/collection_per_tool/collection_per_tool.cwl"],
1814 capture_stdout, sys.stderr, api_client=stubs.api)
1815 self.assertEqual(exited, 0)
1817 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1818 expect_workflow = StripYAMLComments(open(toolfile).read())
1822 "owner_uuid": project_uuid,
1823 "name": "collection_per_tool.cwl",
1825 "definition": expect_workflow,
1828 stubs.api.workflows().create.assert_called_with(
1829 body=JsonDiffMatcher(body))
1831 self.assertEqual(capture_stdout.getvalue(),
1832 stubs.expect_workflow_uuid + '\n')
1834 class TestTemplateInputs(unittest.TestCase):
1837 "inputs_test.cwl": {
1838 'runtime_constraints': {
1839 'docker_image': '999999999999999999999999999999d3+99',
1840 'min_ram_mb_per_node': 1024
1842 'script_parameters': {
1844 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main',
1845 'optionalFloatInput': None,
1848 'dataclass': 'File',
1850 'title': "It's a file; we expect to find some characters in it.",
1851 'description': 'If there were anything further to say, it would be said here,\nor here.'
1855 'dataclass': 'number',
1857 'title': 'Floats like a duck',
1861 'optionalFloatInput': {
1862 'type': ['null', 'float'],
1863 'dataclass': 'number',
1868 'dataclass': 'boolean',
1870 'title': 'True or false?',
1873 'repository': 'arvados',
1874 'script_version': 'master',
1875 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1876 'script': 'cwl-runner',
1879 "name": "inputs_test.cwl",
1883 def test_inputs_empty(self, stubs):
1884 exited = arvados_cwl.main(
1885 ["--create-template",
1886 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1887 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1888 self.assertEqual(exited, 0)
1890 stubs.api.pipeline_templates().create.assert_called_with(
1891 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1894 def test_inputs(self, stubs):
1895 exited = arvados_cwl.main(
1896 ["--create-template",
1897 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1898 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1899 self.assertEqual(exited, 0)
1901 expect_template = copy.deepcopy(self.expect_template)
1902 params = expect_template[
1903 "components"]["inputs_test.cwl"]["script_parameters"]
1904 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1905 params["cwl:tool"] = 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main'
1906 params["floatInput"]["value"] = 1.234
1907 params["boolInput"]["value"] = True
1909 stubs.api.pipeline_templates().create.assert_called_with(
1910 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)