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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4',
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=4",
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=4',
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=60.0', '--thread-count=4',
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']
1123 stubs.api.container_requests().create.assert_called_with(
1124 body=JsonDiffMatcher(expect_container))
1125 self.assertEqual(capture_stdout.getvalue(),
1126 stubs.expect_container_request_uuid + '\n')
1130 def test_submit_container_thread_count(self, stubs):
1131 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1132 capture_stdout = cStringIO.StringIO()
1134 exited = arvados_cwl.main(
1135 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
1136 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1137 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1138 self.assertEqual(exited, 0)
1140 logging.exception("")
1142 expect_container = copy.deepcopy(stubs.expect_container_spec)
1143 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1144 '--no-log-timestamps', '--disable-validate',
1145 '--eval-timeout=20', '--thread-count=20',
1146 '--enable-reuse', "--collection-cache-size=256",
1147 '--debug', '--on-error=continue',
1148 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1150 stubs.api.container_requests().create.assert_called_with(
1151 body=JsonDiffMatcher(expect_container))
1152 self.assertEqual(capture_stdout.getvalue(),
1153 stubs.expect_container_request_uuid + '\n')
1157 def test_submit_job_runner_image(self, stubs):
1158 capture_stdout = cStringIO.StringIO()
1160 exited = arvados_cwl.main(
1161 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
1162 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1163 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1164 self.assertEqual(exited, 0)
1166 logging.exception("")
1168 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99"
1170 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
1171 stubs.api.pipeline_instances().create.assert_called_with(
1172 body=JsonDiffMatcher(expect_pipeline))
1173 self.assertEqual(capture_stdout.getvalue(),
1174 stubs.expect_pipeline_uuid + '\n')
1177 def test_submit_container_runner_image(self, stubs):
1178 capture_stdout = cStringIO.StringIO()
1180 exited = arvados_cwl.main(
1181 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
1182 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1183 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1184 self.assertEqual(exited, 0)
1186 logging.exception("")
1188 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
1190 expect_container = copy.deepcopy(stubs.expect_container_spec)
1191 stubs.api.container_requests().create.assert_called_with(
1192 body=JsonDiffMatcher(expect_container))
1193 self.assertEqual(capture_stdout.getvalue(),
1194 stubs.expect_container_request_uuid + '\n')
1197 def test_submit_priority(self, stubs):
1198 capture_stdout = cStringIO.StringIO()
1200 exited = arvados_cwl.main(
1201 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
1202 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1203 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1204 self.assertEqual(exited, 0)
1206 logging.exception("")
1208 stubs.expect_container_spec["priority"] = 669
1210 expect_container = copy.deepcopy(stubs.expect_container_spec)
1211 stubs.api.container_requests().create.assert_called_with(
1212 body=JsonDiffMatcher(expect_container))
1213 self.assertEqual(capture_stdout.getvalue(),
1214 stubs.expect_container_request_uuid + '\n')
1218 def test_submit_wf_runner_resources(self, stubs):
1219 capture_stdout = cStringIO.StringIO()
1221 exited = arvados_cwl.main(
1222 ["--submit", "--no-wait", "--api=containers", "--debug",
1223 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
1224 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1225 self.assertEqual(exited, 0)
1227 logging.exception("")
1229 expect_container = copy.deepcopy(stubs.expect_container_spec)
1230 expect_container["runtime_constraints"] = {
1233 "ram": (2000+512) * 2**20
1235 expect_container["name"] = "submit_wf_runner_resources.cwl"
1236 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
1238 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
1244 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
1245 "arv": "http://arvados.org/cwl#",
1247 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
1248 '--no-log-timestamps', '--disable-validate',
1249 '--eval-timeout=20', '--thread-count=4',
1250 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
1251 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1253 stubs.api.container_requests().create.assert_called_with(
1254 body=JsonDiffMatcher(expect_container))
1255 self.assertEqual(capture_stdout.getvalue(),
1256 stubs.expect_container_request_uuid + '\n')
1259 arvados_cwl.arvdocker.arv_docker_clear_cache()
1261 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1262 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1263 @mock.patch("arvados.api")
1264 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1265 arvados_cwl.arvdocker.arv_docker_clear_cache()
1267 arvrunner = mock.MagicMock()
1268 arvrunner.project_uuid = ""
1269 api.return_value = mock.MagicMock()
1270 arvrunner.api = api.return_value
1271 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1272 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1273 "link_class": "docker_image_repo+tag",
1274 "name": "arvados/jobs:"+arvados_cwl.__version__,
1276 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1277 {"items": [{"created_at": "",
1279 "link_class": "docker_image_hash",
1282 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1284 find_one_image_hash.return_value = "123456"
1286 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1288 "manifest_text": "",
1290 }], "items_available": 1, "offset": 0},)
1291 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1292 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1293 "portable_data_hash": "9999999999999999999999999999999b+99"}
1294 self.assertEqual("9999999999999999999999999999999b+99",
1295 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1299 def test_submit_secrets(self, stubs):
1300 capture_stdout = cStringIO.StringIO()
1302 exited = arvados_cwl.main(
1303 ["--submit", "--no-wait", "--api=containers", "--debug",
1304 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1305 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1306 self.assertEqual(exited, 0)
1308 logging.exception("")
1311 expect_container = {
1313 "arvados-cwl-runner",
1316 "--no-log-timestamps",
1317 "--disable-validate",
1318 "--eval-timeout=20",
1321 "--collection-cache-size=256",
1323 "--on-error=continue",
1324 "/var/lib/cwl/workflow.json#main",
1325 "/var/lib/cwl/cwl.input.json"
1327 "container_image": "999999999999999999999999999999d3+99",
1328 "cwd": "/var/spool/cwl",
1330 "/var/lib/cwl/cwl.input.json": {
1333 "$include": "/secrets/s0"
1338 "/var/lib/cwl/workflow.json": {
1343 "cwltool": "http://commonwl.org/cwltool#"
1349 "class": "CommandLineTool",
1352 "class": "http://commonwl.org/cwltool#Secrets",
1354 "#secret_job.cwl/pw"
1358 "id": "#secret_job.cwl",
1361 "id": "#secret_job.cwl/pw",
1367 "id": "#secret_job.cwl/out",
1371 "stdout": "hashed_example.txt",
1374 "class": "InitialWorkDirRequirement",
1377 "entry": "username: user\npassword: $(inputs.pw)\n",
1378 "entryname": "example.conf"
1385 "class": "Workflow",
1388 "class": "DockerRequirement",
1389 "dockerPull": "debian:8",
1390 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1393 "class": "http://commonwl.org/cwltool#Secrets",
1409 "outputSource": "#main/step1/out",
1415 "id": "#main/step1",
1418 "id": "#main/step1/pw",
1419 "source": "#main/pw"
1425 "run": "#secret_job.cwl"
1430 "cwlVersion": "v1.0"
1435 "kind": "collection",
1440 "path": "/var/spool/cwl/cwl.output.json"
1443 "name": "secret_wf.cwl",
1444 "output_path": "/var/spool/cwl",
1447 "runtime_constraints": {
1458 "state": "Committed",
1459 "use_existing": True
1462 stubs.api.container_requests().create.assert_called_with(
1463 body=JsonDiffMatcher(expect_container))
1464 self.assertEqual(capture_stdout.getvalue(),
1465 stubs.expect_container_request_uuid + '\n')
1468 def test_submit_request_uuid(self, stubs):
1469 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1471 stubs.api.container_requests().update().execute.return_value = {
1472 "uuid": stubs.expect_container_request_uuid,
1473 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1477 capture_stdout = cStringIO.StringIO()
1479 exited = arvados_cwl.main(
1480 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1481 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1482 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1483 self.assertEqual(exited, 0)
1485 logging.exception("")
1487 stubs.api.container_requests().update.assert_called_with(
1488 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz")
1489 self.assertEqual(capture_stdout.getvalue(),
1490 stubs.expect_container_request_uuid + '\n')
1493 def test_submit_container_cluster_id(self, stubs):
1494 capture_stdout = cStringIO.StringIO()
1495 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1497 exited = arvados_cwl.main(
1498 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
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 expect_container = copy.deepcopy(stubs.expect_container_spec)
1507 stubs.api.container_requests().create.assert_called_with(
1508 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1509 self.assertEqual(capture_stdout.getvalue(),
1510 stubs.expect_container_request_uuid + '\n')
1514 def test_submit_validate_cluster_id(self, stubs):
1515 capture_stdout = cStringIO.StringIO()
1516 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1517 exited = arvados_cwl.main(
1518 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1519 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1520 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1521 self.assertEqual(exited, 1)
1524 class TestCreateTemplate(unittest.TestCase):
1525 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1527 def _adjust_script_params(self, expect_component):
1528 expect_component['script_parameters']['x'] = {
1529 'dataclass': 'File',
1532 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1534 expect_component['script_parameters']['y'] = {
1535 'dataclass': 'Collection',
1537 'type': 'Directory',
1538 'value': '99999999999999999999999999999998+99',
1540 expect_component['script_parameters']['z'] = {
1541 'dataclass': 'Collection',
1543 'type': 'Directory',
1547 def test_create(self, stubs):
1548 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1550 capture_stdout = cStringIO.StringIO()
1552 exited = arvados_cwl.main(
1553 ["--create-workflow", "--debug",
1555 "--project-uuid", project_uuid,
1556 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1557 capture_stdout, sys.stderr, api_client=stubs.api)
1558 self.assertEqual(exited, 0)
1560 stubs.api.pipeline_instances().create.refute_called()
1561 stubs.api.jobs().create.refute_called()
1563 expect_component = copy.deepcopy(stubs.expect_job_spec)
1564 self._adjust_script_params(expect_component)
1567 "submit_wf.cwl": expect_component,
1569 "name": "submit_wf.cwl",
1570 "owner_uuid": project_uuid,
1572 stubs.api.pipeline_templates().create.assert_called_with(
1573 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1575 self.assertEqual(capture_stdout.getvalue(),
1576 stubs.expect_pipeline_template_uuid + '\n')
1580 def test_create_name(self, stubs):
1581 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1583 capture_stdout = cStringIO.StringIO()
1585 exited = arvados_cwl.main(
1586 ["--create-workflow", "--debug",
1587 "--project-uuid", project_uuid,
1589 "--name", "testing 123",
1590 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1591 capture_stdout, sys.stderr, api_client=stubs.api)
1592 self.assertEqual(exited, 0)
1594 stubs.api.pipeline_instances().create.refute_called()
1595 stubs.api.jobs().create.refute_called()
1597 expect_component = copy.deepcopy(stubs.expect_job_spec)
1598 self._adjust_script_params(expect_component)
1601 "testing 123": expect_component,
1603 "name": "testing 123",
1604 "owner_uuid": project_uuid,
1606 stubs.api.pipeline_templates().create.assert_called_with(
1607 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1609 self.assertEqual(capture_stdout.getvalue(),
1610 stubs.expect_pipeline_template_uuid + '\n')
1614 def test_update_name(self, stubs):
1615 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1617 capture_stdout = cStringIO.StringIO()
1619 exited = arvados_cwl.main(
1620 ["--update-workflow", self.existing_template_uuid,
1622 "--project-uuid", project_uuid,
1624 "--name", "testing 123",
1625 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1626 capture_stdout, sys.stderr, api_client=stubs.api)
1627 self.assertEqual(exited, 0)
1629 stubs.api.pipeline_instances().create.refute_called()
1630 stubs.api.jobs().create.refute_called()
1632 expect_component = copy.deepcopy(stubs.expect_job_spec)
1633 self._adjust_script_params(expect_component)
1636 "testing 123": expect_component,
1638 "name": "testing 123",
1639 "owner_uuid": project_uuid,
1641 stubs.api.pipeline_templates().create.refute_called()
1642 stubs.api.pipeline_templates().update.assert_called_with(
1643 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1645 self.assertEqual(capture_stdout.getvalue(),
1646 self.existing_template_uuid + '\n')
1649 class TestCreateWorkflow(unittest.TestCase):
1650 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1651 expect_workflow = StripYAMLComments(
1652 open("tests/wf/expect_packed.cwl").read())
1655 def test_create(self, stubs):
1656 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1658 capture_stdout = cStringIO.StringIO()
1660 exited = arvados_cwl.main(
1661 ["--create-workflow", "--debug",
1663 "--project-uuid", project_uuid,
1664 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1665 capture_stdout, sys.stderr, api_client=stubs.api)
1666 self.assertEqual(exited, 0)
1668 stubs.api.pipeline_templates().create.refute_called()
1669 stubs.api.container_requests().create.refute_called()
1673 "owner_uuid": project_uuid,
1674 "name": "submit_wf.cwl",
1676 "definition": self.expect_workflow,
1679 stubs.api.workflows().create.assert_called_with(
1680 body=JsonDiffMatcher(body))
1682 self.assertEqual(capture_stdout.getvalue(),
1683 stubs.expect_workflow_uuid + '\n')
1687 def test_create_name(self, stubs):
1688 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1690 capture_stdout = cStringIO.StringIO()
1692 exited = arvados_cwl.main(
1693 ["--create-workflow", "--debug",
1695 "--project-uuid", project_uuid,
1696 "--name", "testing 123",
1697 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1698 capture_stdout, sys.stderr, api_client=stubs.api)
1699 self.assertEqual(exited, 0)
1701 stubs.api.pipeline_templates().create.refute_called()
1702 stubs.api.container_requests().create.refute_called()
1706 "owner_uuid": project_uuid,
1707 "name": "testing 123",
1709 "definition": self.expect_workflow,
1712 stubs.api.workflows().create.assert_called_with(
1713 body=JsonDiffMatcher(body))
1715 self.assertEqual(capture_stdout.getvalue(),
1716 stubs.expect_workflow_uuid + '\n')
1719 def test_incompatible_api(self, stubs):
1720 capture_stderr = cStringIO.StringIO()
1721 logging.getLogger('arvados.cwl-runner').addHandler(
1722 logging.StreamHandler(capture_stderr))
1724 exited = arvados_cwl.main(
1725 ["--update-workflow", self.existing_workflow_uuid,
1728 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1729 sys.stderr, sys.stderr, api_client=stubs.api)
1730 self.assertEqual(exited, 1)
1731 self.assertRegexpMatches(
1732 capture_stderr.getvalue(),
1733 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1736 def test_update(self, stubs):
1737 capture_stdout = cStringIO.StringIO()
1739 exited = arvados_cwl.main(
1740 ["--update-workflow", self.existing_workflow_uuid,
1742 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1743 capture_stdout, sys.stderr, api_client=stubs.api)
1744 self.assertEqual(exited, 0)
1748 "name": "submit_wf.cwl",
1750 "definition": self.expect_workflow,
1753 stubs.api.workflows().update.assert_called_with(
1754 uuid=self.existing_workflow_uuid,
1755 body=JsonDiffMatcher(body))
1756 self.assertEqual(capture_stdout.getvalue(),
1757 self.existing_workflow_uuid + '\n')
1761 def test_update_name(self, stubs):
1762 capture_stdout = cStringIO.StringIO()
1764 exited = arvados_cwl.main(
1765 ["--update-workflow", self.existing_workflow_uuid,
1766 "--debug", "--name", "testing 123",
1767 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1768 capture_stdout, sys.stderr, api_client=stubs.api)
1769 self.assertEqual(exited, 0)
1773 "name": "testing 123",
1775 "definition": self.expect_workflow,
1778 stubs.api.workflows().update.assert_called_with(
1779 uuid=self.existing_workflow_uuid,
1780 body=JsonDiffMatcher(body))
1781 self.assertEqual(capture_stdout.getvalue(),
1782 self.existing_workflow_uuid + '\n')
1786 def test_create_collection_per_tool(self, stubs):
1787 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1789 capture_stdout = cStringIO.StringIO()
1791 exited = arvados_cwl.main(
1792 ["--create-workflow", "--debug",
1794 "--project-uuid", project_uuid,
1795 "tests/collection_per_tool/collection_per_tool.cwl"],
1796 capture_stdout, sys.stderr, api_client=stubs.api)
1797 self.assertEqual(exited, 0)
1799 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1800 expect_workflow = StripYAMLComments(open(toolfile).read())
1804 "owner_uuid": project_uuid,
1805 "name": "collection_per_tool.cwl",
1807 "definition": expect_workflow,
1810 stubs.api.workflows().create.assert_called_with(
1811 body=JsonDiffMatcher(body))
1813 self.assertEqual(capture_stdout.getvalue(),
1814 stubs.expect_workflow_uuid + '\n')
1816 class TestTemplateInputs(unittest.TestCase):
1819 "inputs_test.cwl": {
1820 'runtime_constraints': {
1821 'docker_image': '999999999999999999999999999999d3+99',
1822 'min_ram_mb_per_node': 1024
1824 'script_parameters': {
1826 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main',
1827 'optionalFloatInput': None,
1830 'dataclass': 'File',
1832 'title': "It's a file; we expect to find some characters in it.",
1833 'description': 'If there were anything further to say, it would be said here,\nor here.'
1837 'dataclass': 'number',
1839 'title': 'Floats like a duck',
1843 'optionalFloatInput': {
1844 'type': ['null', 'float'],
1845 'dataclass': 'number',
1850 'dataclass': 'boolean',
1852 'title': 'True or false?',
1855 'repository': 'arvados',
1856 'script_version': 'master',
1857 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1858 'script': 'cwl-runner',
1861 "name": "inputs_test.cwl",
1865 def test_inputs_empty(self, stubs):
1866 exited = arvados_cwl.main(
1867 ["--create-template",
1868 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1869 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1870 self.assertEqual(exited, 0)
1872 stubs.api.pipeline_templates().create.assert_called_with(
1873 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1876 def test_inputs(self, stubs):
1877 exited = arvados_cwl.main(
1878 ["--create-template",
1879 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1880 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1881 self.assertEqual(exited, 0)
1883 expect_template = copy.deepcopy(self.expect_template)
1884 params = expect_template[
1885 "components"]["inputs_test.cwl"]["script_parameters"]
1886 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1887 params["cwl:tool"] = 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main'
1888 params["floatInput"]["value"] = 1.234
1889 params["boolInput"]["value"] = True
1891 stubs.api.pipeline_templates().create.assert_called_with(
1892 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)