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', '--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*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', '--debug', '--on-error=continue',
563 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
564 expect_container["use_existing"] = False
566 stubs.api.container_requests().create.assert_called_with(
567 body=JsonDiffMatcher(expect_container))
568 self.assertEqual(capture_stdout.getvalue(),
569 stubs.expect_container_request_uuid + '\n')
573 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
574 capture_stdout = cStringIO.StringIO()
576 exited = arvados_cwl.main(
577 ["--submit", "--no-wait", "--api=containers", "--debug",
578 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
579 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
580 self.assertEqual(exited, 0)
582 expect_container = copy.deepcopy(stubs.expect_container_spec)
583 expect_container["command"] = [
584 'arvados-cwl-runner', '--local', '--api=containers',
585 '--no-log-timestamps', '--disable-validate',
586 '--eval-timeout=20', '--thread-count=4',
587 '--disable-reuse', '--debug', '--on-error=continue',
588 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
589 expect_container["use_existing"] = False
590 expect_container["name"] = "submit_wf_no_reuse.cwl"
591 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
593 "class": "http://arvados.org/cwl#ReuseRequirement",
594 "enableReuse": False,
597 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
598 "arv": "http://arvados.org/cwl#",
599 "cwltool": "http://commonwl.org/cwltool#"
602 stubs.api.container_requests().create.assert_called_with(
603 body=JsonDiffMatcher(expect_container))
604 self.assertEqual(capture_stdout.getvalue(),
605 stubs.expect_container_request_uuid + '\n')
609 def test_submit_container_on_error(self, stubs):
610 capture_stdout = cStringIO.StringIO()
612 exited = arvados_cwl.main(
613 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
614 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
615 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
616 self.assertEqual(exited, 0)
618 logging.exception("")
620 expect_container = copy.deepcopy(stubs.expect_container_spec)
621 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
622 '--no-log-timestamps', '--disable-validate',
623 '--eval-timeout=20', '--thread-count=4',
624 '--enable-reuse', '--debug', '--on-error=stop',
625 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
627 stubs.api.container_requests().create.assert_called_with(
628 body=JsonDiffMatcher(expect_container))
629 self.assertEqual(capture_stdout.getvalue(),
630 stubs.expect_container_request_uuid + '\n')
633 def test_submit_container_output_name(self, stubs):
634 output_name = "test_output_name"
636 capture_stdout = cStringIO.StringIO()
638 exited = arvados_cwl.main(
639 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
640 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
641 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
642 self.assertEqual(exited, 0)
644 logging.exception("")
646 expect_container = copy.deepcopy(stubs.expect_container_spec)
647 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
648 '--no-log-timestamps', '--disable-validate',
649 '--eval-timeout=20', '--thread-count=4',
651 "--output-name="+output_name, '--debug', '--on-error=continue',
652 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
653 expect_container["output_name"] = output_name
655 stubs.api.container_requests().create.assert_called_with(
656 body=JsonDiffMatcher(expect_container))
657 self.assertEqual(capture_stdout.getvalue(),
658 stubs.expect_container_request_uuid + '\n')
661 def test_submit_storage_classes(self, stubs):
662 capture_stdout = cStringIO.StringIO()
664 exited = arvados_cwl.main(
665 ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo",
666 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
667 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
668 self.assertEqual(exited, 0)
670 logging.exception("")
672 expect_container = copy.deepcopy(stubs.expect_container_spec)
673 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
674 '--no-log-timestamps', '--disable-validate',
675 '--eval-timeout=20', '--thread-count=4',
676 '--enable-reuse', "--debug",
677 "--storage-classes=foo", '--on-error=continue',
678 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
680 stubs.api.container_requests().create.assert_called_with(
681 body=JsonDiffMatcher(expect_container))
682 self.assertEqual(capture_stdout.getvalue(),
683 stubs.expect_container_request_uuid + '\n')
685 @mock.patch("arvados_cwl.task_queue.TaskQueue")
686 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
687 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
689 def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
690 def set_final_output(job_order, output_callback, runtimeContext):
691 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
693 job.side_effect = set_final_output
696 exited = arvados_cwl.main(
697 ["--debug", "--local", "--storage-classes=foo",
698 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
699 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
700 self.assertEqual(exited, 0)
702 logging.exception("")
704 make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
706 @mock.patch("arvados_cwl.task_queue.TaskQueue")
707 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
708 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
710 def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
711 def set_final_output(job_order, output_callback, runtimeContext):
712 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
714 job.side_effect = set_final_output
717 exited = arvados_cwl.main(
718 ["--debug", "--local",
719 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
720 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
721 self.assertEqual(exited, 0)
723 logging.exception("")
725 make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
728 def test_submit_container_output_ttl(self, stubs):
729 capture_stdout = cStringIO.StringIO()
731 exited = arvados_cwl.main(
732 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
733 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
734 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
735 self.assertEqual(exited, 0)
737 logging.exception("")
739 expect_container = copy.deepcopy(stubs.expect_container_spec)
740 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
741 '--no-log-timestamps', '--disable-validate',
742 '--eval-timeout=20', '--thread-count=4',
743 '--enable-reuse', '--debug', '--on-error=continue',
744 "--intermediate-output-ttl=3600",
745 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
747 stubs.api.container_requests().create.assert_called_with(
748 body=JsonDiffMatcher(expect_container))
749 self.assertEqual(capture_stdout.getvalue(),
750 stubs.expect_container_request_uuid + '\n')
753 def test_submit_container_trash_intermediate(self, stubs):
754 capture_stdout = cStringIO.StringIO()
756 exited = arvados_cwl.main(
757 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
758 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
759 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
760 self.assertEqual(exited, 0)
762 logging.exception("")
764 expect_container = copy.deepcopy(stubs.expect_container_spec)
765 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
766 '--no-log-timestamps', '--disable-validate',
767 '--eval-timeout=20', '--thread-count=4',
768 '--enable-reuse', '--debug', '--on-error=continue',
769 "--trash-intermediate",
770 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
772 stubs.api.container_requests().create.assert_called_with(
773 body=JsonDiffMatcher(expect_container))
774 self.assertEqual(capture_stdout.getvalue(),
775 stubs.expect_container_request_uuid + '\n')
778 def test_submit_container_output_tags(self, stubs):
779 output_tags = "tag0,tag1,tag2"
781 capture_stdout = cStringIO.StringIO()
783 exited = arvados_cwl.main(
784 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
785 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
786 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
787 self.assertEqual(exited, 0)
789 logging.exception("")
791 expect_container = copy.deepcopy(stubs.expect_container_spec)
792 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
793 '--no-log-timestamps', '--disable-validate',
794 '--eval-timeout=20', '--thread-count=4',
796 "--output-tags="+output_tags, '--debug', '--on-error=continue',
797 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
799 stubs.api.container_requests().create.assert_called_with(
800 body=JsonDiffMatcher(expect_container))
801 self.assertEqual(capture_stdout.getvalue(),
802 stubs.expect_container_request_uuid + '\n')
805 def test_submit_container_runner_ram(self, stubs):
806 capture_stdout = cStringIO.StringIO()
808 exited = arvados_cwl.main(
809 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
810 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
811 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
812 self.assertEqual(exited, 0)
814 logging.exception("")
816 expect_container = copy.deepcopy(stubs.expect_container_spec)
817 expect_container["runtime_constraints"]["ram"] = 2048*1024*1024
819 stubs.api.container_requests().create.assert_called_with(
820 body=JsonDiffMatcher(expect_container))
821 self.assertEqual(capture_stdout.getvalue(),
822 stubs.expect_container_request_uuid + '\n')
824 @mock.patch("arvados.collection.CollectionReader")
825 @mock.patch("time.sleep")
827 def test_submit_file_keepref(self, stubs, tm, collectionReader):
828 capture_stdout = cStringIO.StringIO()
829 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt")
830 exited = arvados_cwl.main(
831 ["--submit", "--no-wait", "--api=containers", "--debug",
832 "tests/wf/submit_keepref_wf.cwl"],
833 capture_stdout, sys.stderr, api_client=stubs.api)
834 self.assertEqual(exited, 0)
837 @mock.patch("arvados.collection.CollectionReader")
838 @mock.patch("time.sleep")
840 def test_submit_keepref(self, stubs, tm, reader):
841 capture_stdout = cStringIO.StringIO()
843 with open("tests/wf/expect_arvworkflow.cwl") as f:
844 reader().open().__enter__().read.return_value = f.read()
846 exited = arvados_cwl.main(
847 ["--submit", "--no-wait", "--api=containers", "--debug",
848 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
849 capture_stdout, sys.stderr, api_client=stubs.api)
850 self.assertEqual(exited, 0)
860 'path': '/var/spool/cwl/cwl.output.json',
863 '/var/lib/cwl/workflow': {
864 'portable_data_hash': '99999999999999999999999999999994+99',
867 '/var/lib/cwl/cwl.input.json': {
873 }, 'state': 'Committed',
874 'output_path': '/var/spool/cwl',
875 'name': 'expect_arvworkflow.cwl#main',
876 'container_image': '999999999999999999999999999999d3+99',
877 'command': ['arvados-cwl-runner', '--local', '--api=containers',
878 '--no-log-timestamps', '--disable-validate',
879 '--eval-timeout=20', '--thread-count=4',
880 '--enable-reuse', '--debug', '--on-error=continue',
881 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
882 'cwd': '/var/spool/cwl',
883 'runtime_constraints': {
888 'use_existing': True,
893 stubs.api.container_requests().create.assert_called_with(
894 body=JsonDiffMatcher(expect_container))
895 self.assertEqual(capture_stdout.getvalue(),
896 stubs.expect_container_request_uuid + '\n')
899 @mock.patch("arvados.collection.CollectionReader")
900 @mock.patch("time.sleep")
902 def test_submit_jobs_keepref(self, stubs, tm, reader):
903 capture_stdout = cStringIO.StringIO()
905 with open("tests/wf/expect_arvworkflow.cwl") as f:
906 reader().open().__enter__().read.return_value = f.read()
908 exited = arvados_cwl.main(
909 ["--submit", "--no-wait", "--api=jobs", "--debug",
910 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
911 capture_stdout, sys.stderr, api_client=stubs.api)
912 self.assertEqual(exited, 0)
914 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
915 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX"
916 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"]
917 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"]
918 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main"
919 expect_pipeline["name"] = "expect_arvworkflow.cwl#main"
920 stubs.api.pipeline_instances().create.assert_called_with(
921 body=JsonDiffMatcher(expect_pipeline))
923 @mock.patch("time.sleep")
925 def test_submit_arvworkflow(self, stubs, tm):
926 capture_stdout = cStringIO.StringIO()
928 with open("tests/wf/expect_arvworkflow.cwl") as f:
929 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
931 exited = arvados_cwl.main(
932 ["--submit", "--no-wait", "--api=containers", "--debug",
933 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
934 capture_stdout, sys.stderr, api_client=stubs.api)
935 self.assertEqual(exited, 0)
945 'path': '/var/spool/cwl/cwl.output.json',
948 '/var/lib/cwl/workflow.json': {
951 'cwlVersion': 'v1.0',
956 {'type': 'string', 'id': '#main/x'}
959 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
960 'run': '#submit_tool.cwl',
970 'inputBinding': {'position': 1},
972 'id': '#submit_tool.cwl/x'}
976 'dockerPull': 'debian:8',
977 'class': 'DockerRequirement',
978 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
981 'id': '#submit_tool.cwl',
983 'baseCommand': 'cat',
984 'class': 'CommandLineTool'
989 '/var/lib/cwl/cwl.input.json': {
995 }, 'state': 'Committed',
996 'output_path': '/var/spool/cwl',
997 'name': 'a test workflow',
998 'container_image': "999999999999999999999999999999d3+99",
999 'command': ['arvados-cwl-runner', '--local', '--api=containers',
1000 '--no-log-timestamps', '--disable-validate',
1001 '--eval-timeout=20', '--thread-count=4',
1002 '--enable-reuse', '--debug', '--on-error=continue',
1003 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
1004 'cwd': '/var/spool/cwl',
1005 'runtime_constraints': {
1010 'use_existing': True,
1012 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
1017 stubs.api.container_requests().create.assert_called_with(
1018 body=JsonDiffMatcher(expect_container))
1019 self.assertEqual(capture_stdout.getvalue(),
1020 stubs.expect_container_request_uuid + '\n')
1024 def test_submit_container_name(self, stubs):
1025 capture_stdout = cStringIO.StringIO()
1027 exited = arvados_cwl.main(
1028 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
1029 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1030 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1031 self.assertEqual(exited, 0)
1033 logging.exception("")
1035 expect_container = copy.deepcopy(stubs.expect_container_spec)
1036 expect_container["name"] = "hello container 123"
1038 stubs.api.container_requests().create.assert_called_with(
1039 body=JsonDiffMatcher(expect_container))
1040 self.assertEqual(capture_stdout.getvalue(),
1041 stubs.expect_container_request_uuid + '\n')
1045 def test_submit_container_project(self, stubs):
1046 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1047 capture_stdout = cStringIO.StringIO()
1049 exited = arvados_cwl.main(
1050 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
1051 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1052 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1053 self.assertEqual(exited, 0)
1055 logging.exception("")
1057 expect_container = copy.deepcopy(stubs.expect_container_spec)
1058 expect_container["owner_uuid"] = project_uuid
1059 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1060 '--no-log-timestamps', '--disable-validate',
1061 "--eval-timeout=20", "--thread-count=4",
1062 '--enable-reuse', '--debug', '--on-error=continue',
1063 '--project-uuid='+project_uuid,
1064 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1066 stubs.api.container_requests().create.assert_called_with(
1067 body=JsonDiffMatcher(expect_container))
1068 self.assertEqual(capture_stdout.getvalue(),
1069 stubs.expect_container_request_uuid + '\n')
1072 def test_submit_container_eval_timeout(self, stubs):
1073 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1074 capture_stdout = cStringIO.StringIO()
1076 exited = arvados_cwl.main(
1077 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
1078 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1079 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1080 self.assertEqual(exited, 0)
1082 logging.exception("")
1084 expect_container = copy.deepcopy(stubs.expect_container_spec)
1085 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1086 '--no-log-timestamps', '--disable-validate',
1087 '--eval-timeout=60.0', '--thread-count=4',
1088 '--enable-reuse', '--debug', '--on-error=continue',
1089 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1091 stubs.api.container_requests().create.assert_called_with(
1092 body=JsonDiffMatcher(expect_container))
1093 self.assertEqual(capture_stdout.getvalue(),
1094 stubs.expect_container_request_uuid + '\n')
1098 def test_submit_container_thread_count(self, stubs):
1099 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1100 capture_stdout = cStringIO.StringIO()
1102 exited = arvados_cwl.main(
1103 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
1104 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1105 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1106 self.assertEqual(exited, 0)
1108 logging.exception("")
1110 expect_container = copy.deepcopy(stubs.expect_container_spec)
1111 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1112 '--no-log-timestamps', '--disable-validate',
1113 '--eval-timeout=20', '--thread-count=20',
1114 '--enable-reuse', '--debug', '--on-error=continue',
1115 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1117 stubs.api.container_requests().create.assert_called_with(
1118 body=JsonDiffMatcher(expect_container))
1119 self.assertEqual(capture_stdout.getvalue(),
1120 stubs.expect_container_request_uuid + '\n')
1124 def test_submit_job_runner_image(self, stubs):
1125 capture_stdout = cStringIO.StringIO()
1127 exited = arvados_cwl.main(
1128 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
1129 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1130 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1131 self.assertEqual(exited, 0)
1133 logging.exception("")
1135 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99"
1137 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
1138 stubs.api.pipeline_instances().create.assert_called_with(
1139 body=JsonDiffMatcher(expect_pipeline))
1140 self.assertEqual(capture_stdout.getvalue(),
1141 stubs.expect_pipeline_uuid + '\n')
1144 def test_submit_container_runner_image(self, stubs):
1145 capture_stdout = cStringIO.StringIO()
1147 exited = arvados_cwl.main(
1148 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
1149 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1150 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1151 self.assertEqual(exited, 0)
1153 logging.exception("")
1155 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
1157 expect_container = copy.deepcopy(stubs.expect_container_spec)
1158 stubs.api.container_requests().create.assert_called_with(
1159 body=JsonDiffMatcher(expect_container))
1160 self.assertEqual(capture_stdout.getvalue(),
1161 stubs.expect_container_request_uuid + '\n')
1164 def test_submit_priority(self, stubs):
1165 capture_stdout = cStringIO.StringIO()
1167 exited = arvados_cwl.main(
1168 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
1169 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1170 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1171 self.assertEqual(exited, 0)
1173 logging.exception("")
1175 stubs.expect_container_spec["priority"] = 669
1177 expect_container = copy.deepcopy(stubs.expect_container_spec)
1178 stubs.api.container_requests().create.assert_called_with(
1179 body=JsonDiffMatcher(expect_container))
1180 self.assertEqual(capture_stdout.getvalue(),
1181 stubs.expect_container_request_uuid + '\n')
1185 def test_submit_wf_runner_resources(self, stubs):
1186 capture_stdout = cStringIO.StringIO()
1188 exited = arvados_cwl.main(
1189 ["--submit", "--no-wait", "--api=containers", "--debug",
1190 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
1191 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1192 self.assertEqual(exited, 0)
1194 logging.exception("")
1196 expect_container = copy.deepcopy(stubs.expect_container_spec)
1197 expect_container["runtime_constraints"] = {
1202 expect_container["name"] = "submit_wf_runner_resources.cwl"
1203 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
1205 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
1210 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
1211 "arv": "http://arvados.org/cwl#",
1214 stubs.api.container_requests().create.assert_called_with(
1215 body=JsonDiffMatcher(expect_container))
1216 self.assertEqual(capture_stdout.getvalue(),
1217 stubs.expect_container_request_uuid + '\n')
1220 arvados_cwl.arvdocker.arv_docker_clear_cache()
1222 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1223 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1224 @mock.patch("arvados.api")
1225 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1226 arvados_cwl.arvdocker.arv_docker_clear_cache()
1228 arvrunner = mock.MagicMock()
1229 arvrunner.project_uuid = ""
1230 api.return_value = mock.MagicMock()
1231 arvrunner.api = api.return_value
1232 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1233 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1234 "link_class": "docker_image_repo+tag",
1235 "name": "arvados/jobs:"+arvados_cwl.__version__,
1237 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1238 {"items": [{"created_at": "",
1240 "link_class": "docker_image_hash",
1243 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1245 find_one_image_hash.return_value = "123456"
1247 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1249 "manifest_text": "",
1251 }], "items_available": 1, "offset": 0},)
1252 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1253 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1254 "portable_data_hash": "9999999999999999999999999999999b+99"}
1255 self.assertEqual("9999999999999999999999999999999b+99",
1256 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1260 def test_submit_secrets(self, stubs):
1261 capture_stdout = cStringIO.StringIO()
1263 exited = arvados_cwl.main(
1264 ["--submit", "--no-wait", "--api=containers", "--debug",
1265 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1266 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1267 self.assertEqual(exited, 0)
1269 logging.exception("")
1272 expect_container = {
1274 "arvados-cwl-runner",
1277 "--no-log-timestamps",
1278 "--disable-validate",
1279 "--eval-timeout=20",
1283 "--on-error=continue",
1284 "/var/lib/cwl/workflow.json#main",
1285 "/var/lib/cwl/cwl.input.json"
1287 "container_image": "999999999999999999999999999999d3+99",
1288 "cwd": "/var/spool/cwl",
1290 "/var/lib/cwl/cwl.input.json": {
1293 "$include": "/secrets/s0"
1298 "/var/lib/cwl/workflow.json": {
1303 "cwltool": "http://commonwl.org/cwltool#"
1309 "class": "CommandLineTool",
1312 "class": "http://commonwl.org/cwltool#Secrets",
1314 "#secret_job.cwl/pw"
1318 "id": "#secret_job.cwl",
1321 "id": "#secret_job.cwl/pw",
1327 "id": "#secret_job.cwl/out",
1331 "stdout": "hashed_example.txt",
1334 "class": "InitialWorkDirRequirement",
1337 "entry": "username: user\npassword: $(inputs.pw)\n",
1338 "entryname": "example.conf"
1345 "class": "Workflow",
1348 "class": "DockerRequirement",
1349 "dockerPull": "debian:8",
1350 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1353 "class": "http://commonwl.org/cwltool#Secrets",
1369 "outputSource": "#main/step1/out",
1375 "id": "#main/step1",
1378 "id": "#main/step1/pw",
1379 "source": "#main/pw"
1385 "run": "#secret_job.cwl"
1390 "cwlVersion": "v1.0"
1395 "kind": "collection",
1400 "path": "/var/spool/cwl/cwl.output.json"
1403 "name": "secret_wf.cwl",
1404 "output_path": "/var/spool/cwl",
1407 "runtime_constraints": {
1418 "state": "Committed",
1419 "use_existing": True
1422 stubs.api.container_requests().create.assert_called_with(
1423 body=JsonDiffMatcher(expect_container))
1424 self.assertEqual(capture_stdout.getvalue(),
1425 stubs.expect_container_request_uuid + '\n')
1428 def test_submit_request_uuid(self, stubs):
1429 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1431 stubs.api.container_requests().update().execute.return_value = {
1432 "uuid": stubs.expect_container_request_uuid,
1433 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1437 capture_stdout = cStringIO.StringIO()
1439 exited = arvados_cwl.main(
1440 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1441 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1442 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1443 self.assertEqual(exited, 0)
1445 logging.exception("")
1447 stubs.api.container_requests().update.assert_called_with(
1448 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz")
1449 self.assertEqual(capture_stdout.getvalue(),
1450 stubs.expect_container_request_uuid + '\n')
1453 def test_submit_container_cluster_id(self, stubs):
1454 capture_stdout = cStringIO.StringIO()
1456 exited = arvados_cwl.main(
1457 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1458 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1459 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1460 self.assertEqual(exited, 0)
1462 logging.exception("")
1464 expect_container = copy.deepcopy(stubs.expect_container_spec)
1466 stubs.api.container_requests().create.assert_called_with(
1467 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1468 self.assertEqual(capture_stdout.getvalue(),
1469 stubs.expect_container_request_uuid + '\n')
1472 class TestCreateTemplate(unittest.TestCase):
1473 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1475 def _adjust_script_params(self, expect_component):
1476 expect_component['script_parameters']['x'] = {
1477 'dataclass': 'File',
1480 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1482 expect_component['script_parameters']['y'] = {
1483 'dataclass': 'Collection',
1485 'type': 'Directory',
1486 'value': '99999999999999999999999999999998+99',
1488 expect_component['script_parameters']['z'] = {
1489 'dataclass': 'Collection',
1491 'type': 'Directory',
1495 def test_create(self, stubs):
1496 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1498 capture_stdout = cStringIO.StringIO()
1500 exited = arvados_cwl.main(
1501 ["--create-workflow", "--debug",
1503 "--project-uuid", project_uuid,
1504 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1505 capture_stdout, sys.stderr, api_client=stubs.api)
1506 self.assertEqual(exited, 0)
1508 stubs.api.pipeline_instances().create.refute_called()
1509 stubs.api.jobs().create.refute_called()
1511 expect_component = copy.deepcopy(stubs.expect_job_spec)
1512 self._adjust_script_params(expect_component)
1515 "submit_wf.cwl": expect_component,
1517 "name": "submit_wf.cwl",
1518 "owner_uuid": project_uuid,
1520 stubs.api.pipeline_templates().create.assert_called_with(
1521 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1523 self.assertEqual(capture_stdout.getvalue(),
1524 stubs.expect_pipeline_template_uuid + '\n')
1528 def test_create_name(self, stubs):
1529 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1531 capture_stdout = cStringIO.StringIO()
1533 exited = arvados_cwl.main(
1534 ["--create-workflow", "--debug",
1535 "--project-uuid", project_uuid,
1537 "--name", "testing 123",
1538 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1539 capture_stdout, sys.stderr, api_client=stubs.api)
1540 self.assertEqual(exited, 0)
1542 stubs.api.pipeline_instances().create.refute_called()
1543 stubs.api.jobs().create.refute_called()
1545 expect_component = copy.deepcopy(stubs.expect_job_spec)
1546 self._adjust_script_params(expect_component)
1549 "testing 123": expect_component,
1551 "name": "testing 123",
1552 "owner_uuid": project_uuid,
1554 stubs.api.pipeline_templates().create.assert_called_with(
1555 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1557 self.assertEqual(capture_stdout.getvalue(),
1558 stubs.expect_pipeline_template_uuid + '\n')
1562 def test_update_name(self, stubs):
1563 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1565 capture_stdout = cStringIO.StringIO()
1567 exited = arvados_cwl.main(
1568 ["--update-workflow", self.existing_template_uuid,
1570 "--project-uuid", project_uuid,
1572 "--name", "testing 123",
1573 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1574 capture_stdout, sys.stderr, api_client=stubs.api)
1575 self.assertEqual(exited, 0)
1577 stubs.api.pipeline_instances().create.refute_called()
1578 stubs.api.jobs().create.refute_called()
1580 expect_component = copy.deepcopy(stubs.expect_job_spec)
1581 self._adjust_script_params(expect_component)
1584 "testing 123": expect_component,
1586 "name": "testing 123",
1587 "owner_uuid": project_uuid,
1589 stubs.api.pipeline_templates().create.refute_called()
1590 stubs.api.pipeline_templates().update.assert_called_with(
1591 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1593 self.assertEqual(capture_stdout.getvalue(),
1594 self.existing_template_uuid + '\n')
1597 class TestCreateWorkflow(unittest.TestCase):
1598 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1599 expect_workflow = StripYAMLComments(
1600 open("tests/wf/expect_packed.cwl").read())
1603 def test_create(self, stubs):
1604 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1606 capture_stdout = cStringIO.StringIO()
1608 exited = arvados_cwl.main(
1609 ["--create-workflow", "--debug",
1611 "--project-uuid", project_uuid,
1612 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1613 capture_stdout, sys.stderr, api_client=stubs.api)
1614 self.assertEqual(exited, 0)
1616 stubs.api.pipeline_templates().create.refute_called()
1617 stubs.api.container_requests().create.refute_called()
1621 "owner_uuid": project_uuid,
1622 "name": "submit_wf.cwl",
1624 "definition": self.expect_workflow,
1627 stubs.api.workflows().create.assert_called_with(
1628 body=JsonDiffMatcher(body))
1630 self.assertEqual(capture_stdout.getvalue(),
1631 stubs.expect_workflow_uuid + '\n')
1635 def test_create_name(self, stubs):
1636 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1638 capture_stdout = cStringIO.StringIO()
1640 exited = arvados_cwl.main(
1641 ["--create-workflow", "--debug",
1643 "--project-uuid", project_uuid,
1644 "--name", "testing 123",
1645 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1646 capture_stdout, sys.stderr, api_client=stubs.api)
1647 self.assertEqual(exited, 0)
1649 stubs.api.pipeline_templates().create.refute_called()
1650 stubs.api.container_requests().create.refute_called()
1654 "owner_uuid": project_uuid,
1655 "name": "testing 123",
1657 "definition": self.expect_workflow,
1660 stubs.api.workflows().create.assert_called_with(
1661 body=JsonDiffMatcher(body))
1663 self.assertEqual(capture_stdout.getvalue(),
1664 stubs.expect_workflow_uuid + '\n')
1667 def test_incompatible_api(self, stubs):
1668 capture_stderr = cStringIO.StringIO()
1669 logging.getLogger('arvados.cwl-runner').addHandler(
1670 logging.StreamHandler(capture_stderr))
1672 exited = arvados_cwl.main(
1673 ["--update-workflow", self.existing_workflow_uuid,
1676 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1677 sys.stderr, sys.stderr, api_client=stubs.api)
1678 self.assertEqual(exited, 1)
1679 self.assertRegexpMatches(
1680 capture_stderr.getvalue(),
1681 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1684 def test_update(self, stubs):
1685 capture_stdout = cStringIO.StringIO()
1687 exited = arvados_cwl.main(
1688 ["--update-workflow", self.existing_workflow_uuid,
1690 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1691 capture_stdout, sys.stderr, api_client=stubs.api)
1692 self.assertEqual(exited, 0)
1696 "name": "submit_wf.cwl",
1698 "definition": self.expect_workflow,
1701 stubs.api.workflows().update.assert_called_with(
1702 uuid=self.existing_workflow_uuid,
1703 body=JsonDiffMatcher(body))
1704 self.assertEqual(capture_stdout.getvalue(),
1705 self.existing_workflow_uuid + '\n')
1709 def test_update_name(self, stubs):
1710 capture_stdout = cStringIO.StringIO()
1712 exited = arvados_cwl.main(
1713 ["--update-workflow", self.existing_workflow_uuid,
1714 "--debug", "--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)
1721 "name": "testing 123",
1723 "definition": self.expect_workflow,
1726 stubs.api.workflows().update.assert_called_with(
1727 uuid=self.existing_workflow_uuid,
1728 body=JsonDiffMatcher(body))
1729 self.assertEqual(capture_stdout.getvalue(),
1730 self.existing_workflow_uuid + '\n')
1734 def test_create_collection_per_tool(self, stubs):
1735 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1737 capture_stdout = cStringIO.StringIO()
1739 exited = arvados_cwl.main(
1740 ["--create-workflow", "--debug",
1742 "--project-uuid", project_uuid,
1743 "tests/collection_per_tool/collection_per_tool.cwl"],
1744 capture_stdout, sys.stderr, api_client=stubs.api)
1745 self.assertEqual(exited, 0)
1747 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1748 expect_workflow = StripYAMLComments(open(toolfile).read())
1752 "owner_uuid": project_uuid,
1753 "name": "collection_per_tool.cwl",
1755 "definition": expect_workflow,
1758 stubs.api.workflows().create.assert_called_with(
1759 body=JsonDiffMatcher(body))
1761 self.assertEqual(capture_stdout.getvalue(),
1762 stubs.expect_workflow_uuid + '\n')
1764 class TestTemplateInputs(unittest.TestCase):
1767 "inputs_test.cwl": {
1768 'runtime_constraints': {
1769 'docker_image': '999999999999999999999999999999d3+99',
1770 'min_ram_mb_per_node': 1024
1772 'script_parameters': {
1774 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main',
1775 'optionalFloatInput': None,
1778 'dataclass': 'File',
1780 'title': "It's a file; we expect to find some characters in it.",
1781 'description': 'If there were anything further to say, it would be said here,\nor here.'
1785 'dataclass': 'number',
1787 'title': 'Floats like a duck',
1791 'optionalFloatInput': {
1792 'type': ['null', 'float'],
1793 'dataclass': 'number',
1798 'dataclass': 'boolean',
1800 'title': 'True or false?',
1803 'repository': 'arvados',
1804 'script_version': 'master',
1805 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1806 'script': 'cwl-runner',
1809 "name": "inputs_test.cwl",
1813 def test_inputs_empty(self, stubs):
1814 exited = arvados_cwl.main(
1815 ["--create-template",
1816 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1817 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1818 self.assertEqual(exited, 0)
1820 stubs.api.pipeline_templates().create.assert_called_with(
1821 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1824 def test_inputs(self, stubs):
1825 exited = arvados_cwl.main(
1826 ["--create-template",
1827 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1828 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1829 self.assertEqual(exited, 0)
1831 expect_template = copy.deepcopy(self.expect_template)
1832 params = expect_template[
1833 "components"]["inputs_test.cwl"]["script_parameters"]
1834 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1835 params["cwl:tool"] = 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main'
1836 params["floatInput"]["value"] = 1.234
1837 params["boolInput"]["value"] = True
1839 stubs.api.pipeline_templates().create.assert_called_with(
1840 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)