1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
16 import arvados.collection
18 import arvados_cwl.runner
21 from .matcher import JsonDiffMatcher, StripYAMLComments
22 from .mock_discovery import get_rootDesc
24 import ruamel.yaml as yaml
29 @functools.wraps(func)
30 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
31 @mock.patch("arvados.collection.KeepClient")
32 @mock.patch("arvados.keep.KeepClient")
33 @mock.patch("arvados.events.subscribe")
34 def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs):
39 stubs.keepdocker = keepdocker
41 def putstub(p, **kwargs):
42 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
43 keep_client1().put.side_effect = putstub
44 keep_client1.put.side_effect = putstub
45 keep_client2().put.side_effect = putstub
46 keep_client2.put.side_effect = putstub
48 stubs.keep_client = keep_client2
49 stubs.keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
50 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
52 stubs.api = mock.MagicMock()
53 stubs.api._rootDesc = get_rootDesc()
55 stubs.api.users().current().execute.return_value = {
56 "uuid": stubs.fake_user_uuid,
58 stubs.api.collections().list().execute.return_value = {"items": []}
60 class CollectionExecute(object):
61 def __init__(self, exe):
63 def execute(self, num_retries=None):
66 def collection_createstub(created_collections, body, ensure_unique_name=None):
67 mt = body["manifest_text"]
68 uuid = "zzzzz-4zz18-zzzzzzzzzzzzzz%d" % len(created_collections)
69 pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt))
70 created_collections[uuid] = {
72 "portable_data_hash": pdh,
75 return CollectionExecute(created_collections[uuid])
77 def collection_getstub(created_collections, uuid):
78 for v in created_collections.itervalues():
79 if uuid in (v["uuid"], v["portable_data_hash"]):
80 return CollectionExecute(v)
82 created_collections = {
83 "99999999999999999999999999999998+99": {
85 "portable_data_hash": "99999999999999999999999999999998+99",
86 "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt"
88 "99999999999999999999999999999994+99": {
90 "portable_data_hash": "99999999999999999999999999999994+99",
91 "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl"
94 stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections)
95 stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections)
97 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
98 stubs.api.jobs().create().execute.return_value = {
99 "uuid": stubs.expect_job_uuid,
103 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
104 stubs.api.container_requests().create().execute.return_value = {
105 "uuid": stubs.expect_container_request_uuid,
106 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
110 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
111 stubs.api.pipeline_templates().create().execute.return_value = {
112 "uuid": stubs.expect_pipeline_template_uuid,
114 stubs.expect_job_spec = {
115 'runtime_constraints': {
116 'docker_image': 'arvados/jobs:'+arvados_cwl.__version__,
117 'min_ram_mb_per_node': 1024
119 'script_parameters': {
121 'basename': 'blorp.txt',
122 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
126 'basename': '99999999999999999999999999999998+99',
127 'location': 'keep:99999999999999999999999999999998+99',
131 'basename': 'anonymous',
133 "basename": "renamed.txt",
135 "location": "keep:99999999999999999999999999999998+99/file1.txt"
139 'cwl:tool': '3fffdeaa75e018172e1b583425f4ebff+60/workflow.cwl#main'
141 'repository': 'arvados',
142 'script_version': 'master',
143 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
144 'script': 'cwl-runner'
146 stubs.pipeline_component = stubs.expect_job_spec.copy()
147 stubs.expect_pipeline_instance = {
148 'name': 'submit_wf.cwl',
149 'state': 'RunningOnServer',
153 'runtime_constraints': {'docker_image': 'arvados/jobs:'+arvados_cwl.__version__, 'min_ram_mb_per_node': 1024},
154 'script_parameters': {
155 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}},
157 'basename': 'blorp.txt',
159 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
162 'z': {"value": {'basename': 'anonymous', 'class': 'Directory',
165 'basename': 'renamed.txt',
166 'class': 'File', 'location':
167 'keep:99999999999999999999999999999998+99/file1.txt'
170 'cwl:tool': '3fffdeaa75e018172e1b583425f4ebff+60/workflow.cwl#main',
171 'arv:enable_reuse': True,
172 'arv:on_error': 'continue'
174 'repository': 'arvados',
175 'script_version': 'master',
176 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
177 'script': 'cwl-runner',
178 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'}
182 stubs.pipeline_create = copy.deepcopy(stubs.expect_pipeline_instance)
183 stubs.expect_pipeline_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
184 stubs.pipeline_create["uuid"] = stubs.expect_pipeline_uuid
185 stubs.pipeline_with_job = copy.deepcopy(stubs.pipeline_create)
186 stubs.pipeline_with_job["components"]["cwl-runner"]["job"] = {
187 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
190 stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create
191 stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job
193 with open("tests/wf/submit_wf_packed.cwl") as f:
194 expect_packed_workflow = yaml.round_trip_load(f)
196 stubs.expect_container_spec = {
203 '/var/lib/cwl/workflow.json': {
204 'content': expect_packed_workflow,
208 'path': '/var/spool/cwl/cwl.output.json',
211 '/var/lib/cwl/cwl.input.json': {
215 'basename': '99999999999999999999999999999998+99',
216 'location': 'keep:99999999999999999999999999999998+99',
217 'class': 'Directory'},
219 'basename': u'blorp.txt',
221 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
224 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [
225 {'basename': 'renamed.txt',
227 'location': 'keep:99999999999999999999999999999998+99/file1.txt'
235 'state': 'Committed',
237 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
238 '--enable-reuse', '--on-error=continue', '--eval-timeout=20',
239 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
240 'name': 'submit_wf.cwl',
241 'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
242 'output_path': '/var/spool/cwl',
243 'cwd': '/var/spool/cwl',
244 'runtime_constraints': {
247 'ram': 1024*1024*1024
249 'use_existing': True,
254 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
255 stubs.api.workflows().create().execute.return_value = {
256 "uuid": stubs.expect_workflow_uuid,
258 def update_mock(**kwargs):
259 stubs.updated_uuid = kwargs.get('uuid')
261 stubs.api.workflows().update.side_effect = update_mock
262 stubs.api.workflows().update().execute.side_effect = lambda **kwargs: {
263 "uuid": stubs.updated_uuid,
266 return func(self, stubs, *args, **kwargs)
270 class TestSubmit(unittest.TestCase):
271 @mock.patch("arvados_cwl.runner.arv_docker_get_image")
272 @mock.patch("time.sleep")
274 def test_submit(self, stubs, tm, arvdock):
275 capture_stdout = cStringIO.StringIO()
276 exited = arvados_cwl.main(
277 ["--submit", "--no-wait", "--api=jobs", "--debug",
278 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
279 capture_stdout, sys.stderr, api_client=stubs.api)
280 self.assertEqual(exited, 0)
282 stubs.api.collections().create.assert_has_calls([
283 mock.call(body=JsonDiffMatcher({
285 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
286 'replication_desired': None,
287 'name': 'submit_tool.cwl dependencies',
288 }), ensure_unique_name=True),
289 mock.call(body=JsonDiffMatcher({
291 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
292 'replication_desired': None,
293 'name': 'submit_wf.cwl input',
294 }), ensure_unique_name=True),
295 mock.call(body=JsonDiffMatcher({
297 '. 61df2ed9ee3eb7dd9b799e5ca35305fa+1217 0:1217:workflow.cwl\n',
298 'replication_desired': None,
299 'name': 'submit_wf.cwl',
300 }), ensure_unique_name=True) ])
302 arvdock.assert_has_calls([
303 mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None),
304 mock.call(stubs.api, {'dockerPull': 'arvados/jobs:'+arvados_cwl.__version__}, True, None)
307 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
308 stubs.api.pipeline_instances().create.assert_called_with(
309 body=JsonDiffMatcher(expect_pipeline))
310 self.assertEqual(capture_stdout.getvalue(),
311 stubs.expect_pipeline_uuid + '\n')
314 @mock.patch("time.sleep")
316 def test_submit_no_reuse(self, stubs, tm):
317 capture_stdout = cStringIO.StringIO()
318 exited = arvados_cwl.main(
319 ["--submit", "--no-wait", "--api=jobs", "--debug", "--disable-reuse",
320 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
321 capture_stdout, sys.stderr, api_client=stubs.api)
322 self.assertEqual(exited, 0)
324 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
325 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False}
326 expect_pipeline["properties"] = {"run_options": {"enable_job_reuse": False}}
328 stubs.api.pipeline_instances().create.assert_called_with(
329 body=JsonDiffMatcher(expect_pipeline))
330 self.assertEqual(capture_stdout.getvalue(),
331 stubs.expect_pipeline_uuid + '\n')
333 @mock.patch("time.sleep")
335 def test_submit_on_error(self, stubs, tm):
336 capture_stdout = cStringIO.StringIO()
337 exited = arvados_cwl.main(
338 ["--submit", "--no-wait", "--api=jobs", "--debug", "--on-error=stop",
339 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
340 capture_stdout, sys.stderr, api_client=stubs.api)
341 self.assertEqual(exited, 0)
343 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
344 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop"
346 stubs.api.pipeline_instances().create.assert_called_with(
347 body=JsonDiffMatcher(expect_pipeline))
348 self.assertEqual(capture_stdout.getvalue(),
349 stubs.expect_pipeline_uuid + '\n')
352 @mock.patch("time.sleep")
354 def test_submit_runner_ram(self, stubs, tm):
355 capture_stdout = cStringIO.StringIO()
356 exited = arvados_cwl.main(
357 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=2048",
358 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
359 capture_stdout, sys.stderr, api_client=stubs.api)
360 self.assertEqual(exited, 0)
362 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
363 expect_pipeline["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048
365 stubs.api.pipeline_instances().create.assert_called_with(
366 body=JsonDiffMatcher(expect_pipeline))
367 self.assertEqual(capture_stdout.getvalue(),
368 stubs.expect_pipeline_uuid + '\n')
371 @mock.patch("time.sleep")
373 def test_submit_invalid_runner_ram(self, stubs, tm):
374 capture_stdout = cStringIO.StringIO()
375 exited = arvados_cwl.main(
376 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048",
377 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
378 capture_stdout, sys.stderr, api_client=stubs.api)
379 self.assertEqual(exited, 1)
381 @mock.patch("time.sleep")
383 def test_submit_output_name(self, stubs, tm):
384 output_name = "test_output_name"
386 capture_stdout = cStringIO.StringIO()
387 exited = arvados_cwl.main(
388 ["--submit", "--no-wait", "--debug", "--output-name", output_name,
389 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
390 capture_stdout, sys.stderr, api_client=stubs.api)
391 self.assertEqual(exited, 0)
393 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
394 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name
396 stubs.api.pipeline_instances().create.assert_called_with(
397 body=JsonDiffMatcher(expect_pipeline))
398 self.assertEqual(capture_stdout.getvalue(),
399 stubs.expect_pipeline_uuid + '\n')
402 @mock.patch("time.sleep")
404 def test_submit_pipeline_name(self, stubs, tm):
405 capture_stdout = cStringIO.StringIO()
406 exited = arvados_cwl.main(
407 ["--submit", "--no-wait", "--debug", "--name=hello job 123",
408 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
409 capture_stdout, sys.stderr, api_client=stubs.api)
410 self.assertEqual(exited, 0)
412 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
413 expect_pipeline["name"] = "hello job 123"
415 stubs.api.pipeline_instances().create.assert_called_with(
416 body=JsonDiffMatcher(expect_pipeline))
417 self.assertEqual(capture_stdout.getvalue(),
418 stubs.expect_pipeline_uuid + '\n')
420 @mock.patch("time.sleep")
422 def test_submit_output_tags(self, stubs, tm):
423 output_tags = "tag0,tag1,tag2"
425 capture_stdout = cStringIO.StringIO()
426 exited = arvados_cwl.main(
427 ["--submit", "--no-wait", "--debug", "--output-tags", output_tags,
428 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
429 capture_stdout, sys.stderr, api_client=stubs.api)
430 self.assertEqual(exited, 0)
432 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
433 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags
435 stubs.api.pipeline_instances().create.assert_called_with(
436 body=JsonDiffMatcher(expect_pipeline))
437 self.assertEqual(capture_stdout.getvalue(),
438 stubs.expect_pipeline_uuid + '\n')
440 @mock.patch("time.sleep")
442 def test_submit_with_project_uuid(self, stubs, tm):
443 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
445 exited = arvados_cwl.main(
446 ["--submit", "--no-wait",
447 "--project-uuid", project_uuid,
448 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
449 sys.stdout, sys.stderr, api_client=stubs.api)
450 self.assertEqual(exited, 0)
452 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
453 expect_pipeline["owner_uuid"] = project_uuid
454 stubs.api.pipeline_instances().create.assert_called_with(
455 body=JsonDiffMatcher(expect_pipeline))
458 def test_submit_container(self, stubs):
459 capture_stdout = cStringIO.StringIO()
461 exited = arvados_cwl.main(
462 ["--submit", "--no-wait", "--api=containers", "--debug",
463 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
464 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
465 self.assertEqual(exited, 0)
467 logging.exception("")
469 stubs.api.collections().create.assert_has_calls([
470 mock.call(body=JsonDiffMatcher({
472 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
473 'replication_desired': None,
474 'name': 'submit_tool.cwl dependencies',
475 }), ensure_unique_name=True),
476 mock.call(body=JsonDiffMatcher({
478 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
479 'replication_desired': None,
480 'name': 'submit_wf.cwl input',
481 }), ensure_unique_name=True)])
483 expect_container = copy.deepcopy(stubs.expect_container_spec)
484 stubs.api.container_requests().create.assert_called_with(
485 body=JsonDiffMatcher(expect_container))
486 self.assertEqual(capture_stdout.getvalue(),
487 stubs.expect_container_request_uuid + '\n')
490 def test_submit_container_no_reuse(self, stubs):
491 capture_stdout = cStringIO.StringIO()
493 exited = arvados_cwl.main(
494 ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse",
495 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
496 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
497 self.assertEqual(exited, 0)
499 logging.exception("")
501 expect_container = copy.deepcopy(stubs.expect_container_spec)
502 expect_container["command"] = [
503 'arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
504 '--disable-reuse', '--on-error=continue', '--eval-timeout=20',
505 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
506 expect_container["use_existing"] = False
508 stubs.api.container_requests().create.assert_called_with(
509 body=JsonDiffMatcher(expect_container))
510 self.assertEqual(capture_stdout.getvalue(),
511 stubs.expect_container_request_uuid + '\n')
515 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
516 capture_stdout = cStringIO.StringIO()
518 exited = arvados_cwl.main(
519 ["--submit", "--no-wait", "--api=containers", "--debug",
520 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
521 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
522 self.assertEqual(exited, 0)
524 expect_container = copy.deepcopy(stubs.expect_container_spec)
525 expect_container["command"] = [
526 'arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
527 '--disable-reuse', '--on-error=continue', '--eval-timeout=20',
528 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
529 expect_container["use_existing"] = False
530 expect_container["name"] = "submit_wf_no_reuse.cwl"
531 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
533 "class": "http://arvados.org/cwl#ReuseRequirement",
534 "enableReuse": False,
537 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
538 "arv": "http://arvados.org/cwl#",
539 "cwltool": "http://commonwl.org/cwltool#"
542 stubs.api.container_requests().create.assert_called_with(
543 body=JsonDiffMatcher(expect_container))
544 self.assertEqual(capture_stdout.getvalue(),
545 stubs.expect_container_request_uuid + '\n')
549 def test_submit_container_on_error(self, stubs):
550 capture_stdout = cStringIO.StringIO()
552 exited = arvados_cwl.main(
553 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
554 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
555 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
556 self.assertEqual(exited, 0)
558 logging.exception("")
560 expect_container = copy.deepcopy(stubs.expect_container_spec)
561 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
562 '--enable-reuse', '--on-error=stop', '--eval-timeout=20',
563 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
565 stubs.api.container_requests().create.assert_called_with(
566 body=JsonDiffMatcher(expect_container))
567 self.assertEqual(capture_stdout.getvalue(),
568 stubs.expect_container_request_uuid + '\n')
571 def test_submit_container_output_name(self, stubs):
572 output_name = "test_output_name"
574 capture_stdout = cStringIO.StringIO()
576 exited = arvados_cwl.main(
577 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
578 "tests/wf/submit_wf.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 logging.exception("")
584 expect_container = copy.deepcopy(stubs.expect_container_spec)
585 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
586 "--output-name="+output_name, '--enable-reuse', '--on-error=continue', '--eval-timeout=20',
587 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
588 expect_container["output_name"] = output_name
590 stubs.api.container_requests().create.assert_called_with(
591 body=JsonDiffMatcher(expect_container))
592 self.assertEqual(capture_stdout.getvalue(),
593 stubs.expect_container_request_uuid + '\n')
597 def test_submit_container_output_ttl(self, stubs):
598 capture_stdout = cStringIO.StringIO()
600 exited = arvados_cwl.main(
601 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
602 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
603 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
604 self.assertEqual(exited, 0)
606 logging.exception("")
608 expect_container = copy.deepcopy(stubs.expect_container_spec)
609 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
610 '--enable-reuse', '--on-error=continue',
611 "--intermediate-output-ttl=3600", '--eval-timeout=20',
612 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
614 stubs.api.container_requests().create.assert_called_with(
615 body=JsonDiffMatcher(expect_container))
616 self.assertEqual(capture_stdout.getvalue(),
617 stubs.expect_container_request_uuid + '\n')
620 def test_submit_container_trash_intermediate(self, stubs):
621 capture_stdout = cStringIO.StringIO()
623 exited = arvados_cwl.main(
624 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
625 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
626 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
627 self.assertEqual(exited, 0)
629 logging.exception("")
631 expect_container = copy.deepcopy(stubs.expect_container_spec)
632 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
633 '--enable-reuse', '--on-error=continue',
634 "--trash-intermediate", '--eval-timeout=20',
635 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
637 stubs.api.container_requests().create.assert_called_with(
638 body=JsonDiffMatcher(expect_container))
639 self.assertEqual(capture_stdout.getvalue(),
640 stubs.expect_container_request_uuid + '\n')
643 def test_submit_container_output_tags(self, stubs):
644 output_tags = "tag0,tag1,tag2"
646 capture_stdout = cStringIO.StringIO()
648 exited = arvados_cwl.main(
649 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
650 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
651 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
652 self.assertEqual(exited, 0)
654 logging.exception("")
656 expect_container = copy.deepcopy(stubs.expect_container_spec)
657 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
658 "--output-tags="+output_tags, '--enable-reuse', '--on-error=continue', '--eval-timeout=20',
659 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
661 stubs.api.container_requests().create.assert_called_with(
662 body=JsonDiffMatcher(expect_container))
663 self.assertEqual(capture_stdout.getvalue(),
664 stubs.expect_container_request_uuid + '\n')
667 def test_submit_container_runner_ram(self, stubs):
668 capture_stdout = cStringIO.StringIO()
670 exited = arvados_cwl.main(
671 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
672 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
673 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
674 self.assertEqual(exited, 0)
676 logging.exception("")
678 expect_container = copy.deepcopy(stubs.expect_container_spec)
679 expect_container["runtime_constraints"]["ram"] = 2048*1024*1024
681 stubs.api.container_requests().create.assert_called_with(
682 body=JsonDiffMatcher(expect_container))
683 self.assertEqual(capture_stdout.getvalue(),
684 stubs.expect_container_request_uuid + '\n')
686 @mock.patch("arvados.collection.CollectionReader")
687 @mock.patch("time.sleep")
689 def test_submit_file_keepref(self, stubs, tm, collectionReader):
690 capture_stdout = cStringIO.StringIO()
691 exited = arvados_cwl.main(
692 ["--submit", "--no-wait", "--api=containers", "--debug",
693 "tests/wf/submit_keepref_wf.cwl"],
694 capture_stdout, sys.stderr, api_client=stubs.api)
695 self.assertEqual(exited, 0)
698 @mock.patch("arvados.collection.CollectionReader")
699 @mock.patch("time.sleep")
701 def test_submit_keepref(self, stubs, tm, reader):
702 capture_stdout = cStringIO.StringIO()
704 with open("tests/wf/expect_arvworkflow.cwl") as f:
705 reader().open().__enter__().read.return_value = f.read()
707 exited = arvados_cwl.main(
708 ["--submit", "--no-wait", "--api=containers", "--debug",
709 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
710 capture_stdout, sys.stderr, api_client=stubs.api)
711 self.assertEqual(exited, 0)
721 'path': '/var/spool/cwl/cwl.output.json',
724 '/var/lib/cwl/workflow': {
725 'portable_data_hash': '99999999999999999999999999999994+99',
728 '/var/lib/cwl/cwl.input.json': {
734 }, 'state': 'Committed',
736 'output_path': '/var/spool/cwl',
737 'name': 'expect_arvworkflow.cwl#main',
738 'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
739 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
740 '--enable-reuse', '--on-error=continue', '--eval-timeout=20',
741 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
742 'cwd': '/var/spool/cwl',
743 'runtime_constraints': {
748 'use_existing': True,
753 stubs.api.container_requests().create.assert_called_with(
754 body=JsonDiffMatcher(expect_container))
755 self.assertEqual(capture_stdout.getvalue(),
756 stubs.expect_container_request_uuid + '\n')
759 @mock.patch("arvados.collection.CollectionReader")
760 @mock.patch("time.sleep")
762 def test_submit_jobs_keepref(self, stubs, tm, reader):
763 capture_stdout = cStringIO.StringIO()
765 with open("tests/wf/expect_arvworkflow.cwl") as f:
766 reader().open().__enter__().read.return_value = f.read()
768 exited = arvados_cwl.main(
769 ["--submit", "--no-wait", "--api=jobs", "--debug",
770 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
771 capture_stdout, sys.stderr, api_client=stubs.api)
772 self.assertEqual(exited, 0)
774 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
775 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX"
776 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"]
777 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"]
778 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main"
779 expect_pipeline["name"] = "expect_arvworkflow.cwl#main"
780 stubs.api.pipeline_instances().create.assert_called_with(
781 body=JsonDiffMatcher(expect_pipeline))
783 @mock.patch("time.sleep")
785 def test_submit_arvworkflow(self, stubs, tm):
786 capture_stdout = cStringIO.StringIO()
788 with open("tests/wf/expect_arvworkflow.cwl") as f:
789 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
791 exited = arvados_cwl.main(
792 ["--submit", "--no-wait", "--api=containers", "--debug",
793 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
794 capture_stdout, sys.stderr, api_client=stubs.api)
795 self.assertEqual(exited, 0)
805 'path': '/var/spool/cwl/cwl.output.json',
808 '/var/lib/cwl/workflow.json': {
811 'cwlVersion': 'v1.0',
816 {'type': 'string', 'id': '#main/x'}
819 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
820 'run': '#submit_tool.cwl',
830 'inputBinding': {'position': 1},
832 'id': '#submit_tool.cwl/x'}
835 {'dockerPull': 'debian:8', 'class': 'DockerRequirement'}
837 'id': '#submit_tool.cwl',
839 'baseCommand': 'cat',
840 'class': 'CommandLineTool'
845 '/var/lib/cwl/cwl.input.json': {
851 }, 'state': 'Committed',
853 'output_path': '/var/spool/cwl',
854 'name': 'a test workflow',
855 'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
856 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
857 '--enable-reuse', '--on-error=continue', '--eval-timeout=20',
858 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
859 'cwd': '/var/spool/cwl',
860 'runtime_constraints': {
865 'use_existing': True,
867 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
872 stubs.api.container_requests().create.assert_called_with(
873 body=JsonDiffMatcher(expect_container))
874 self.assertEqual(capture_stdout.getvalue(),
875 stubs.expect_container_request_uuid + '\n')
879 def test_submit_container_name(self, stubs):
880 capture_stdout = cStringIO.StringIO()
882 exited = arvados_cwl.main(
883 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
884 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
885 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
886 self.assertEqual(exited, 0)
888 logging.exception("")
890 expect_container = copy.deepcopy(stubs.expect_container_spec)
891 expect_container["name"] = "hello container 123"
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')
900 def test_submit_container_project(self, stubs):
901 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
902 capture_stdout = cStringIO.StringIO()
904 exited = arvados_cwl.main(
905 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
906 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
907 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
908 self.assertEqual(exited, 0)
910 logging.exception("")
912 expect_container = copy.deepcopy(stubs.expect_container_spec)
913 expect_container["owner_uuid"] = project_uuid
914 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
915 '--enable-reuse', '--on-error=continue', '--project-uuid='+project_uuid, '--eval-timeout=20',
916 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
918 stubs.api.container_requests().create.assert_called_with(
919 body=JsonDiffMatcher(expect_container))
920 self.assertEqual(capture_stdout.getvalue(),
921 stubs.expect_container_request_uuid + '\n')
924 def test_submit_container_eval_timeout(self, stubs):
925 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
926 capture_stdout = cStringIO.StringIO()
928 exited = arvados_cwl.main(
929 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
930 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
931 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
932 self.assertEqual(exited, 0)
934 logging.exception("")
936 expect_container = copy.deepcopy(stubs.expect_container_spec)
937 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
938 '--enable-reuse', '--on-error=continue', '--eval-timeout=60.0',
939 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
941 stubs.api.container_requests().create.assert_called_with(
942 body=JsonDiffMatcher(expect_container))
943 self.assertEqual(capture_stdout.getvalue(),
944 stubs.expect_container_request_uuid + '\n')
948 def test_submit_job_runner_image(self, stubs):
949 capture_stdout = cStringIO.StringIO()
951 exited = arvados_cwl.main(
952 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
953 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
954 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
955 self.assertEqual(exited, 0)
957 logging.exception("")
959 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "arvados/jobs:123"
961 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
962 stubs.api.pipeline_instances().create.assert_called_with(
963 body=JsonDiffMatcher(expect_pipeline))
964 self.assertEqual(capture_stdout.getvalue(),
965 stubs.expect_pipeline_uuid + '\n')
968 def test_submit_container_runner_image(self, stubs):
969 capture_stdout = cStringIO.StringIO()
971 exited = arvados_cwl.main(
972 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
973 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
974 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
975 self.assertEqual(exited, 0)
977 logging.exception("")
979 stubs.expect_container_spec["container_image"] = "arvados/jobs:123"
981 expect_container = copy.deepcopy(stubs.expect_container_spec)
982 stubs.api.container_requests().create.assert_called_with(
983 body=JsonDiffMatcher(expect_container))
984 self.assertEqual(capture_stdout.getvalue(),
985 stubs.expect_container_request_uuid + '\n')
988 def test_submit_priority(self, stubs):
989 capture_stdout = cStringIO.StringIO()
991 exited = arvados_cwl.main(
992 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
993 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
994 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
995 self.assertEqual(exited, 0)
997 logging.exception("")
999 stubs.expect_container_spec["priority"] = 669
1001 expect_container = copy.deepcopy(stubs.expect_container_spec)
1002 stubs.api.container_requests().create.assert_called_with(
1003 body=JsonDiffMatcher(expect_container))
1004 self.assertEqual(capture_stdout.getvalue(),
1005 stubs.expect_container_request_uuid + '\n')
1008 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1009 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1010 @mock.patch("arvados.api")
1011 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1012 arvrunner = mock.MagicMock()
1013 arvrunner.project_uuid = ""
1014 api.return_value = mock.MagicMock()
1015 arvrunner.api = api.return_value
1016 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1017 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1018 "link_class": "docker_image_repo+tag",
1019 "name": "arvados/jobs:"+arvados_cwl.__version__,
1021 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1022 {"items": [{"created_at": "",
1024 "link_class": "docker_image_hash",
1027 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1029 find_one_image_hash.return_value = "123456"
1031 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1033 "manifest_text": "",
1035 }], "items_available": 1, "offset": 0},)
1036 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1037 self.assertEqual("arvados/jobs:"+arvados_cwl.__version__,
1038 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1041 def test_submit_secrets(self, stubs):
1042 capture_stdout = cStringIO.StringIO()
1044 exited = arvados_cwl.main(
1045 ["--submit", "--no-wait", "--api=containers", "--debug",
1046 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1047 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1048 self.assertEqual(exited, 0)
1050 logging.exception("")
1053 expect_container = {
1055 "arvados-cwl-runner",
1058 "--no-log-timestamps",
1060 "--on-error=continue",
1061 "--eval-timeout=20",
1062 "/var/lib/cwl/workflow.json#main",
1063 "/var/lib/cwl/cwl.input.json"
1065 "container_image": "arvados/jobs:"+arvados_cwl.__version__,
1066 "cwd": "/var/spool/cwl",
1068 "/var/lib/cwl/cwl.input.json": {
1071 "$include": "/secrets/s0"
1076 "/var/lib/cwl/workflow.json": {
1081 "cwltool": "http://commonwl.org/cwltool#"
1087 "class": "CommandLineTool",
1090 "class": "http://commonwl.org/cwltool#Secrets",
1092 "#secret_job.cwl/pw"
1096 "id": "#secret_job.cwl",
1099 "id": "#secret_job.cwl/pw",
1105 "id": "#secret_job.cwl/out",
1109 "stdout": "hashed_example.txt",
1112 "class": "InitialWorkDirRequirement",
1115 "entry": "username: user\npassword: $(inputs.pw)\n",
1116 "entryname": "example.conf"
1123 "class": "Workflow",
1126 "class": "DockerRequirement",
1127 "dockerPull": "debian:8"
1130 "class": "http://commonwl.org/cwltool#Secrets",
1146 "outputSource": "#main/step1/out",
1152 "id": "#main/step1",
1155 "id": "#main/step1/pw",
1156 "source": "#main/pw"
1162 "run": "#secret_job.cwl"
1167 "cwlVersion": "v1.0"
1172 "kind": "collection",
1177 "path": "/var/spool/cwl/cwl.output.json"
1180 "name": "secret_wf.cwl",
1181 "output_path": "/var/spool/cwl",
1185 "runtime_constraints": {
1196 "state": "Committed",
1197 "use_existing": True
1200 stubs.api.container_requests().create.assert_called_with(
1201 body=JsonDiffMatcher(expect_container))
1202 self.assertEqual(capture_stdout.getvalue(),
1203 stubs.expect_container_request_uuid + '\n')
1206 class TestCreateTemplate(unittest.TestCase):
1207 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1209 def _adjust_script_params(self, expect_component):
1210 expect_component['script_parameters']['x'] = {
1211 'dataclass': 'File',
1214 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1216 expect_component['script_parameters']['y'] = {
1217 'dataclass': 'Collection',
1219 'type': 'Directory',
1220 'value': '99999999999999999999999999999998+99',
1222 expect_component['script_parameters']['z'] = {
1223 'dataclass': 'Collection',
1225 'type': 'Directory',
1229 def test_create(self, stubs):
1230 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1232 capture_stdout = cStringIO.StringIO()
1234 exited = arvados_cwl.main(
1235 ["--create-workflow", "--debug",
1237 "--project-uuid", project_uuid,
1238 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1239 capture_stdout, sys.stderr, api_client=stubs.api)
1240 self.assertEqual(exited, 0)
1242 stubs.api.pipeline_instances().create.refute_called()
1243 stubs.api.jobs().create.refute_called()
1245 expect_component = copy.deepcopy(stubs.expect_job_spec)
1246 self._adjust_script_params(expect_component)
1249 "submit_wf.cwl": expect_component,
1251 "name": "submit_wf.cwl",
1252 "owner_uuid": project_uuid,
1254 stubs.api.pipeline_templates().create.assert_called_with(
1255 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1257 self.assertEqual(capture_stdout.getvalue(),
1258 stubs.expect_pipeline_template_uuid + '\n')
1262 def test_create_name(self, stubs):
1263 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1265 capture_stdout = cStringIO.StringIO()
1267 exited = arvados_cwl.main(
1268 ["--create-workflow", "--debug",
1269 "--project-uuid", project_uuid,
1271 "--name", "testing 123",
1272 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1273 capture_stdout, sys.stderr, api_client=stubs.api)
1274 self.assertEqual(exited, 0)
1276 stubs.api.pipeline_instances().create.refute_called()
1277 stubs.api.jobs().create.refute_called()
1279 expect_component = copy.deepcopy(stubs.expect_job_spec)
1280 self._adjust_script_params(expect_component)
1283 "testing 123": expect_component,
1285 "name": "testing 123",
1286 "owner_uuid": project_uuid,
1288 stubs.api.pipeline_templates().create.assert_called_with(
1289 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1291 self.assertEqual(capture_stdout.getvalue(),
1292 stubs.expect_pipeline_template_uuid + '\n')
1296 def test_update_name(self, stubs):
1297 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1299 capture_stdout = cStringIO.StringIO()
1301 exited = arvados_cwl.main(
1302 ["--update-workflow", self.existing_template_uuid,
1304 "--project-uuid", project_uuid,
1306 "--name", "testing 123",
1307 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1308 capture_stdout, sys.stderr, api_client=stubs.api)
1309 self.assertEqual(exited, 0)
1311 stubs.api.pipeline_instances().create.refute_called()
1312 stubs.api.jobs().create.refute_called()
1314 expect_component = copy.deepcopy(stubs.expect_job_spec)
1315 self._adjust_script_params(expect_component)
1318 "testing 123": expect_component,
1320 "name": "testing 123",
1321 "owner_uuid": project_uuid,
1323 stubs.api.pipeline_templates().create.refute_called()
1324 stubs.api.pipeline_templates().update.assert_called_with(
1325 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1327 self.assertEqual(capture_stdout.getvalue(),
1328 self.existing_template_uuid + '\n')
1331 class TestCreateWorkflow(unittest.TestCase):
1332 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1333 expect_workflow = StripYAMLComments(
1334 open("tests/wf/expect_packed.cwl").read())
1337 def test_create(self, stubs):
1338 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1340 capture_stdout = cStringIO.StringIO()
1342 exited = arvados_cwl.main(
1343 ["--create-workflow", "--debug",
1345 "--project-uuid", project_uuid,
1346 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1347 capture_stdout, sys.stderr, api_client=stubs.api)
1348 self.assertEqual(exited, 0)
1350 stubs.api.pipeline_templates().create.refute_called()
1351 stubs.api.container_requests().create.refute_called()
1355 "owner_uuid": project_uuid,
1356 "name": "submit_wf.cwl",
1358 "definition": self.expect_workflow,
1361 stubs.api.workflows().create.assert_called_with(
1362 body=JsonDiffMatcher(body))
1364 self.assertEqual(capture_stdout.getvalue(),
1365 stubs.expect_workflow_uuid + '\n')
1369 def test_create_name(self, stubs):
1370 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1372 capture_stdout = cStringIO.StringIO()
1374 exited = arvados_cwl.main(
1375 ["--create-workflow", "--debug",
1377 "--project-uuid", project_uuid,
1378 "--name", "testing 123",
1379 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1380 capture_stdout, sys.stderr, api_client=stubs.api)
1381 self.assertEqual(exited, 0)
1383 stubs.api.pipeline_templates().create.refute_called()
1384 stubs.api.container_requests().create.refute_called()
1388 "owner_uuid": project_uuid,
1389 "name": "testing 123",
1391 "definition": self.expect_workflow,
1394 stubs.api.workflows().create.assert_called_with(
1395 body=JsonDiffMatcher(body))
1397 self.assertEqual(capture_stdout.getvalue(),
1398 stubs.expect_workflow_uuid + '\n')
1401 def test_incompatible_api(self, stubs):
1402 capture_stderr = cStringIO.StringIO()
1403 logging.getLogger('arvados.cwl-runner').addHandler(
1404 logging.StreamHandler(capture_stderr))
1406 exited = arvados_cwl.main(
1407 ["--update-workflow", self.existing_workflow_uuid,
1410 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1411 sys.stderr, sys.stderr, api_client=stubs.api)
1412 self.assertEqual(exited, 1)
1413 self.assertRegexpMatches(
1414 capture_stderr.getvalue(),
1415 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1418 def test_update(self, stubs):
1419 capture_stdout = cStringIO.StringIO()
1421 exited = arvados_cwl.main(
1422 ["--update-workflow", self.existing_workflow_uuid,
1424 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1425 capture_stdout, sys.stderr, api_client=stubs.api)
1426 self.assertEqual(exited, 0)
1430 "name": "submit_wf.cwl",
1432 "definition": self.expect_workflow,
1435 stubs.api.workflows().update.assert_called_with(
1436 uuid=self.existing_workflow_uuid,
1437 body=JsonDiffMatcher(body))
1438 self.assertEqual(capture_stdout.getvalue(),
1439 self.existing_workflow_uuid + '\n')
1443 def test_update_name(self, stubs):
1444 capture_stdout = cStringIO.StringIO()
1446 exited = arvados_cwl.main(
1447 ["--update-workflow", self.existing_workflow_uuid,
1448 "--debug", "--name", "testing 123",
1449 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1450 capture_stdout, sys.stderr, api_client=stubs.api)
1451 self.assertEqual(exited, 0)
1455 "name": "testing 123",
1457 "definition": self.expect_workflow,
1460 stubs.api.workflows().update.assert_called_with(
1461 uuid=self.existing_workflow_uuid,
1462 body=JsonDiffMatcher(body))
1463 self.assertEqual(capture_stdout.getvalue(),
1464 self.existing_workflow_uuid + '\n')
1468 def test_create_collection_per_tool(self, stubs):
1469 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1471 capture_stdout = cStringIO.StringIO()
1473 exited = arvados_cwl.main(
1474 ["--create-workflow", "--debug",
1476 "--project-uuid", project_uuid,
1477 "tests/collection_per_tool/collection_per_tool.cwl"],
1478 capture_stdout, sys.stderr, api_client=stubs.api)
1479 self.assertEqual(exited, 0)
1481 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1482 expect_workflow = StripYAMLComments(open(toolfile).read())
1486 "owner_uuid": project_uuid,
1487 "name": "collection_per_tool.cwl",
1489 "definition": expect_workflow,
1492 stubs.api.workflows().create.assert_called_with(
1493 body=JsonDiffMatcher(body))
1495 self.assertEqual(capture_stdout.getvalue(),
1496 stubs.expect_workflow_uuid + '\n')
1498 class TestTemplateInputs(unittest.TestCase):
1501 "inputs_test.cwl": {
1502 'runtime_constraints': {
1503 'docker_image': 'arvados/jobs:'+arvados_cwl.__version__,
1504 'min_ram_mb_per_node': 1024
1506 'script_parameters': {
1508 '6c5ee1cd606088106d9f28367cde1e41+60/workflow.cwl#main',
1509 'optionalFloatInput': None,
1512 'dataclass': 'File',
1514 'title': "It's a file; we expect to find some characters in it.",
1515 'description': 'If there were anything further to say, it would be said here,\nor here.'
1519 'dataclass': 'number',
1521 'title': 'Floats like a duck',
1525 'optionalFloatInput': {
1526 'type': ['null', 'float'],
1527 'dataclass': 'number',
1532 'dataclass': 'boolean',
1534 'title': 'True or false?',
1537 'repository': 'arvados',
1538 'script_version': 'master',
1539 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1540 'script': 'cwl-runner',
1543 "name": "inputs_test.cwl",
1547 def test_inputs_empty(self, stubs):
1548 exited = arvados_cwl.main(
1549 ["--create-template",
1550 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1551 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1552 self.assertEqual(exited, 0)
1554 stubs.api.pipeline_templates().create.assert_called_with(
1555 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1558 def test_inputs(self, stubs):
1559 exited = arvados_cwl.main(
1560 ["--create-template",
1561 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1562 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
1563 self.assertEqual(exited, 0)
1565 expect_template = copy.deepcopy(self.expect_template)
1566 params = expect_template[
1567 "components"]["inputs_test.cwl"]["script_parameters"]
1568 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1569 params["cwl:tool"] = '6c5ee1cd606088106d9f28367cde1e41+60/workflow.cwl#main'
1570 params["floatInput"]["value"] = 1.234
1571 params["boolInput"]["value"] = True
1573 stubs.api.pipeline_templates().create.assert_called_with(
1574 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)