X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/79b826befbc0b62a822e2d0c922e5c4ea0a3bb7c..98911cfe4792b20798858cefb353c451460e1a80:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index 112f432579..77bef075fa 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + import copy import cStringIO import functools @@ -14,7 +18,7 @@ import arvados_cwl import arvados_cwl.runner import arvados.keep -from .matcher import JsonDiffMatcher +from .matcher import JsonDiffMatcher, StripYAMLComments from .mock_discovery import get_rootDesc import ruamel.yaml as yaml @@ -34,7 +38,6 @@ def stubs(func): stubs.events = events stubs.keepdocker = keepdocker - def putstub(p, **kwargs): return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p)) keep_client1().put.side_effect = putstub @@ -53,33 +56,43 @@ def stubs(func): "uuid": stubs.fake_user_uuid, } stubs.api.collections().list().execute.return_value = {"items": []} - stubs.api.collections().create().execute.side_effect = ({ - "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1", - "portable_data_hash": "99999999999999999999999999999991+99", - "manifest_text": "" - }, { - "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2", - "portable_data_hash": "99999999999999999999999999999992+99", - "manifest_text": "./tool 00000000000000000000000000000000+0 0:0:submit_tool.cwl 0:0:blub.txt" - }, - { - "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz4", - "portable_data_hash": "99999999999999999999999999999994+99", - "manifest_text": "" - }, - { - "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz5", - "portable_data_hash": "99999999999999999999999999999995+99", - "manifest_text": "" - }, - { - "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz6", - "portable_data_hash": "99999999999999999999999999999996+99", - "manifest_text": "" + + class CollectionExecute(object): + def __init__(self, exe): + self.exe = exe + def execute(self, num_retries=None): + return self.exe + + def collection_createstub(created_collections, body, ensure_unique_name=None): + mt = body["manifest_text"] + uuid = "zzzzz-4zz18-zzzzzzzzzzzzzz%d" % len(created_collections) + pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt)) + created_collections[uuid] = { + "uuid": uuid, + "portable_data_hash": pdh, + "manifest_text": mt + } + return CollectionExecute(created_collections[uuid]) + + def collection_getstub(created_collections, uuid): + for v in created_collections.itervalues(): + if uuid in (v["uuid"], v["portable_data_hash"]): + return CollectionExecute(v) + + created_collections = { + "99999999999999999999999999999998+99": { + "uuid": "", + "portable_data_hash": "99999999999999999999999999999998+99", + "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt" + }, + "99999999999999999999999999999994+99": { + "uuid": "", + "portable_data_hash": "99999999999999999999999999999994+99", + "manifest_text": ". 99999999999999999999999999999994+99 0:0:expect_arvworkflow.cwl" + } } - ) - stubs.api.collections().get().execute.return_value = { - "portable_data_hash": "99999999999999999999999999999993+99", "manifest_text": "./tool 00000000000000000000000000000000+0 0:0:submit_tool.cwl 0:0:blub.txt"} + stubs.api.collections().create.side_effect = functools.partial(collection_createstub, created_collections) + stubs.api.collections().get.side_effect = functools.partial(collection_getstub, created_collections) stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" stubs.api.jobs().create().execute.return_value = { @@ -106,7 +119,7 @@ def stubs(func): 'script_parameters': { 'x': { 'basename': 'blorp.txt', - 'location': 'keep:99999999999999999999999999999992+99/blorp.txt', + 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt', 'class': 'File' }, 'y': { @@ -123,8 +136,7 @@ def stubs(func): }], 'class': 'Directory' }, - 'cwl:tool': - '99999999999999999999999999999994+99/workflow.cwl#main' + 'cwl:tool': '3fffdeaa75e018172e1b583425f4ebff+60/workflow.cwl#main' }, 'repository': 'arvados', 'script_version': 'master', @@ -141,12 +153,22 @@ def stubs(func): 'runtime_constraints': {'docker_image': 'arvados/jobs:'+arvados_cwl.__version__, 'min_ram_mb_per_node': 1024}, 'script_parameters': { 'y': {"value": {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}}, - 'x': {"value": {'basename': 'blorp.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999992+99/blorp.txt'}}, + 'x': {"value": { + 'basename': 'blorp.txt', + 'class': 'File', + 'location': 'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt', + "size": 16 + }}, 'z': {"value": {'basename': 'anonymous', 'class': 'Directory', 'listing': [ - {'basename': 'renamed.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999998+99/file1.txt'} + { + 'basename': 'renamed.txt', + 'class': 'File', 'location': + 'keep:99999999999999999999999999999998+99/file1.txt' + } ]}}, - 'cwl:tool': '99999999999999999999999999999994+99/workflow.cwl#main', + 'cwl:tool': '3fffdeaa75e018172e1b583425f4ebff+60/workflow.cwl#main', + 'arv:debug': True, 'arv:enable_reuse': True, 'arv:on_error': 'continue' }, @@ -173,7 +195,7 @@ def stubs(func): expect_packed_workflow = yaml.round_trip_load(f) stubs.expect_container_spec = { - 'priority': 1, + 'priority': 500, 'mounts': { '/var/spool/cwl': { 'writable': True, @@ -190,19 +212,33 @@ def stubs(func): '/var/lib/cwl/cwl.input.json': { 'kind': 'json', 'content': { - 'y': {'basename': '99999999999999999999999999999998+99', 'location': 'keep:99999999999999999999999999999998+99', 'class': 'Directory'}, - 'x': {'basename': u'blorp.txt', 'class': 'File', 'location': u'keep:99999999999999999999999999999992+99/blorp.txt'}, + 'y': { + 'basename': '99999999999999999999999999999998+99', + 'location': 'keep:99999999999999999999999999999998+99', + 'class': 'Directory'}, + 'x': { + 'basename': u'blorp.txt', + 'class': 'File', + 'location': u'keep:169f39d466a5438ac4a90e779bf750c7+53/blorp.txt', + "size": 16 + }, 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [ - {'basename': 'renamed.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999998+99/file1.txt'} + {'basename': 'renamed.txt', + 'class': 'File', + 'location': 'keep:99999999999999999999999999999998+99/file1.txt' + } ]} }, 'kind': 'json' } }, + 'secret_mounts': {}, 'state': 'Committed', 'owner_uuid': None, - 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=continue', + 'command': ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], 'name': 'submit_wf.cwl', 'container_image': 'arvados/jobs:'+arvados_cwl.__version__, @@ -213,7 +249,9 @@ def stubs(func): 'vcpus': 1, 'ram': 1024*1024*1024 }, - "properties": {} + 'use_existing': True, + 'properties': {}, + 'secret_mounts': {} } stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz" @@ -245,21 +283,24 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) stubs.api.collections().create.assert_has_calls([ - mock.call(), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n', 'replication_desired': None, 'name': 'submit_tool.cwl dependencies', }), ensure_unique_name=True), - mock.call().execute(num_retries=4), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n', 'replication_desired': None, 'name': 'submit_wf.cwl input', }), ensure_unique_name=True), - mock.call().execute(num_retries=4)]) + mock.call(body=JsonDiffMatcher({ + 'manifest_text': + '. 61df2ed9ee3eb7dd9b799e5ca35305fa+1217 0:1217:workflow.cwl\n', + 'replication_desired': None, + 'name': 'submit_wf.cwl', + }), ensure_unique_name=True) ]) arvdock.assert_has_calls([ mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None), @@ -285,6 +326,7 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False} + expect_pipeline["properties"] = {"run_options": {"enable_job_reuse": False}} stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) @@ -404,7 +446,7 @@ class TestSubmit(unittest.TestCase): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' exited = arvados_cwl.main( - ["--submit", "--no-wait", + ["--submit", "--no-wait", "--debug", "--project-uuid", project_uuid, "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], sys.stdout, sys.stderr, api_client=stubs.api) @@ -428,21 +470,18 @@ class TestSubmit(unittest.TestCase): logging.exception("") stubs.api.collections().create.assert_has_calls([ - mock.call(), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n', 'replication_desired': None, 'name': 'submit_tool.cwl dependencies', }), ensure_unique_name=True), - mock.call().execute(num_retries=4), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n', 'replication_desired': None, 'name': 'submit_wf.cwl input', - }), ensure_unique_name=True), - mock.call().execute(num_retries=4)]) + }), ensure_unique_name=True)]) expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( @@ -463,9 +502,49 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--disable-reuse', '--on-error=continue', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = [ + 'arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--disable-reuse', '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["use_existing"] = False + + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + + @stubs + def test_submit_container_reuse_disabled_by_workflow(self, stubs): + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["command"] = [ + 'arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--disable-reuse', '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["use_existing"] = False + expect_container["name"] = "submit_wf_no_reuse.cwl" + expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [ + { + "class": "http://arvados.org/cwl#ReuseRequirement", + "enableReuse": False, + }, + ] + expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][0]["$namespaces"] = { + "arv": "http://arvados.org/cwl#", + "cwltool": "http://commonwl.org/cwltool#" + } stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -486,9 +565,11 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=stop', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=stop', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -510,9 +591,12 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - "--output-name="+output_name, '--enable-reuse', '--on-error=continue', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', + "--output-name="+output_name, '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] expect_container["output_name"] = output_name stubs.api.container_requests().create.assert_called_with( @@ -534,8 +618,10 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=continue', + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', "--intermediate-output-ttl=3600", '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -557,8 +643,10 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=continue', + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', "--trash-intermediate", '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -582,9 +670,12 @@ class TestSubmit(unittest.TestCase): logging.exception("") expect_container = copy.deepcopy(stubs.expect_container_spec) - expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - "--output-tags="+output_tags, '--enable-reuse', '--on-error=continue', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', + "--output-tags="+output_tags, '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -639,7 +730,7 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) expect_container = { - 'priority': 1, + 'priority': 500, 'mounts': { '/var/spool/cwl': { 'writable': True, @@ -664,8 +755,10 @@ class TestSubmit(unittest.TestCase): 'output_path': '/var/spool/cwl', 'name': 'expect_arvworkflow.cwl#main', 'container_image': 'arvados/jobs:'+arvados_cwl.__version__, - 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=continue', + 'command': ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'], 'cwd': '/var/spool/cwl', 'runtime_constraints': { @@ -673,7 +766,9 @@ class TestSubmit(unittest.TestCase): 'vcpus': 1, 'ram': 1073741824 }, - "properties": {} + 'use_existing': True, + 'properties': {}, + 'secret_mounts': {} } stubs.api.container_requests().create.assert_called_with( @@ -721,7 +816,7 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) expect_container = { - 'priority': 1, + 'priority': 500, 'mounts': { '/var/spool/cwl': { 'writable': True, @@ -779,8 +874,10 @@ class TestSubmit(unittest.TestCase): 'output_path': '/var/spool/cwl', 'name': 'a test workflow', 'container_image': 'arvados/jobs:'+arvados_cwl.__version__, - 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', - '--enable-reuse', '--on-error=continue', + 'command': ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], 'cwd': '/var/spool/cwl', 'runtime_constraints': { @@ -788,9 +885,11 @@ class TestSubmit(unittest.TestCase): 'vcpus': 1, 'ram': 1073741824 }, - "properties": { + 'use_existing': True, + 'properties': { "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37" - } + }, + 'secret_mounts': {} } stubs.api.container_requests().create.assert_called_with( @@ -820,6 +919,85 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') + @stubs + def test_submit_container_project(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid, + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + except: + logging.exception("") + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["owner_uuid"] = project_uuid + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + "--eval-timeout=20", "--thread-count=4", + '--enable-reuse', '--debug', '--on-error=continue', + '--project-uuid='+project_uuid, + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + @stubs + def test_submit_container_eval_timeout(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + except: + logging.exception("") + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=60.0', '--thread-count=4', + '--enable-reuse', '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + + @stubs + def test_submit_container_thread_count(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + except: + logging.exception("") + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', + '--eval-timeout=20', '--thread-count=20', + '--enable-reuse', '--debug', '--on-error=continue', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + @stubs def test_submit_job_runner_image(self, stubs): capture_stdout = cStringIO.StringIO() @@ -860,9 +1038,29 @@ class TestSubmit(unittest.TestCase): self.assertEqual(capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + @stubs + def test_submit_priority(self, stubs): + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + except: + logging.exception("") + + stubs.expect_container_spec["priority"] = 669 + + expect_container = copy.deepcopy(stubs.expect_container_spec) + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + @mock.patch("arvados.commands.keepdocker.find_one_image_hash") - @mock.patch("cwltool.docker.get_image") + @mock.patch("cwltool.docker.DockerCommandLineJob.get_image") @mock.patch("arvados.api") def test_arvados_jobs_image(self, api, get_image, find_one_image_hash): arvrunner = mock.MagicMock() @@ -893,6 +1091,175 @@ class TestSubmit(unittest.TestCase): self.assertEqual("arvados/jobs:"+arvados_cwl.__version__, arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__)) + @stubs + def test_submit_secrets(self, stubs): + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"], + capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + except: + logging.exception("") + + + expect_container = { + "command": [ + "arvados-cwl-runner", + "--local", + "--api=containers", + "--no-log-timestamps", + "--disable-validate", + "--eval-timeout=20", + '--thread-count=4', + "--enable-reuse", + '--debug', + "--on-error=continue", + "/var/lib/cwl/workflow.json#main", + "/var/lib/cwl/cwl.input.json" + ], + "container_image": "arvados/jobs:"+arvados_cwl.__version__, + "cwd": "/var/spool/cwl", + "mounts": { + "/var/lib/cwl/cwl.input.json": { + "content": { + "pw": { + "$include": "/secrets/s0" + } + }, + "kind": "json" + }, + "/var/lib/cwl/workflow.json": { + "content": { + "$graph": [ + { + "$namespaces": { + "cwltool": "http://commonwl.org/cwltool#" + }, + "arguments": [ + "md5sum", + "example.conf" + ], + "class": "CommandLineTool", + "hints": [ + { + "class": "http://commonwl.org/cwltool#Secrets", + "secrets": [ + "#secret_job.cwl/pw" + ] + } + ], + "id": "#secret_job.cwl", + "inputs": [ + { + "id": "#secret_job.cwl/pw", + "type": "string" + } + ], + "outputs": [ + { + "id": "#secret_job.cwl/out", + "type": "stdout" + } + ], + "stdout": "hashed_example.txt", + "requirements": [ + { + "class": "InitialWorkDirRequirement", + "listing": [ + { + "entry": "username: user\npassword: $(inputs.pw)\n", + "entryname": "example.conf" + } + ] + } + ] + }, + { + "class": "Workflow", + "hints": [ + { + "class": "DockerRequirement", + "dockerPull": "debian:8" + }, + { + "class": "http://commonwl.org/cwltool#Secrets", + "secrets": [ + "#main/pw" + ] + } + ], + "id": "#main", + "inputs": [ + { + "id": "#main/pw", + "type": "string" + } + ], + "outputs": [ + { + "id": "#main/out", + "outputSource": "#main/step1/out", + "type": "File" + } + ], + "steps": [ + { + "id": "#main/step1", + "in": [ + { + "id": "#main/step1/pw", + "source": "#main/pw" + } + ], + "out": [ + "#main/step1/out" + ], + "run": "#secret_job.cwl" + } + ] + } + ], + "cwlVersion": "v1.0" + }, + "kind": "json" + }, + "/var/spool/cwl": { + "kind": "collection", + "writable": True + }, + "stdout": { + "kind": "file", + "path": "/var/spool/cwl/cwl.output.json" + } + }, + "name": "secret_wf.cwl", + "output_path": "/var/spool/cwl", + "owner_uuid": None, + "priority": 500, + "properties": {}, + "runtime_constraints": { + "API": True, + "ram": 1073741824, + "vcpus": 1 + }, + "secret_mounts": { + "/secrets/s0": { + "content": "blorp", + "kind": "text" + } + }, + "state": "Committed", + "use_existing": True + } + + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + class TestCreateTemplate(unittest.TestCase): existing_template_uuid = "zzzzz-d1hrv-validworkfloyml" @@ -901,7 +1268,7 @@ class TestCreateTemplate(unittest.TestCase): 'dataclass': 'File', 'required': True, 'type': 'File', - 'value': '99999999999999999999999999999992+99/blorp.txt', + 'value': '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt', } expect_component['script_parameters']['y'] = { 'dataclass': 'Collection', @@ -1020,7 +1387,8 @@ class TestCreateTemplate(unittest.TestCase): class TestCreateWorkflow(unittest.TestCase): existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml" - expect_workflow = open("tests/wf/expect_packed.cwl").read() + expect_workflow = StripYAMLComments( + open("tests/wf/expect_packed.cwl").read()) @stubs def test_create(self, stubs): @@ -1153,6 +1521,37 @@ class TestCreateWorkflow(unittest.TestCase): self.existing_workflow_uuid + '\n') + @stubs + def test_create_collection_per_tool(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--create-workflow", "--debug", + "--api=containers", + "--project-uuid", project_uuid, + "tests/collection_per_tool/collection_per_tool.cwl"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl" + expect_workflow = StripYAMLComments(open(toolfile).read()) + + body = { + "workflow": { + "owner_uuid": project_uuid, + "name": "collection_per_tool.cwl", + "description": "", + "definition": expect_workflow, + } + } + stubs.api.workflows().create.assert_called_with( + body=JsonDiffMatcher(body)) + + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_workflow_uuid + '\n') + class TestTemplateInputs(unittest.TestCase): expect_template = { "components": { @@ -1163,7 +1562,7 @@ class TestTemplateInputs(unittest.TestCase): }, 'script_parameters': { 'cwl:tool': - '99999999999999999999999999999992+99/workflow.cwl#main', + '6c5ee1cd606088106d9f28367cde1e41+60/workflow.cwl#main', 'optionalFloatInput': None, 'fileInput': { 'type': 'File', @@ -1223,8 +1622,8 @@ class TestTemplateInputs(unittest.TestCase): expect_template = copy.deepcopy(self.expect_template) params = expect_template[ "components"]["inputs_test.cwl"]["script_parameters"] - params["fileInput"]["value"] = '99999999999999999999999999999992+99/blorp.txt' - params["cwl:tool"] = '99999999999999999999999999999994+99/workflow.cwl#main' + params["fileInput"]["value"] = '169f39d466a5438ac4a90e779bf750c7+53/blorp.txt' + params["cwl:tool"] = '6c5ee1cd606088106d9f28367cde1e41+60/workflow.cwl#main' params["floatInput"]["value"] = 1.234 params["boolInput"]["value"] = True