1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from future import standard_library
6 standard_library.install_aliases()
7 from builtins import object
8 from builtins import bytes
21 import arvados.collection
23 import arvados_cwl.executor
24 import arvados_cwl.runner
27 from .matcher import JsonDiffMatcher, StripYAMLComments
28 from .mock_discovery import get_rootDesc
30 import ruamel.yaml as yaml
35 @functools.wraps(func)
36 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
37 @mock.patch("arvados.collection.KeepClient")
38 @mock.patch("arvados.keep.KeepClient")
39 @mock.patch("arvados.events.subscribe")
40 def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs):
45 stubs.keepdocker = keepdocker
47 def putstub(p, **kwargs):
48 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
49 keep_client1().put.side_effect = putstub
50 keep_client1.put.side_effect = putstub
51 keep_client2().put.side_effect = putstub
52 keep_client2.put.side_effect = putstub
54 stubs.keep_client = keep_client2
55 stubs.docker_images = {
56 "arvados/jobs:"+arvados_cwl.__version__: [("zzzzz-4zz18-zzzzzzzzzzzzzd3", "")],
57 "debian:8": [("zzzzz-4zz18-zzzzzzzzzzzzzd4", "")],
58 "arvados/jobs:123": [("zzzzz-4zz18-zzzzzzzzzzzzzd5", "")],
59 "arvados/jobs:latest": [("zzzzz-4zz18-zzzzzzzzzzzzzd6", "")],
61 def kd(a, b, image_name=None, image_tag=None):
62 return stubs.docker_images.get("%s:%s" % (image_name, image_tag), [])
63 stubs.keepdocker.side_effect = kd
65 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
66 stubs.fake_container_uuid = "zzzzz-dz642-zzzzzzzzzzzzzzz"
68 stubs.api = mock.MagicMock()
69 stubs.api._rootDesc = get_rootDesc()
71 stubs.api.users().current().execute.return_value = {
72 "uuid": stubs.fake_user_uuid,
74 stubs.api.collections().list().execute.return_value = {"items": []}
75 stubs.api.containers().current().execute.return_value = {
76 "uuid": stubs.fake_container_uuid,
79 class CollectionExecute(object):
80 def __init__(self, exe):
82 def execute(self, num_retries=None):
85 def collection_createstub(created_collections, body, ensure_unique_name=None):
86 mt = body["manifest_text"].encode('utf-8')
87 uuid = "zzzzz-4zz18-zzzzzzzzzzzzzx%d" % len(created_collections)
88 pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt))
89 created_collections[uuid] = {
91 "portable_data_hash": pdh,
92 "manifest_text": mt.decode('utf-8')
94 return CollectionExecute(created_collections[uuid])
96 def collection_getstub(created_collections, uuid):
97 for v in created_collections.values():
98 if uuid in (v["uuid"], v["portable_data_hash"]):
99 return CollectionExecute(v)
101 created_collections = {
102 "99999999999999999999999999999998+99": {
104 "portable_data_hash": "99999999999999999999999999999998+99",
105 "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt"
107 "99999999999999999999999999999994+99": {
109 "portable_data_hash": "99999999999999999999999999999994+99",
110 "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl"
112 "zzzzz-4zz18-zzzzzzzzzzzzzd3": {
113 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd3",
114 "portable_data_hash": "999999999999999999999999999999d3+99",
117 "zzzzz-4zz18-zzzzzzzzzzzzzd4": {
118 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd4",
119 "portable_data_hash": "999999999999999999999999999999d4+99",
122 "zzzzz-4zz18-zzzzzzzzzzzzzd5": {
123 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd5",
124 "portable_data_hash": "999999999999999999999999999999d5+99",
127 "zzzzz-4zz18-zzzzzzzzzzzzzd6": {
128 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzd6",
129 "portable_data_hash": "999999999999999999999999999999d6+99",
133 stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections)
134 stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections)
136 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
137 stubs.api.jobs().create().execute.return_value = {
138 "uuid": stubs.expect_job_uuid,
142 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
143 stubs.api.container_requests().create().execute.return_value = {
144 "uuid": stubs.expect_container_request_uuid,
145 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
149 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
150 stubs.api.pipeline_templates().create().execute.return_value = {
151 "uuid": stubs.expect_pipeline_template_uuid,
153 stubs.expect_job_spec = {
154 'runtime_constraints': {
155 'docker_image': '999999999999999999999999999999d3+99',
156 'min_ram_mb_per_node': 1024
158 'script_parameters': {
160 'basename': 'blorp.txt',
161 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
165 'basename': '99999999999999999999999999999998+99',
166 'location': 'keep:99999999999999999999999999999998+99',
170 'basename': 'anonymous',
172 "basename": "renamed.txt",
174 "location": "keep:99999999999999999999999999999998+99/file1.txt",
179 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main'
181 'repository': 'arvados',
182 'script_version': 'master',
183 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
184 'script': 'cwl-runner'
186 stubs.pipeline_component = stubs.expect_job_spec.copy()
187 stubs.expect_pipeline_instance = {
188 'name': 'submit_wf.cwl',
189 'state': 'RunningOnServer',
193 'runtime_constraints': {'docker_image': '999999999999999999999999999999d3+99', 'min_ram_mb_per_node': 1024},
194 'script_parameters': {
195 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}},
197 'basename': 'blorp.txt',
199 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
202 'z': {"value": {'basename': 'anonymous', 'class': 'Directory',
205 'basename': 'renamed.txt',
206 'class': 'File', 'location':
207 'keep:99999999999999999999999999999998+99/file1.txt',
211 'cwl:tool': '57ad063d64c60dbddc027791f0649211+60/workflow.cwl#main',
213 'arv:enable_reuse': True,
214 'arv:on_error': 'continue'
216 'repository': 'arvados',
217 'script_version': 'master',
218 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
219 'script': 'cwl-runner',
220 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'}
224 stubs.pipeline_create = copy.deepcopy(stubs.expect_pipeline_instance)
225 stubs.expect_pipeline_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
226 stubs.pipeline_create["uuid"] = stubs.expect_pipeline_uuid
227 stubs.pipeline_with_job = copy.deepcopy(stubs.pipeline_create)
228 stubs.pipeline_with_job["components"]["cwl-runner"]["job"] = {
229 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
232 stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create
233 stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job
235 with open("tests/wf/submit_wf_packed.cwl") as f:
236 expect_packed_workflow = yaml.round_trip_load(f)
238 stubs.expect_container_spec = {
245 '/var/lib/cwl/workflow.json': {
246 'content': expect_packed_workflow,
250 'path': '/var/spool/cwl/cwl.output.json',
253 '/var/lib/cwl/cwl.input.json': {
257 'basename': '99999999999999999999999999999998+99',
258 'location': 'keep:99999999999999999999999999999998+99',
259 'class': 'Directory'},
261 'basename': u'blorp.txt',
263 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
266 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [
267 {'basename': 'renamed.txt',
269 'location': 'keep:99999999999999999999999999999998+99/file1.txt',
278 'state': 'Committed',
279 'command': ['arvados-cwl-runner', '--local', '--api=containers',
280 '--no-log-timestamps', '--disable-validate',
281 '--eval-timeout=20', '--thread-count=1',
282 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
283 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
284 'name': 'submit_wf.cwl',
285 'container_image': '999999999999999999999999999999d3+99',
286 'output_path': '/var/spool/cwl',
287 'cwd': '/var/spool/cwl',
288 'runtime_constraints': {
291 'ram': (1024+256)*1024*1024
293 'use_existing': True,
298 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
299 stubs.api.workflows().create().execute.return_value = {
300 "uuid": stubs.expect_workflow_uuid,
302 def update_mock(**kwargs):
303 stubs.updated_uuid = kwargs.get('uuid')
305 stubs.api.workflows().update.side_effect = update_mock
306 stubs.api.workflows().update().execute.side_effect = lambda **kwargs: {
307 "uuid": stubs.updated_uuid,
310 return func(self, stubs, *args, **kwargs)
314 class TestSubmit(unittest.TestCase):
315 @mock.patch("arvados_cwl.arvdocker.arv_docker_get_image")
316 @mock.patch("time.sleep")
318 def test_submit(self, stubs, tm, arvdock):
319 def get_image(api_client, dockerRequirement, pull_image, project_uuid):
320 if dockerRequirement["dockerPull"] == 'arvados/jobs:'+arvados_cwl.__version__:
321 return '999999999999999999999999999999d3+99'
322 elif dockerRequirement["dockerPull"] == "debian:8":
323 return '999999999999999999999999999999d4+99'
324 arvdock.side_effect = get_image
326 capture_stdout = io.StringIO()
327 exited = arvados_cwl.main(
328 ["--submit", "--no-wait", "--api=jobs", "--debug",
329 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
330 capture_stdout, sys.stderr, api_client=stubs.api)
331 self.assertEqual(exited, 0)
333 stubs.api.collections().create.assert_has_calls([
334 mock.call(body=JsonDiffMatcher({
336 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
337 'replication_desired': None,
338 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
339 }), ensure_unique_name=False),
340 mock.call(body=JsonDiffMatcher({
342 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
343 'replication_desired': None,
344 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
345 }), ensure_unique_name=False),
346 mock.call(body=JsonDiffMatcher({
348 ". 68089141fbf7e020ac90a9d6a575bc8f+1312 0:1312:workflow.cwl\n",
349 'replication_desired': None,
350 'name': 'submit_wf.cwl',
351 }), ensure_unique_name=True) ])
353 arvdock.assert_has_calls([
354 mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None),
355 mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8", 'http://arvados.org/cwl#dockerCollectionPDH': '999999999999999999999999999999d4+99'}, True, None),
356 mock.call(stubs.api, {'dockerPull': 'arvados/jobs:'+arvados_cwl.__version__}, True, None)
359 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
360 stubs.api.pipeline_instances().create.assert_called_with(
361 body=JsonDiffMatcher(expect_pipeline))
362 self.assertEqual(capture_stdout.getvalue(),
363 stubs.expect_pipeline_uuid + '\n')
366 @mock.patch("time.sleep")
368 def test_submit_no_reuse(self, stubs, tm):
369 capture_stdout = io.StringIO()
370 exited = arvados_cwl.main(
371 ["--submit", "--no-wait", "--api=jobs", "--debug", "--disable-reuse",
372 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
373 capture_stdout, sys.stderr, api_client=stubs.api)
374 self.assertEqual(exited, 0)
376 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
377 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False}
378 expect_pipeline["properties"] = {"run_options": {"enable_job_reuse": False}}
380 stubs.api.pipeline_instances().create.assert_called_with(
381 body=JsonDiffMatcher(expect_pipeline))
382 self.assertEqual(capture_stdout.getvalue(),
383 stubs.expect_pipeline_uuid + '\n')
386 def test_error_when_multiple_storage_classes_specified(self, stubs):
387 storage_classes = "foo,bar"
388 exited = arvados_cwl.main(
389 ["--debug", "--storage-classes", storage_classes,
390 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
391 sys.stdin, sys.stderr, api_client=stubs.api)
392 self.assertEqual(exited, 1)
394 @mock.patch("time.sleep")
396 def test_submit_on_error(self, stubs, tm):
397 capture_stdout = io.StringIO()
398 exited = arvados_cwl.main(
399 ["--submit", "--no-wait", "--api=jobs", "--debug", "--on-error=stop",
400 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
401 capture_stdout, sys.stderr, api_client=stubs.api)
402 self.assertEqual(exited, 0)
404 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
405 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop"
407 stubs.api.pipeline_instances().create.assert_called_with(
408 body=JsonDiffMatcher(expect_pipeline))
409 self.assertEqual(capture_stdout.getvalue(),
410 stubs.expect_pipeline_uuid + '\n')
413 @mock.patch("time.sleep")
415 def test_submit_runner_ram(self, stubs, tm):
416 capture_stdout = io.StringIO()
417 exited = arvados_cwl.main(
418 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=2048",
419 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
420 capture_stdout, sys.stderr, api_client=stubs.api)
421 self.assertEqual(exited, 0)
423 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
424 expect_pipeline["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048
426 stubs.api.pipeline_instances().create.assert_called_with(
427 body=JsonDiffMatcher(expect_pipeline))
428 self.assertEqual(capture_stdout.getvalue(),
429 stubs.expect_pipeline_uuid + '\n')
432 @mock.patch("time.sleep")
434 def test_submit_invalid_runner_ram(self, stubs, tm):
435 capture_stdout = io.StringIO()
436 exited = arvados_cwl.main(
437 ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048",
438 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
439 capture_stdout, sys.stderr, api_client=stubs.api)
440 self.assertEqual(exited, 1)
442 @mock.patch("time.sleep")
444 def test_submit_output_name(self, stubs, tm):
445 output_name = "test_output_name"
447 capture_stdout = io.StringIO()
448 exited = arvados_cwl.main(
449 ["--submit", "--no-wait", "--debug", "--output-name", output_name,
450 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
451 capture_stdout, sys.stderr, api_client=stubs.api)
452 self.assertEqual(exited, 0)
454 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
455 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name
457 stubs.api.pipeline_instances().create.assert_called_with(
458 body=JsonDiffMatcher(expect_pipeline))
459 self.assertEqual(capture_stdout.getvalue(),
460 stubs.expect_pipeline_uuid + '\n')
463 @mock.patch("time.sleep")
465 def test_submit_pipeline_name(self, stubs, tm):
466 capture_stdout = io.StringIO()
467 exited = arvados_cwl.main(
468 ["--submit", "--no-wait", "--debug", "--name=hello job 123",
469 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
470 capture_stdout, sys.stderr, api_client=stubs.api)
471 self.assertEqual(exited, 0)
473 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
474 expect_pipeline["name"] = "hello job 123"
476 stubs.api.pipeline_instances().create.assert_called_with(
477 body=JsonDiffMatcher(expect_pipeline))
478 self.assertEqual(capture_stdout.getvalue(),
479 stubs.expect_pipeline_uuid + '\n')
481 @mock.patch("time.sleep")
483 def test_submit_output_tags(self, stubs, tm):
484 output_tags = "tag0,tag1,tag2"
486 capture_stdout = io.StringIO()
487 exited = arvados_cwl.main(
488 ["--submit", "--no-wait", "--debug", "--output-tags", output_tags,
489 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
490 capture_stdout, sys.stderr, api_client=stubs.api)
491 self.assertEqual(exited, 0)
493 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
494 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags
496 stubs.api.pipeline_instances().create.assert_called_with(
497 body=JsonDiffMatcher(expect_pipeline))
498 self.assertEqual(capture_stdout.getvalue(),
499 stubs.expect_pipeline_uuid + '\n')
501 @mock.patch("time.sleep")
503 def test_submit_with_project_uuid(self, stubs, tm):
504 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
506 exited = arvados_cwl.main(
507 ["--submit", "--no-wait", "--debug",
508 "--project-uuid", project_uuid,
509 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
510 sys.stdout, sys.stderr, api_client=stubs.api)
511 self.assertEqual(exited, 0)
513 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
514 expect_pipeline["owner_uuid"] = project_uuid
515 stubs.api.pipeline_instances().create.assert_called_with(
516 body=JsonDiffMatcher(expect_pipeline))
519 def test_submit_container(self, stubs):
520 capture_stdout = io.StringIO()
522 exited = arvados_cwl.main(
523 ["--submit", "--no-wait", "--api=containers", "--debug",
524 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
525 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
526 self.assertEqual(exited, 0)
528 logging.exception("")
530 stubs.api.collections().create.assert_has_calls([
531 mock.call(body=JsonDiffMatcher({
533 '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
534 'replication_desired': None,
535 'name': 'submit_tool.cwl dependencies (5d373e7629203ce39e7c22af98a0f881+52)',
536 }), ensure_unique_name=False),
537 mock.call(body=JsonDiffMatcher({
539 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
540 'replication_desired': None,
541 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)',
542 }), ensure_unique_name=False)])
544 expect_container = copy.deepcopy(stubs.expect_container_spec)
545 stubs.api.container_requests().create.assert_called_with(
546 body=JsonDiffMatcher(expect_container))
547 self.assertEqual(capture_stdout.getvalue(),
548 stubs.expect_container_request_uuid + '\n')
551 def test_submit_container_no_reuse(self, stubs):
552 capture_stdout = io.StringIO()
554 exited = arvados_cwl.main(
555 ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse",
556 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
557 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
558 self.assertEqual(exited, 0)
560 logging.exception("")
562 expect_container = copy.deepcopy(stubs.expect_container_spec)
563 expect_container["command"] = [
564 'arvados-cwl-runner', '--local', '--api=containers',
565 '--no-log-timestamps', '--disable-validate',
566 '--eval-timeout=20', '--thread-count=1',
567 '--disable-reuse', "--collection-cache-size=256",
568 '--debug', '--on-error=continue',
569 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
570 expect_container["use_existing"] = False
572 stubs.api.container_requests().create.assert_called_with(
573 body=JsonDiffMatcher(expect_container))
574 self.assertEqual(capture_stdout.getvalue(),
575 stubs.expect_container_request_uuid + '\n')
579 def test_submit_container_reuse_disabled_by_workflow(self, stubs):
580 capture_stdout = io.StringIO()
582 exited = arvados_cwl.main(
583 ["--submit", "--no-wait", "--api=containers", "--debug",
584 "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"],
585 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
586 self.assertEqual(exited, 0)
588 expect_container = copy.deepcopy(stubs.expect_container_spec)
589 expect_container["command"] = [
590 'arvados-cwl-runner', '--local', '--api=containers',
591 '--no-log-timestamps', '--disable-validate',
592 '--eval-timeout=20', '--thread-count=1',
593 '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
594 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
595 expect_container["use_existing"] = False
596 expect_container["name"] = "submit_wf_no_reuse.cwl"
597 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
599 "class": "http://arvados.org/cwl#ReuseRequirement",
600 "enableReuse": False,
603 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
604 "arv": "http://arvados.org/cwl#",
605 "cwltool": "http://commonwl.org/cwltool#"
608 stubs.api.container_requests().create.assert_called_with(
609 body=JsonDiffMatcher(expect_container))
610 self.assertEqual(capture_stdout.getvalue(),
611 stubs.expect_container_request_uuid + '\n')
615 def test_submit_container_on_error(self, stubs):
616 capture_stdout = io.StringIO()
618 exited = arvados_cwl.main(
619 ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop",
620 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
621 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
622 self.assertEqual(exited, 0)
624 logging.exception("")
626 expect_container = copy.deepcopy(stubs.expect_container_spec)
627 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
628 '--no-log-timestamps', '--disable-validate',
629 '--eval-timeout=20', '--thread-count=1',
630 '--enable-reuse', "--collection-cache-size=256",
631 '--debug', '--on-error=stop',
632 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
634 stubs.api.container_requests().create.assert_called_with(
635 body=JsonDiffMatcher(expect_container))
636 self.assertEqual(capture_stdout.getvalue(),
637 stubs.expect_container_request_uuid + '\n')
640 def test_submit_container_output_name(self, stubs):
641 output_name = "test_output_name"
643 capture_stdout = io.StringIO()
645 exited = arvados_cwl.main(
646 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name,
647 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
648 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
649 self.assertEqual(exited, 0)
651 logging.exception("")
653 expect_container = copy.deepcopy(stubs.expect_container_spec)
654 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
655 '--no-log-timestamps', '--disable-validate',
656 '--eval-timeout=20', '--thread-count=1',
657 '--enable-reuse', "--collection-cache-size=256",
658 "--output-name="+output_name, '--debug', '--on-error=continue',
659 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
660 expect_container["output_name"] = output_name
662 stubs.api.container_requests().create.assert_called_with(
663 body=JsonDiffMatcher(expect_container))
664 self.assertEqual(capture_stdout.getvalue(),
665 stubs.expect_container_request_uuid + '\n')
668 def test_submit_storage_classes(self, stubs):
669 capture_stdout = io.StringIO()
671 exited = arvados_cwl.main(
672 ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo",
673 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
674 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
675 self.assertEqual(exited, 0)
677 logging.exception("")
679 expect_container = copy.deepcopy(stubs.expect_container_spec)
680 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
681 '--no-log-timestamps', '--disable-validate',
682 '--eval-timeout=20', '--thread-count=1',
683 '--enable-reuse', "--collection-cache-size=256", "--debug",
684 "--storage-classes=foo", '--on-error=continue',
685 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
687 stubs.api.container_requests().create.assert_called_with(
688 body=JsonDiffMatcher(expect_container))
689 self.assertEqual(capture_stdout.getvalue(),
690 stubs.expect_container_request_uuid + '\n')
692 @mock.patch("arvados_cwl.task_queue.TaskQueue")
693 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
694 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
696 def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
697 def set_final_output(job_order, output_callback, runtimeContext):
698 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
700 job.side_effect = set_final_output
703 exited = arvados_cwl.main(
704 ["--debug", "--local", "--storage-classes=foo",
705 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
706 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
707 self.assertEqual(exited, 0)
709 logging.exception("")
711 make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
713 @mock.patch("arvados_cwl.task_queue.TaskQueue")
714 @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job")
715 @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection", return_value = (None, None))
717 def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq):
718 def set_final_output(job_order, output_callback, runtimeContext):
719 output_callback("zzzzz-4zz18-zzzzzzzzzzzzzzzz", "success")
721 job.side_effect = set_final_output
724 exited = arvados_cwl.main(
725 ["--debug", "--local",
726 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
727 sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
728 self.assertEqual(exited, 0)
730 logging.exception("")
732 make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz')
735 def test_submit_container_output_ttl(self, stubs):
736 capture_stdout = io.StringIO()
738 exited = arvados_cwl.main(
739 ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600",
740 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
741 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
742 self.assertEqual(exited, 0)
744 logging.exception("")
746 expect_container = copy.deepcopy(stubs.expect_container_spec)
747 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
748 '--no-log-timestamps', '--disable-validate',
749 '--eval-timeout=20', '--thread-count=1',
750 '--enable-reuse', "--collection-cache-size=256", '--debug',
751 '--on-error=continue',
752 "--intermediate-output-ttl=3600",
753 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
755 stubs.api.container_requests().create.assert_called_with(
756 body=JsonDiffMatcher(expect_container))
757 self.assertEqual(capture_stdout.getvalue(),
758 stubs.expect_container_request_uuid + '\n')
761 def test_submit_container_trash_intermediate(self, stubs):
762 capture_stdout = io.StringIO()
764 exited = arvados_cwl.main(
765 ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate",
766 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
767 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
768 self.assertEqual(exited, 0)
770 logging.exception("")
772 expect_container = copy.deepcopy(stubs.expect_container_spec)
773 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
774 '--no-log-timestamps', '--disable-validate',
775 '--eval-timeout=20', '--thread-count=1',
776 '--enable-reuse', "--collection-cache-size=256",
777 '--debug', '--on-error=continue',
778 "--trash-intermediate",
779 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
781 stubs.api.container_requests().create.assert_called_with(
782 body=JsonDiffMatcher(expect_container))
783 self.assertEqual(capture_stdout.getvalue(),
784 stubs.expect_container_request_uuid + '\n')
787 def test_submit_container_output_tags(self, stubs):
788 output_tags = "tag0,tag1,tag2"
790 capture_stdout = io.StringIO()
792 exited = arvados_cwl.main(
793 ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags,
794 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
795 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
796 self.assertEqual(exited, 0)
798 logging.exception("")
800 expect_container = copy.deepcopy(stubs.expect_container_spec)
801 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
802 '--no-log-timestamps', '--disable-validate',
803 '--eval-timeout=20', '--thread-count=1',
804 '--enable-reuse', "--collection-cache-size=256",
805 "--output-tags="+output_tags, '--debug', '--on-error=continue',
806 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
808 stubs.api.container_requests().create.assert_called_with(
809 body=JsonDiffMatcher(expect_container))
810 self.assertEqual(capture_stdout.getvalue(),
811 stubs.expect_container_request_uuid + '\n')
814 def test_submit_container_runner_ram(self, stubs):
815 capture_stdout = io.StringIO()
817 exited = arvados_cwl.main(
818 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048",
819 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
820 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
821 self.assertEqual(exited, 0)
823 logging.exception("")
825 expect_container = copy.deepcopy(stubs.expect_container_spec)
826 expect_container["runtime_constraints"]["ram"] = (2048+256)*1024*1024
828 stubs.api.container_requests().create.assert_called_with(
829 body=JsonDiffMatcher(expect_container))
830 self.assertEqual(capture_stdout.getvalue(),
831 stubs.expect_container_request_uuid + '\n')
833 @mock.patch("arvados.collection.CollectionReader")
834 @mock.patch("time.sleep")
836 def test_submit_file_keepref(self, stubs, tm, collectionReader):
837 capture_stdout = io.StringIO()
838 collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt")
839 exited = arvados_cwl.main(
840 ["--submit", "--no-wait", "--api=containers", "--debug",
841 "tests/wf/submit_keepref_wf.cwl"],
842 capture_stdout, sys.stderr, api_client=stubs.api)
843 self.assertEqual(exited, 0)
846 @mock.patch("arvados.collection.CollectionReader")
847 @mock.patch("time.sleep")
849 def test_submit_keepref(self, stubs, tm, reader):
850 capture_stdout = io.StringIO()
852 with open("tests/wf/expect_arvworkflow.cwl") as f:
853 reader().open().__enter__().read.return_value = f.read()
855 exited = arvados_cwl.main(
856 ["--submit", "--no-wait", "--api=containers", "--debug",
857 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
858 capture_stdout, sys.stderr, api_client=stubs.api)
859 self.assertEqual(exited, 0)
869 'path': '/var/spool/cwl/cwl.output.json',
872 '/var/lib/cwl/workflow': {
873 'portable_data_hash': '99999999999999999999999999999994+99',
876 '/var/lib/cwl/cwl.input.json': {
882 }, 'state': 'Committed',
883 'output_path': '/var/spool/cwl',
884 'name': 'expect_arvworkflow.cwl#main',
885 'container_image': '999999999999999999999999999999d3+99',
886 'command': ['arvados-cwl-runner', '--local', '--api=containers',
887 '--no-log-timestamps', '--disable-validate',
888 '--eval-timeout=20', '--thread-count=1',
889 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
890 '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
891 'cwd': '/var/spool/cwl',
892 'runtime_constraints': {
897 'use_existing': True,
902 stubs.api.container_requests().create.assert_called_with(
903 body=JsonDiffMatcher(expect_container))
904 self.assertEqual(capture_stdout.getvalue(),
905 stubs.expect_container_request_uuid + '\n')
908 @mock.patch("arvados.collection.CollectionReader")
909 @mock.patch("time.sleep")
911 def test_submit_jobs_keepref(self, stubs, tm, reader):
912 capture_stdout = io.StringIO()
914 with open("tests/wf/expect_arvworkflow.cwl") as f:
915 reader().open().__enter__().read.return_value = f.read()
917 exited = arvados_cwl.main(
918 ["--submit", "--no-wait", "--api=jobs", "--debug",
919 "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"],
920 capture_stdout, sys.stderr, api_client=stubs.api)
921 self.assertEqual(exited, 0)
923 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
924 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX"
925 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"]
926 del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"]
927 expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main"
928 expect_pipeline["name"] = "expect_arvworkflow.cwl#main"
929 stubs.api.pipeline_instances().create.assert_called_with(
930 body=JsonDiffMatcher(expect_pipeline))
932 @mock.patch("time.sleep")
934 def test_submit_arvworkflow(self, stubs, tm):
935 capture_stdout = io.StringIO()
937 with open("tests/wf/expect_arvworkflow.cwl") as f:
938 stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"}
940 exited = arvados_cwl.main(
941 ["--submit", "--no-wait", "--api=containers", "--debug",
942 "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"],
943 capture_stdout, sys.stderr, api_client=stubs.api)
944 self.assertEqual(exited, 0)
954 'path': '/var/spool/cwl/cwl.output.json',
957 '/var/lib/cwl/workflow.json': {
960 'cwlVersion': 'v1.0',
965 {'type': 'string', 'id': '#main/x'}
968 {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
969 'run': '#submit_tool.cwl',
979 'inputBinding': {'position': 1},
981 'id': '#submit_tool.cwl/x'}
985 'dockerPull': 'debian:8',
986 'class': 'DockerRequirement',
987 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
990 'id': '#submit_tool.cwl',
992 'baseCommand': 'cat',
993 'class': 'CommandLineTool'
998 '/var/lib/cwl/cwl.input.json': {
1004 }, 'state': 'Committed',
1005 'output_path': '/var/spool/cwl',
1006 'name': 'a test workflow',
1007 'container_image': "999999999999999999999999999999d3+99",
1008 'command': ['arvados-cwl-runner', '--local', '--api=containers',
1009 '--no-log-timestamps', '--disable-validate',
1010 '--eval-timeout=20', '--thread-count=1',
1011 '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue',
1012 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
1013 'cwd': '/var/spool/cwl',
1014 'runtime_constraints': {
1019 'use_existing': True,
1021 "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
1026 stubs.api.container_requests().create.assert_called_with(
1027 body=JsonDiffMatcher(expect_container))
1028 self.assertEqual(capture_stdout.getvalue(),
1029 stubs.expect_container_request_uuid + '\n')
1033 def test_submit_container_name(self, stubs):
1034 capture_stdout = io.StringIO()
1036 exited = arvados_cwl.main(
1037 ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123",
1038 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1039 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1040 self.assertEqual(exited, 0)
1042 logging.exception("")
1044 expect_container = copy.deepcopy(stubs.expect_container_spec)
1045 expect_container["name"] = "hello container 123"
1047 stubs.api.container_requests().create.assert_called_with(
1048 body=JsonDiffMatcher(expect_container))
1049 self.assertEqual(capture_stdout.getvalue(),
1050 stubs.expect_container_request_uuid + '\n')
1054 def test_submit_missing_input(self, stubs):
1055 capture_stdout = io.StringIO()
1056 exited = arvados_cwl.main(
1057 ["--submit", "--no-wait", "--api=containers", "--debug",
1058 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1059 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1060 self.assertEqual(exited, 0)
1062 capture_stdout = io.StringIO()
1063 exited = arvados_cwl.main(
1064 ["--submit", "--no-wait", "--api=containers", "--debug",
1065 "tests/wf/submit_wf.cwl", "tests/submit_test_job_missing.json"],
1066 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1067 self.assertEqual(exited, 1)
1071 def test_submit_container_project(self, stubs):
1072 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1073 capture_stdout = io.StringIO()
1075 exited = arvados_cwl.main(
1076 ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid,
1077 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1078 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1079 self.assertEqual(exited, 0)
1081 logging.exception("")
1083 expect_container = copy.deepcopy(stubs.expect_container_spec)
1084 expect_container["owner_uuid"] = project_uuid
1085 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1086 '--no-log-timestamps', '--disable-validate',
1087 "--eval-timeout=20", "--thread-count=1",
1088 '--enable-reuse', "--collection-cache-size=256", '--debug',
1089 '--on-error=continue',
1090 '--project-uuid='+project_uuid,
1091 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1093 stubs.api.container_requests().create.assert_called_with(
1094 body=JsonDiffMatcher(expect_container))
1095 self.assertEqual(capture_stdout.getvalue(),
1096 stubs.expect_container_request_uuid + '\n')
1099 def test_submit_container_eval_timeout(self, stubs):
1100 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1101 capture_stdout = io.StringIO()
1103 exited = arvados_cwl.main(
1104 ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60",
1105 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1106 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1107 self.assertEqual(exited, 0)
1109 logging.exception("")
1111 expect_container = copy.deepcopy(stubs.expect_container_spec)
1112 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1113 '--no-log-timestamps', '--disable-validate',
1114 '--eval-timeout=60.0', '--thread-count=1',
1115 '--enable-reuse', "--collection-cache-size=256",
1116 '--debug', '--on-error=continue',
1117 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1119 stubs.api.container_requests().create.assert_called_with(
1120 body=JsonDiffMatcher(expect_container))
1121 self.assertEqual(capture_stdout.getvalue(),
1122 stubs.expect_container_request_uuid + '\n')
1125 def test_submit_container_collection_cache(self, stubs):
1126 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1127 capture_stdout = io.StringIO()
1129 exited = arvados_cwl.main(
1130 ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500",
1131 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1132 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1133 self.assertEqual(exited, 0)
1135 logging.exception("")
1137 expect_container = copy.deepcopy(stubs.expect_container_spec)
1138 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1139 '--no-log-timestamps', '--disable-validate',
1140 '--eval-timeout=20', '--thread-count=1',
1141 '--enable-reuse', "--collection-cache-size=500",
1142 '--debug', '--on-error=continue',
1143 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1144 expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024
1146 stubs.api.container_requests().create.assert_called_with(
1147 body=JsonDiffMatcher(expect_container))
1148 self.assertEqual(capture_stdout.getvalue(),
1149 stubs.expect_container_request_uuid + '\n')
1153 def test_submit_container_thread_count(self, stubs):
1154 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1155 capture_stdout = io.StringIO()
1157 exited = arvados_cwl.main(
1158 ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20",
1159 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1160 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1161 self.assertEqual(exited, 0)
1163 logging.exception("")
1165 expect_container = copy.deepcopy(stubs.expect_container_spec)
1166 expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers',
1167 '--no-log-timestamps', '--disable-validate',
1168 '--eval-timeout=20', '--thread-count=20',
1169 '--enable-reuse', "--collection-cache-size=256",
1170 '--debug', '--on-error=continue',
1171 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1173 stubs.api.container_requests().create.assert_called_with(
1174 body=JsonDiffMatcher(expect_container))
1175 self.assertEqual(capture_stdout.getvalue(),
1176 stubs.expect_container_request_uuid + '\n')
1180 def test_submit_job_runner_image(self, stubs):
1181 capture_stdout = io.StringIO()
1183 exited = arvados_cwl.main(
1184 ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123",
1185 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1186 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1187 self.assertEqual(exited, 0)
1189 logging.exception("")
1191 stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99"
1193 expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
1194 stubs.api.pipeline_instances().create.assert_called_with(
1195 body=JsonDiffMatcher(expect_pipeline))
1196 self.assertEqual(capture_stdout.getvalue(),
1197 stubs.expect_pipeline_uuid + '\n')
1200 def test_submit_container_runner_image(self, stubs):
1201 capture_stdout = io.StringIO()
1203 exited = arvados_cwl.main(
1204 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123",
1205 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1206 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1207 self.assertEqual(exited, 0)
1209 logging.exception("")
1211 stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99"
1213 expect_container = copy.deepcopy(stubs.expect_container_spec)
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 def test_submit_priority(self, stubs):
1221 capture_stdout = io.StringIO()
1223 exited = arvados_cwl.main(
1224 ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669",
1225 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1226 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1227 self.assertEqual(exited, 0)
1229 logging.exception("")
1231 stubs.expect_container_spec["priority"] = 669
1233 expect_container = copy.deepcopy(stubs.expect_container_spec)
1234 stubs.api.container_requests().create.assert_called_with(
1235 body=JsonDiffMatcher(expect_container))
1236 self.assertEqual(capture_stdout.getvalue(),
1237 stubs.expect_container_request_uuid + '\n')
1241 def test_submit_wf_runner_resources(self, stubs):
1242 capture_stdout = io.StringIO()
1244 exited = arvados_cwl.main(
1245 ["--submit", "--no-wait", "--api=containers", "--debug",
1246 "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"],
1247 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1248 self.assertEqual(exited, 0)
1250 logging.exception("")
1252 expect_container = copy.deepcopy(stubs.expect_container_spec)
1253 expect_container["runtime_constraints"] = {
1256 "ram": (2000+512) * 2**20
1258 expect_container["name"] = "submit_wf_runner_resources.cwl"
1259 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [
1261 "class": "http://arvados.org/cwl#WorkflowRunnerResources",
1267 expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = {
1268 "arv": "http://arvados.org/cwl#",
1270 expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers',
1271 '--no-log-timestamps', '--disable-validate',
1272 '--eval-timeout=20', '--thread-count=1',
1273 '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue',
1274 '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json']
1276 stubs.api.container_requests().create.assert_called_with(
1277 body=JsonDiffMatcher(expect_container))
1278 self.assertEqual(capture_stdout.getvalue(),
1279 stubs.expect_container_request_uuid + '\n')
1282 arvados_cwl.arvdocker.arv_docker_clear_cache()
1284 @mock.patch("arvados.commands.keepdocker.find_one_image_hash")
1285 @mock.patch("cwltool.docker.DockerCommandLineJob.get_image")
1286 @mock.patch("arvados.api")
1287 def test_arvados_jobs_image(self, api, get_image, find_one_image_hash):
1288 arvados_cwl.arvdocker.arv_docker_clear_cache()
1290 arvrunner = mock.MagicMock()
1291 arvrunner.project_uuid = ""
1292 api.return_value = mock.MagicMock()
1293 arvrunner.api = api.return_value
1294 arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "",
1295 "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1296 "link_class": "docker_image_repo+tag",
1297 "name": "arvados/jobs:"+arvados_cwl.__version__,
1299 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0},
1300 {"items": [{"created_at": "",
1302 "link_class": "docker_image_hash",
1305 "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}
1307 find_one_image_hash.return_value = "123456"
1309 arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1311 "manifest_text": "",
1313 }], "items_available": 1, "offset": 0},)
1314 arvrunner.api.collections().create().execute.return_value = {"uuid": ""}
1315 arvrunner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb",
1316 "portable_data_hash": "9999999999999999999999999999999b+99"}
1317 self.assertEqual("9999999999999999999999999999999b+99",
1318 arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__))
1322 def test_submit_secrets(self, stubs):
1323 capture_stdout = io.StringIO()
1325 exited = arvados_cwl.main(
1326 ["--submit", "--no-wait", "--api=containers", "--debug",
1327 "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"],
1328 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1329 self.assertEqual(exited, 0)
1331 logging.exception("")
1334 expect_container = {
1336 "arvados-cwl-runner",
1339 "--no-log-timestamps",
1340 "--disable-validate",
1341 "--eval-timeout=20",
1344 "--collection-cache-size=256",
1346 "--on-error=continue",
1347 "/var/lib/cwl/workflow.json#main",
1348 "/var/lib/cwl/cwl.input.json"
1350 "container_image": "999999999999999999999999999999d3+99",
1351 "cwd": "/var/spool/cwl",
1353 "/var/lib/cwl/cwl.input.json": {
1356 "$include": "/secrets/s0"
1361 "/var/lib/cwl/workflow.json": {
1366 "cwltool": "http://commonwl.org/cwltool#"
1372 "class": "CommandLineTool",
1375 "class": "http://commonwl.org/cwltool#Secrets",
1377 "#secret_job.cwl/pw"
1381 "id": "#secret_job.cwl",
1384 "id": "#secret_job.cwl/pw",
1390 "id": "#secret_job.cwl/out",
1394 "stdout": "hashed_example.txt",
1397 "class": "InitialWorkDirRequirement",
1400 "entry": "username: user\npassword: $(inputs.pw)\n",
1401 "entryname": "example.conf"
1408 "class": "Workflow",
1411 "class": "DockerRequirement",
1412 "dockerPull": "debian:8",
1413 "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99"
1416 "class": "http://commonwl.org/cwltool#Secrets",
1432 "outputSource": "#main/step1/out",
1438 "id": "#main/step1",
1441 "id": "#main/step1/pw",
1442 "source": "#main/pw"
1448 "run": "#secret_job.cwl"
1453 "cwlVersion": "v1.0"
1458 "kind": "collection",
1463 "path": "/var/spool/cwl/cwl.output.json"
1466 "name": "secret_wf.cwl",
1467 "output_path": "/var/spool/cwl",
1470 "runtime_constraints": {
1481 "state": "Committed",
1482 "use_existing": True
1485 stubs.api.container_requests().create.assert_called_with(
1486 body=JsonDiffMatcher(expect_container))
1487 self.assertEqual(capture_stdout.getvalue(),
1488 stubs.expect_container_request_uuid + '\n')
1491 def test_submit_request_uuid(self, stubs):
1492 stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy"
1494 stubs.api.container_requests().update().execute.return_value = {
1495 "uuid": stubs.expect_container_request_uuid,
1496 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
1500 capture_stdout = io.StringIO()
1502 exited = arvados_cwl.main(
1503 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy",
1504 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1505 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1506 self.assertEqual(exited, 0)
1508 logging.exception("")
1510 stubs.api.container_requests().update.assert_called_with(
1511 uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz")
1512 self.assertEqual(capture_stdout.getvalue(),
1513 stubs.expect_container_request_uuid + '\n')
1516 def test_submit_container_cluster_id(self, stubs):
1517 capture_stdout = io.StringIO()
1518 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1520 exited = arvados_cwl.main(
1521 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb",
1522 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1523 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1524 self.assertEqual(exited, 0)
1526 logging.exception("")
1528 expect_container = copy.deepcopy(stubs.expect_container_spec)
1530 stubs.api.container_requests().create.assert_called_with(
1531 body=JsonDiffMatcher(expect_container), cluster_id="zbbbb")
1532 self.assertEqual(capture_stdout.getvalue(),
1533 stubs.expect_container_request_uuid + '\n')
1537 def test_submit_validate_cluster_id(self, stubs):
1538 capture_stdout = io.StringIO()
1539 stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123"
1540 exited = arvados_cwl.main(
1541 ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc",
1542 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1543 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
1544 self.assertEqual(exited, 1)
1547 class TestCreateTemplate(unittest.TestCase):
1548 existing_template_uuid = "zzzzz-d1hrv-validworkfloyml"
1550 def _adjust_script_params(self, expect_component):
1551 expect_component['script_parameters']['x'] = {
1552 'dataclass': 'File',
1555 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt',
1557 expect_component['script_parameters']['y'] = {
1558 'dataclass': 'Collection',
1560 'type': 'Directory',
1561 'value': '99999999999999999999999999999998+99',
1563 expect_component['script_parameters']['z'] = {
1564 'dataclass': 'Collection',
1566 'type': 'Directory',
1570 def test_create(self, stubs):
1571 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1573 capture_stdout = io.StringIO()
1575 exited = arvados_cwl.main(
1576 ["--create-workflow", "--debug",
1578 "--project-uuid", project_uuid,
1579 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1580 capture_stdout, sys.stderr, api_client=stubs.api)
1581 self.assertEqual(exited, 0)
1583 stubs.api.pipeline_instances().create.refute_called()
1584 stubs.api.jobs().create.refute_called()
1586 expect_component = copy.deepcopy(stubs.expect_job_spec)
1587 self._adjust_script_params(expect_component)
1590 "submit_wf.cwl": expect_component,
1592 "name": "submit_wf.cwl",
1593 "owner_uuid": project_uuid,
1595 stubs.api.pipeline_templates().create.assert_called_with(
1596 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1598 self.assertEqual(capture_stdout.getvalue(),
1599 stubs.expect_pipeline_template_uuid + '\n')
1603 def test_create_name(self, stubs):
1604 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1606 capture_stdout = io.StringIO()
1608 exited = arvados_cwl.main(
1609 ["--create-workflow", "--debug",
1610 "--project-uuid", project_uuid,
1612 "--name", "testing 123",
1613 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1614 capture_stdout, sys.stderr, api_client=stubs.api)
1615 self.assertEqual(exited, 0)
1617 stubs.api.pipeline_instances().create.refute_called()
1618 stubs.api.jobs().create.refute_called()
1620 expect_component = copy.deepcopy(stubs.expect_job_spec)
1621 self._adjust_script_params(expect_component)
1624 "testing 123": expect_component,
1626 "name": "testing 123",
1627 "owner_uuid": project_uuid,
1629 stubs.api.pipeline_templates().create.assert_called_with(
1630 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
1632 self.assertEqual(capture_stdout.getvalue(),
1633 stubs.expect_pipeline_template_uuid + '\n')
1637 def test_update_name(self, stubs):
1638 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1640 capture_stdout = io.StringIO()
1642 exited = arvados_cwl.main(
1643 ["--update-workflow", self.existing_template_uuid,
1645 "--project-uuid", project_uuid,
1647 "--name", "testing 123",
1648 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1649 capture_stdout, sys.stderr, api_client=stubs.api)
1650 self.assertEqual(exited, 0)
1652 stubs.api.pipeline_instances().create.refute_called()
1653 stubs.api.jobs().create.refute_called()
1655 expect_component = copy.deepcopy(stubs.expect_job_spec)
1656 self._adjust_script_params(expect_component)
1659 "testing 123": expect_component,
1661 "name": "testing 123",
1662 "owner_uuid": project_uuid,
1664 stubs.api.pipeline_templates().create.refute_called()
1665 stubs.api.pipeline_templates().update.assert_called_with(
1666 body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)
1668 self.assertEqual(capture_stdout.getvalue(),
1669 self.existing_template_uuid + '\n')
1672 class TestCreateWorkflow(unittest.TestCase):
1673 existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml"
1674 expect_workflow = StripYAMLComments(
1675 open("tests/wf/expect_packed.cwl").read())
1678 def test_create(self, stubs):
1679 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1681 capture_stdout = io.StringIO()
1683 exited = arvados_cwl.main(
1684 ["--create-workflow", "--debug",
1686 "--project-uuid", project_uuid,
1687 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1688 capture_stdout, sys.stderr, api_client=stubs.api)
1689 self.assertEqual(exited, 0)
1691 stubs.api.pipeline_templates().create.refute_called()
1692 stubs.api.container_requests().create.refute_called()
1696 "owner_uuid": project_uuid,
1697 "name": "submit_wf.cwl",
1699 "definition": self.expect_workflow,
1702 stubs.api.workflows().create.assert_called_with(
1703 body=JsonDiffMatcher(body))
1705 self.assertEqual(capture_stdout.getvalue(),
1706 stubs.expect_workflow_uuid + '\n')
1710 def test_create_name(self, stubs):
1711 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1713 capture_stdout = io.StringIO()
1715 exited = arvados_cwl.main(
1716 ["--create-workflow", "--debug",
1718 "--project-uuid", project_uuid,
1719 "--name", "testing 123",
1720 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1721 capture_stdout, sys.stderr, api_client=stubs.api)
1722 self.assertEqual(exited, 0)
1724 stubs.api.pipeline_templates().create.refute_called()
1725 stubs.api.container_requests().create.refute_called()
1729 "owner_uuid": project_uuid,
1730 "name": "testing 123",
1732 "definition": self.expect_workflow,
1735 stubs.api.workflows().create.assert_called_with(
1736 body=JsonDiffMatcher(body))
1738 self.assertEqual(capture_stdout.getvalue(),
1739 stubs.expect_workflow_uuid + '\n')
1742 def test_incompatible_api(self, stubs):
1743 capture_stderr = io.StringIO()
1744 logging.getLogger('arvados.cwl-runner').addHandler(
1745 logging.StreamHandler(capture_stderr))
1747 exited = arvados_cwl.main(
1748 ["--update-workflow", self.existing_workflow_uuid,
1751 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1752 sys.stderr, sys.stderr, api_client=stubs.api)
1753 self.assertEqual(exited, 1)
1754 self.assertRegexpMatches(
1755 capture_stderr.getvalue(),
1756 "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid))
1759 def test_update(self, stubs):
1760 capture_stdout = io.StringIO()
1762 exited = arvados_cwl.main(
1763 ["--update-workflow", self.existing_workflow_uuid,
1765 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1766 capture_stdout, sys.stderr, api_client=stubs.api)
1767 self.assertEqual(exited, 0)
1771 "name": "submit_wf.cwl",
1773 "definition": self.expect_workflow,
1776 stubs.api.workflows().update.assert_called_with(
1777 uuid=self.existing_workflow_uuid,
1778 body=JsonDiffMatcher(body))
1779 self.assertEqual(capture_stdout.getvalue(),
1780 self.existing_workflow_uuid + '\n')
1784 def test_update_name(self, stubs):
1785 capture_stdout = io.StringIO()
1787 exited = arvados_cwl.main(
1788 ["--update-workflow", self.existing_workflow_uuid,
1789 "--debug", "--name", "testing 123",
1790 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
1791 capture_stdout, sys.stderr, api_client=stubs.api)
1792 self.assertEqual(exited, 0)
1796 "name": "testing 123",
1798 "definition": self.expect_workflow,
1801 stubs.api.workflows().update.assert_called_with(
1802 uuid=self.existing_workflow_uuid,
1803 body=JsonDiffMatcher(body))
1804 self.assertEqual(capture_stdout.getvalue(),
1805 self.existing_workflow_uuid + '\n')
1809 def test_create_collection_per_tool(self, stubs):
1810 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
1812 capture_stdout = io.StringIO()
1814 exited = arvados_cwl.main(
1815 ["--create-workflow", "--debug",
1817 "--project-uuid", project_uuid,
1818 "tests/collection_per_tool/collection_per_tool.cwl"],
1819 capture_stdout, sys.stderr, api_client=stubs.api)
1820 self.assertEqual(exited, 0)
1822 toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl"
1823 expect_workflow = StripYAMLComments(open(toolfile).read())
1827 "owner_uuid": project_uuid,
1828 "name": "collection_per_tool.cwl",
1830 "definition": expect_workflow,
1833 stubs.api.workflows().create.assert_called_with(
1834 body=JsonDiffMatcher(body))
1836 self.assertEqual(capture_stdout.getvalue(),
1837 stubs.expect_workflow_uuid + '\n')
1839 class TestTemplateInputs(unittest.TestCase):
1842 "inputs_test.cwl": {
1843 'runtime_constraints': {
1844 'docker_image': '999999999999999999999999999999d3+99',
1845 'min_ram_mb_per_node': 1024
1847 'script_parameters': {
1849 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main',
1850 'optionalFloatInput': None,
1853 'dataclass': 'File',
1855 'title': "It's a file; we expect to find some characters in it.",
1856 'description': 'If there were anything further to say, it would be said here,\nor here.'
1860 'dataclass': 'number',
1862 'title': 'Floats like a duck',
1866 'optionalFloatInput': {
1867 'type': ['null', 'float'],
1868 'dataclass': 'number',
1873 'dataclass': 'boolean',
1875 'title': 'True or false?',
1878 'repository': 'arvados',
1879 'script_version': 'master',
1880 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9',
1881 'script': 'cwl-runner',
1884 "name": "inputs_test.cwl",
1888 def test_inputs_empty(self, stubs):
1889 exited = arvados_cwl.main(
1890 ["--create-template",
1891 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
1892 io.StringIO(), sys.stderr, api_client=stubs.api)
1893 self.assertEqual(exited, 0)
1895 stubs.api.pipeline_templates().create.assert_called_with(
1896 body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
1899 def test_inputs(self, stubs):
1900 exited = arvados_cwl.main(
1901 ["--create-template",
1902 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
1903 io.StringIO(), sys.stderr, api_client=stubs.api)
1904 self.assertEqual(exited, 0)
1906 expect_template = copy.deepcopy(self.expect_template)
1907 params = expect_template[
1908 "components"]["inputs_test.cwl"]["script_parameters"]
1909 params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt'
1910 params["cwl:tool"] = 'a2de777156fb700f1363b1f2e370adca+60/workflow.cwl#main'
1911 params["floatInput"]["value"] = 1.234
1912 params["boolInput"]["value"] = True
1914 stubs.api.pipeline_templates().create.assert_called_with(
1915 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)