X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/60d986b8908487c086eb4e402ac69669cb26108b..2001423a6eb7937a689414f3fa62be5b124812c1:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index 9e918fc9a1..85c49c9134 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -124,7 +124,7 @@ def stubs(func): 'class': 'Directory' }, 'cwl:tool': - 'ef2c299cb4e5a565a46d94887eafdc62+58/workflow.cwl' + '99999999999999999999999999999994+99/workflow.cwl#main' }, 'repository': 'arvados', 'script_version': 'master', @@ -146,7 +146,7 @@ def stubs(func): 'listing': [ {'basename': 'renamed.txt', 'class': 'File', 'location': 'keep:99999999999999999999999999999998+99/file1.txt'} ]}}, - 'cwl:tool': 'f57578d5cfda7f70fef00cbc4b621e6b+58/workflow.cwl', + 'cwl:tool': '99999999999999999999999999999994+99/workflow.cwl#main', 'arv:enable_reuse': True, 'arv:on_error': 'continue' }, @@ -180,7 +180,7 @@ def stubs(func): 'kind': 'collection' }, '/var/lib/cwl/workflow.json': { - 'json': expect_packed_workflow, + 'content': expect_packed_workflow, 'kind': 'json' }, 'stdout': { @@ -233,12 +233,13 @@ def stubs(func): class TestSubmit(unittest.TestCase): + @mock.patch("arvados_cwl.runner.arv_docker_get_image") @mock.patch("time.sleep") @stubs - def test_submit(self, stubs, tm): + def test_submit(self, stubs, tm, arvdock): capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( - ["--submit", "--no-wait", "--debug", + ["--submit", "--no-wait", "--api=jobs", "--debug", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) @@ -248,17 +249,22 @@ class TestSubmit(unittest.TestCase): mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n', - 'owner_uuid': None, + 'replication_desired': None, 'name': 'submit_tool.cwl dependencies', }), ensure_unique_name=True), - mock.call().execute(), + mock.call().execute(num_retries=4), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n', - 'owner_uuid': None, + 'replication_desired': None, 'name': 'submit_wf.cwl input', }), ensure_unique_name=True), - mock.call().execute()]) + mock.call().execute(num_retries=4)]) + + arvdock.assert_has_calls([ + mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None), + mock.call(stubs.api, {'dockerPull': 'arvados/jobs:'+arvados_cwl.__version__}, True, None) + ]) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( @@ -272,14 +278,14 @@ class TestSubmit(unittest.TestCase): def test_submit_no_reuse(self, stubs, tm): capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( - ["--submit", "--no-wait", "--debug", "--disable-reuse", + ["--submit", "--no-wait", "--api=jobs", "--debug", "--disable-reuse", "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:enable_reuse"] = {"value": False} - expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False} + stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), @@ -290,14 +296,14 @@ class TestSubmit(unittest.TestCase): def test_submit_on_error(self, stubs, tm): capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( - ["--submit", "--no-wait", "--debug", "--on-error=stop", + ["--submit", "--no-wait", "--api=jobs", "--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) + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop" + stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), @@ -314,9 +320,9 @@ class TestSubmit(unittest.TestCase): 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) + expect_pipeline["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048 + stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), @@ -345,9 +351,9 @@ class TestSubmit(unittest.TestCase): capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) - stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name - expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name + stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), @@ -364,11 +370,11 @@ class TestSubmit(unittest.TestCase): 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) + expect_pipeline["name"] = "hello job 123" + 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') @@ -384,9 +390,9 @@ class TestSubmit(unittest.TestCase): capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) - stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags - expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags + stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) self.assertEqual(capture_stdout.getvalue(), @@ -426,17 +432,17 @@ class TestSubmit(unittest.TestCase): mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n', - 'owner_uuid': None, + 'replication_desired': None, 'name': 'submit_tool.cwl dependencies', }), ensure_unique_name=True), - mock.call().execute(), + mock.call().execute(num_retries=4), mock.call(body=JsonDiffMatcher({ 'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n', - 'owner_uuid': None, + 'replication_desired': None, 'name': 'submit_wf.cwl input', }), ensure_unique_name=True), - mock.call().execute()]) + mock.call().execute(num_retries=4)]) expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( @@ -456,11 +462,11 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + 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 = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), @@ -479,11 +485,11 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + 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 = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), @@ -503,12 +509,12 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + 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'] - stubs.expect_container_spec["output_name"] = output_name + expect_container["output_name"] = output_name - 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(), @@ -528,11 +534,11 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', + 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 = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), @@ -550,9 +556,9 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["runtime_constraints"]["ram"] = 2048*1024*1024 - expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["runtime_constraints"]["ram"] = 2048*1024*1024 + stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), @@ -628,6 +634,31 @@ class TestSubmit(unittest.TestCase): self.assertEqual(capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + + @mock.patch("arvados.collection.CollectionReader") + @mock.patch("time.sleep") + @stubs + def test_submit_jobs_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=jobs", "--debug", + "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"], + capture_stdout, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 0) + + expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX" + del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"] + del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"] + expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main" + expect_pipeline["name"] = "expect_arvworkflow.cwl#main" + stubs.api.pipeline_instances().create.assert_called_with( + body=JsonDiffMatcher(expect_pipeline)) + @mock.patch("time.sleep") @stubs def test_submit_arvworkflow(self, stubs, tm): @@ -655,7 +686,7 @@ class TestSubmit(unittest.TestCase): }, '/var/lib/cwl/workflow.json': { 'kind': 'json', - 'json': { + 'content': { 'cwlVersion': 'v1.0', '$graph': [ { @@ -733,9 +764,9 @@ class TestSubmit(unittest.TestCase): except: logging.exception("") - stubs.expect_container_spec["name"] = "hello container 123" - expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["name"] = "hello container 123" + stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(capture_stdout.getvalue(), @@ -791,18 +822,8 @@ class TestSubmit(unittest.TestCase): arvrunner.project_uuid = "" api.return_value = mock.MagicMock() arvrunner.api = api.return_value - arvrunner.api.links().list().execute.side_effect = ({"items": [], "items_available": 0, "offset": 0}, - {"items": [], "items_available": 0, "offset": 0}, - {"items": [], "items_available": 0, "offset": 0}, - {"items": [{"created_at": "", - "head_uuid": "", - "link_class": "docker_image_hash", - "name": "123456", - "owner_uuid": "", - "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0}, - {"items": [], "items_available": 0, "offset": 0}, - {"items": [{"created_at": "", - "head_uuid": "", + arvrunner.api.links().list().execute.side_effect = ({"items": [{"created_at": "", + "head_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb", "link_class": "docker_image_repo+tag", "name": "arvados/jobs:"+arvados_cwl.__version__, "owner_uuid": "", @@ -812,19 +833,18 @@ class TestSubmit(unittest.TestCase): "link_class": "docker_image_hash", "name": "123456", "owner_uuid": "", - "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0} , + "properties": {"image_timestamp": ""}}], "items_available": 1, "offset": 0} ) find_one_image_hash.return_value = "123456" - arvrunner.api.collections().list().execute.side_effect = ({"items": [], "items_available": 0, "offset": 0}, - {"items": [{"uuid": "", + arvrunner.api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzb", "owner_uuid": "", "manifest_text": "", "properties": "" - }], "items_available": 1, "offset": 0}, - {"items": [{"uuid": ""}], "items_available": 1, "offset": 0}) + }], "items_available": 1, "offset": 0},) arvrunner.api.collections().create().execute.return_value = {"uuid": ""} - self.assertEqual("arvados/jobs:"+arvados_cwl.__version__, arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__)) + self.assertEqual("arvados/jobs:"+arvados_cwl.__version__, + arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__)) class TestCreateTemplate(unittest.TestCase): existing_template_uuid = "zzzzz-d1hrv-validworkfloyml" @@ -1096,8 +1116,7 @@ class TestTemplateInputs(unittest.TestCase): }, 'script_parameters': { 'cwl:tool': - '99999999999999999999999999999991+99/' - 'wf/inputs_test.cwl', + '99999999999999999999999999999992+99/workflow.cwl#main', 'optionalFloatInput': None, 'fileInput': { 'type': 'File', @@ -1158,6 +1177,7 @@ class TestTemplateInputs(unittest.TestCase): 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["floatInput"]["value"] = 1.234 params["boolInput"]["value"] = True