X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/322d784513c37abc8fa1d1c05dd5f41019868735..83a0c3c06e3d6c58da44cd433573b732c59f3beb:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index c4b0ceab0e..0ee90c8c74 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -98,7 +98,8 @@ def stubs(func): } stubs.expect_job_spec = { 'runtime_constraints': { - 'docker_image': 'arvados/jobs:'+arvados_cwl.__version__ + 'docker_image': 'arvados/jobs:'+arvados_cwl.__version__, + 'min_ram_mb_per_node': 1024 }, 'script_parameters': { 'x': { @@ -124,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() @@ -134,7 +136,7 @@ def stubs(func): 'owner_uuid': None, "components": { "cwl-runner": { - 'runtime_constraints': {'docker_image': 'arvados/jobs:'+arvados_cwl.__version__}, + '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:99999999999999999999999999999994+99/blorp.txt'}}, @@ -143,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'} } @@ -178,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', @@ -193,8 +206,9 @@ def stubs(func): 'runtime_constraints': { 'API': True, 'vcpus': 1, - 'ram': 268435456 - } + 'ram': 1024*1024*1024 + }, + "properties": {} } stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz" @@ -270,10 +284,58 @@ 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') + + @mock.patch("time.sleep") + @stubs + def test_submit_runner_ram(self, stubs, tm): + capture_stdout = cStringIO.StringIO() + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--debug", "--submit-runner-ram=2048", + "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"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048 + + 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') + + + @mock.patch("time.sleep") + @stubs + def test_submit_invalid_runner_ram(self, stubs, tm): + capture_stdout = cStringIO.StringIO() + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 1) + @mock.patch("time.sleep") @stubs def test_submit_output_name(self, stubs, tm): @@ -288,6 +350,25 @@ class TestSubmit(unittest.TestCase): stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name + 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') + + + @mock.patch("time.sleep") + @stubs + def test_submit_pipeline_name(self, stubs, tm): + capture_stdout = cStringIO.StringIO() + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--debug", "--name=hello job 123", + "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["name"] = "hello job 123" + expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( body=expect_pipeline) @@ -310,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') @@ -329,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): @@ -370,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') @@ -386,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') @@ -408,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') @@ -430,7 +538,211 @@ 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=JsonDiffMatcher(expect_container)) + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + + @stubs + def test_submit_container_runner_ram(self, stubs): + capture_stdout = cStringIO.StringIO() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048", + "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["runtime_constraints"]["ram"] = 2048*1024*1024 + + 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.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() + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123", + "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["name"] = "hello container 123" expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( @@ -438,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") @@ -482,23 +795,9 @@ class TestSubmit(unittest.TestCase): self.assertEqual("arvados/jobs:"+arvados_cwl.__version__, arvados_cwl.runner.arvados_jobs_image(arvrunner)) class TestCreateTemplate(unittest.TestCase): - @stubs - def test_create(self, stubs): - project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + existing_template_uuid = "zzzzz-d1hrv-validworkfloyml" - capture_stdout = cStringIO.StringIO() - - exited = arvados_cwl.main( - ["--create-workflow", "--debug", - "--project-uuid", project_uuid, - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) - - stubs.api.pipeline_instances().create.refute_called() - stubs.api.jobs().create.refute_called() - - expect_component = copy.deepcopy(stubs.expect_job_spec) + def _adjust_script_params(self, expect_component): expect_component['script_parameters']['x'] = { 'dataclass': 'File', 'required': True, @@ -516,6 +815,26 @@ class TestCreateTemplate(unittest.TestCase): 'required': True, 'type': 'Directory', } + + @stubs + def test_create(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--create-workflow", "--debug", + "--api=jobs", + "--project-uuid", project_uuid, + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + stubs.api.pipeline_instances().create.refute_called() + stubs.api.jobs().create.refute_called() + + expect_component = copy.deepcopy(stubs.expect_job_spec) + self._adjust_script_params(expect_component) expect_template = { "components": { "submit_wf.cwl": expect_component, @@ -530,6 +849,76 @@ class TestCreateTemplate(unittest.TestCase): stubs.expect_pipeline_template_uuid + '\n') + @stubs + def test_create_name(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--create-workflow", "--debug", + "--project-uuid", project_uuid, + "--api=jobs", + "--name", "testing 123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + stubs.api.pipeline_instances().create.refute_called() + stubs.api.jobs().create.refute_called() + + expect_component = copy.deepcopy(stubs.expect_job_spec) + self._adjust_script_params(expect_component) + expect_template = { + "components": { + "testing 123": expect_component, + }, + "name": "testing 123", + "owner_uuid": project_uuid, + } + stubs.api.pipeline_templates().create.assert_called_with( + body=JsonDiffMatcher(expect_template), ensure_unique_name=True) + + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_pipeline_template_uuid + '\n') + + + @stubs + def test_update_name(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--update-workflow", self.existing_template_uuid, + "--debug", + "--project-uuid", project_uuid, + "--api=jobs", + "--name", "testing 123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + stubs.api.pipeline_instances().create.refute_called() + stubs.api.jobs().create.refute_called() + + expect_component = copy.deepcopy(stubs.expect_job_spec) + self._adjust_script_params(expect_component) + expect_template = { + "components": { + "testing 123": expect_component, + }, + "name": "testing 123", + "owner_uuid": project_uuid, + } + stubs.api.pipeline_templates().create.refute_called() + stubs.api.pipeline_templates().update.assert_called_with( + body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid) + + self.assertEqual(capture_stdout.getvalue(), + self.existing_template_uuid + '\n') + + class TestCreateWorkflow(unittest.TestCase): existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml" expect_workflow = open("tests/wf/expect_packed.cwl").read() @@ -565,6 +954,39 @@ class TestCreateWorkflow(unittest.TestCase): self.assertEqual(capture_stdout.getvalue(), stubs.expect_workflow_uuid + '\n') + + @stubs + def test_create_name(self, stubs): + project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' + + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--create-workflow", "--debug", + "--api=containers", + "--project-uuid", project_uuid, + "--name", "testing 123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + stubs.api.pipeline_templates().create.refute_called() + stubs.api.container_requests().create.refute_called() + + body = { + "workflow": { + "owner_uuid": project_uuid, + "name": "testing 123", + "description": "", + "definition": self.expect_workflow, + } + } + stubs.api.workflows().create.assert_called_with( + body=JsonDiffMatcher(body)) + + self.assertEqual(capture_stdout.getvalue(), + stubs.expect_workflow_uuid + '\n') + @stubs def test_incompatible_api(self, stubs): capture_stderr = cStringIO.StringIO() @@ -607,12 +1029,38 @@ class TestCreateWorkflow(unittest.TestCase): self.existing_workflow_uuid + '\n') + @stubs + def test_update_name(self, stubs): + capture_stdout = cStringIO.StringIO() + + exited = arvados_cwl.main( + ["--update-workflow", self.existing_workflow_uuid, + "--debug", "--name", "testing 123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + body = { + "workflow": { + "name": "testing 123", + "description": "", + "definition": self.expect_workflow, + } + } + stubs.api.workflows().update.assert_called_with( + uuid=self.existing_workflow_uuid, + body=JsonDiffMatcher(body)) + self.assertEqual(capture_stdout.getvalue(), + self.existing_workflow_uuid + '\n') + + class TestTemplateInputs(unittest.TestCase): expect_template = { "components": { "inputs_test.cwl": { 'runtime_constraints': { 'docker_image': 'arvados/jobs:'+arvados_cwl.__version__, + 'min_ram_mb_per_node': 1024 }, 'script_parameters': { 'cwl:tool': @@ -647,7 +1095,8 @@ class TestTemplateInputs(unittest.TestCase): }, }, 'repository': 'arvados', - 'script_version': arvados_cwl.__version__, + 'script_version': 'master', + 'minimum_script_version': '570509ab4d2ef93d870fd2b1f2eab178afb1bad9', 'script': 'cwl-runner', }, }, @@ -657,7 +1106,7 @@ class TestTemplateInputs(unittest.TestCase): @stubs def test_inputs_empty(self, stubs): exited = arvados_cwl.main( - ["--create-template", "--no-wait", + ["--create-template", "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"], cStringIO.StringIO(), sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) @@ -668,7 +1117,7 @@ class TestTemplateInputs(unittest.TestCase): @stubs def test_inputs(self, stubs): exited = arvados_cwl.main( - ["--create-template", "--no-wait", + ["--create-template", "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"], cStringIO.StringIO(), sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0)