X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/bdb92619b5f6d920119b8c32c3027cf4b751ed16..83a0c3c06e3d6c58da44cd433573b732c59f3beb:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index d917aef57a..0ee90c8c74 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -125,7 +125,8 @@ def stubs(func): '99999999999999999999999999999991+99/wf/submit_wf.cwl' }, 'repository': 'arvados', - 'script_version': arvados_cwl.__version__, + 'script_version': 'master', + 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9', 'script': 'cwl-runner' } stubs.pipeline_component = stubs.expect_job_spec.copy() @@ -144,10 +145,12 @@ def stubs(func): {'basename': 'renamed.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999998+99/file1.txt'} ]}}, 'cwl:tool': '99999999999999999999999999999991+99/wf/submit_wf.cwl', - 'arv:enable_reuse': True + 'arv:enable_reuse': True, + 'arv:on_error': 'continue' }, 'repository': 'arvados', - 'script_version': arvados_cwl.__version__, + 'script_version': 'master', + 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9', 'script': 'cwl-runner', 'job': {'state': 'Queued', 'uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'} } @@ -179,14 +182,23 @@ def stubs(func): 'path': '/var/spool/cwl/cwl.output.json', 'kind': 'file' }, - '/var/lib/cwl/job/cwl.input.json': { - 'portable_data_hash': 'd20d7cddd1984f105dd3702c7f125afb+60/cwl.input.json', - 'kind': 'collection' + '/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:99999999999999999999999999999994+99/blorp.txt'}, + 'z': {'basename': 'anonymous', 'class': 'Directory', 'listing': [ + {'basename': 'renamed.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999998+99/file1.txt'} + ]} + }, + 'kind': 'json' } }, 'state': 'Committed', 'owner_uuid': None, - 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--enable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/job/cwl.input.json'], + 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + '--enable-reuse', '--on-error=continue', + '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json'], 'name': 'submit_wf.cwl', 'container_image': 'arvados/jobs:'+arvados_cwl.__version__, 'output_path': '/var/spool/cwl', @@ -195,7 +207,8 @@ def stubs(func): 'API': True, 'vcpus': 1, 'ram': 1024*1024*1024 - } + }, + "properties": {} } stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz" @@ -271,7 +284,25 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( - body=expect_pipeline) + body=JsonDiffMatcher(expect_pipeline)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_pipeline_uuid + '\n') + + @mock.patch("time.sleep") + @stubs + def test_submit_on_error(self, stubs, tm): + capture_stdout = cStringIO.StringIO() + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--debug", "--on-error=stop", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop" + + expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) + stubs.api.pipeline_instances().create.assert_called_with( + body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @@ -290,7 +321,7 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( - body=expect_pipeline) + body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @@ -321,7 +352,7 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( - body=expect_pipeline) + body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @@ -360,7 +391,7 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( - body=expect_pipeline) + body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @@ -379,7 +410,7 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["owner_uuid"] = project_uuid stubs.api.pipeline_instances().create.assert_called_with( - body=expect_pipeline) + body=JsonDiffMatcher(expect_pipeline)) @stubs def test_submit_container(self, stubs): @@ -420,7 +451,7 @@ class TestSubmit(unittest.TestCase): expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( - body=expect_container) + body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') @@ -436,11 +467,36 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--disable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/job/cwl.input.json'] + stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + '--disable-reuse', '--on-error=continue', + '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json'] expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( - body=expect_container) + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + + @stubs + def test_submit_container_on_error(self, stubs): + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop", + "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["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + '--enable-reuse', '--on-error=stop', + '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json'] + + 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') @@ -458,11 +514,13 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', "--output-name="+output_name, '--enable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/job/cwl.input.json'] + stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + "--output-name="+output_name, '--enable-reuse', '--on-error=continue', + '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json'] expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( - body=expect_container) + body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') @@ -480,11 +538,13 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', "--output-tags="+output_tags, '--enable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/job/cwl.input.json'] + stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + "--output-tags="+output_tags, '--enable-reuse', '--on-error=continue', + '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json'] expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( - body=expect_container) + body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') @@ -504,10 +564,172 @@ class TestSubmit(unittest.TestCase): expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( - body=expect_container) + body=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + @mock.patch("arvados.collection.CollectionReader") + @mock.patch("time.sleep") + @stubs + def test_submit_file_keepref(self, stubs, tm, collectionReader): + capture_stdout = cStringIO.StringIO() + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_keepref_wf.cwl"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + + @mock.patch("arvados.collection.CollectionReader") + @mock.patch("time.sleep") + @stubs + def test_submit_keepref(self, stubs, tm, reader): + capture_stdout = cStringIO.StringIO() + + with open("tests/wf/expect_arvworkflow.cwl") as f: + reader().open().__enter__().read.return_value = f.read() + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + expect_container = { + 'priority': 1, + 'mounts': { + '/var/spool/cwl': { + 'writable': True, + 'kind': 'collection' + }, + 'stdout': { + 'path': '/var/spool/cwl/cwl.output.json', + 'kind': 'file' + }, + '/var/lib/cwl/workflow': { + 'portable_data_hash': '99999999999999999999999999999994+99', + 'kind': 'collection' + }, + '/var/lib/cwl/cwl.input.json': { + 'content': { + 'x': 'XxX' + }, + 'kind': 'json' + } + }, 'state': 'Committed', + 'owner_uuid': None, + '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', + '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'], + 'cwd': '/var/spool/cwl', + 'runtime_constraints': { + 'API': True, + 'vcpus': 1, + 'ram': 1073741824 + }, + "properties": {} + } + + 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("time.sleep") + @stubs + def test_submit_arvworkflow(self, stubs, tm): + capture_stdout = cStringIO.StringIO() + + with open("tests/wf/expect_arvworkflow.cwl") as f: + stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"} + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + expect_container = { + 'priority': 1, + 'mounts': { + '/var/spool/cwl': { + 'writable': True, + 'kind': 'collection' + }, + 'stdout': { + 'path': '/var/spool/cwl/cwl.output.json', + 'kind': 'file' + }, + '/var/lib/cwl/workflow.json': { + 'kind': 'json', + 'json': { + 'cwlVersion': 'v1.0', + '$graph': [ + { + 'inputs': [ + { + 'inputBinding': {'position': 1}, + 'type': 'string', + 'id': '#submit_tool.cwl/x'} + ], + 'requirements': [ + {'dockerPull': 'debian:8', 'class': 'DockerRequirement'} + ], + 'id': '#submit_tool.cwl', + 'outputs': [], + 'baseCommand': 'cat', + 'class': 'CommandLineTool' + }, { + 'id': '#main', + 'inputs': [ + {'type': 'string', 'id': '#main/x'} + ], + 'steps': [ + {'in': [{'source': '#main/x', 'id': '#main/step1/x'}], + 'run': '#submit_tool.cwl', + 'id': '#main/step1', + 'out': []} + ], + 'class': 'Workflow', + 'outputs': [] + } + ] + } + }, + '/var/lib/cwl/cwl.input.json': { + 'content': { + 'x': 'XxX' + }, + 'kind': 'json' + } + }, 'state': 'Committed', + 'owner_uuid': None, + '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', + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], + 'cwd': '/var/spool/cwl', + 'runtime_constraints': { + 'API': True, + 'vcpus': 1, + 'ram': 1073741824 + }, + "properties": { + "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37" + } + } + + 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_name(self, stubs): capture_stdout = cStringIO.StringIO() @@ -528,6 +750,7 @@ class TestSubmit(unittest.TestCase): 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("arvados.api") @@ -872,7 +1095,8 @@ class TestTemplateInputs(unittest.TestCase): }, }, 'repository': 'arvados', - 'script_version': arvados_cwl.__version__, + 'script_version': 'master', + 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9', 'script': 'cwl-runner', }, },