X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/469ea187586ea8017e26874c2d80414ce7571fae..c31c6528cac695bc86d4244516e07ea316cac979:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index a726ec5017..dcbee726b6 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -19,6 +19,7 @@ import sys import unittest import cwltool.process import re +import os from io import BytesIO @@ -45,7 +46,7 @@ import ruamel.yaml as yaml _rootDesc = None -def stubs(wfname='submit_wf.cwl'): +def stubs(wfdetails=('submit_wf.cwl', None)): def outer_wrapper(func, *rest): @functools.wraps(func) @mock.patch("arvados_cwl.arvdocker.determine_image_id") @@ -58,6 +59,10 @@ def stubs(wfname='submit_wf.cwl'): uuid4, determine_image_id, *args, **kwargs): class Stubs(object): pass + + wfname = wfdetails[0] + wfpath = wfdetails[1] + stubs = Stubs() stubs.events = events stubs.keepdocker = keepdocker @@ -273,9 +278,28 @@ def stubs(wfname='submit_wf.cwl'): stubs.api.pipeline_instances().create().execute.return_value = stubs.pipeline_create stubs.api.pipeline_instances().get().execute.return_value = stubs.pipeline_with_job - with open("tests/wf/submit_wf_packed.cwl") as f: + cwd = os.getcwd() + filepath = os.path.join(cwd, "tests/wf/submit_wf_packed.cwl") + with open(filepath) as f: expect_packed_workflow = yaml.round_trip_load(f) + if wfpath is None: + wfpath = wfname + + gitinfo_workflow = copy.deepcopy(expect_packed_workflow) + gitinfo_workflow["$graph"][0]["id"] = "file://%s/tests/wf/%s" % (cwd, wfpath) + mocktool = mock.NonCallableMock(tool=gitinfo_workflow["$graph"][0], metadata=gitinfo_workflow) + + stubs.git_info = arvados_cwl.executor.ArvCwlExecutor.get_git_info(mocktool) + expect_packed_workflow.update(stubs.git_info) + + stubs.git_props = {"arv:"+k.split("#", 1)[1]: v for k,v in stubs.git_info.items()} + + if wfname == wfpath: + container_name = "%s (%s)" % (wfpath, stubs.git_props["arv:gitDescribe"]) + else: + container_name = wfname + stubs.expect_container_spec = { 'priority': 500, 'mounts': { @@ -321,12 +345,12 @@ def stubs(wfname='submit_wf.cwl'): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - '--output-name=Output from workflow '+wfname, + '--output-name=Output from workflow '+container_name, '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], - 'name': wfname, + 'name': container_name, 'container_image': '999999999999999999999999999999d3+99', - 'output_name': 'Output from workflow '+wfname, + 'output_name': 'Output from workflow %s' % (container_name), 'output_path': '/var/spool/cwl', 'cwd': '/var/spool/cwl', 'runtime_constraints': { @@ -335,7 +359,7 @@ def stubs(wfname='submit_wf.cwl'): 'ram': (1024+256)*1024*1024 }, 'use_existing': False, - 'properties': {}, + 'properties': stubs.git_props, 'secret_mounts': {} } @@ -369,7 +393,7 @@ class TestSubmit(unittest.TestCase): root_logger.handlers = handlers @mock.patch("time.sleep") - @stubs + @stubs() def test_submit_invalid_runner_ram(self, stubs, tm): exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048", @@ -378,7 +402,7 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 1) - @stubs + @stubs() def test_submit_container(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", @@ -390,7 +414,7 @@ class TestSubmit(unittest.TestCase): 'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n', 'replication_desired': None, - 'name': 'submit_wf.cwl input (169f39d466a5438ac4a90e779bf750c7+53)', + 'name': 'submit_wf.cwl ('+ stubs.git_props["arv:gitDescribe"] +') input (169f39d466a5438ac4a90e779bf750c7+53)', }), ensure_unique_name=False), mock.call(body=JsonDiffMatcher({ 'manifest_text': @@ -408,7 +432,7 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_tool(self, stubs): # test for issue #16139 exited = arvados_cwl.main( @@ -420,7 +444,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_no_reuse(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse", @@ -433,7 +457,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--disable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] expect_container["use_existing"] = False @@ -444,7 +468,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs('submit_wf_no_reuse.cwl') + @stubs(('submit_wf_no_reuse.cwl', None)) def test_submit_container_reuse_disabled_by_workflow(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", @@ -453,13 +477,7 @@ class TestSubmit(unittest.TestCase): 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', '--disable-color', - '--eval-timeout=20', '--thread-count=0', - '--disable-reuse', "--collection-cache-size=256", - '--output-name=Output from workflow submit_wf_no_reuse.cwl', '--debug', '--on-error=continue', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = ["--disable-reuse" if v == "--enable-reuse" else v for v in expect_container["command"]] expect_container["use_existing"] = False expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$graph"][1]["hints"] = [ { @@ -478,7 +496,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') - @stubs + @stubs() def test_submit_container_on_error(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop", @@ -490,7 +508,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=stop', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -500,7 +518,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_output_name(self, stubs): output_name = "test_output_name" @@ -524,7 +542,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_storage_classes(self, stubs): exited = arvados_cwl.main( ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo", @@ -536,7 +554,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - '--output-name=Output from workflow submit_wf.cwl', + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], "--debug", "--storage-classes=foo", '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -547,7 +565,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_multiple_storage_classes(self, stubs): exited = arvados_cwl.main( ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo,bar", "--intermediate-storage-classes=baz", @@ -559,7 +577,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], "--debug", "--storage-classes=foo,bar", "--intermediate-storage-classes=baz", '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -573,7 +591,7 @@ class TestSubmit(unittest.TestCase): @mock.patch("cwltool.task_queue.TaskQueue") @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job") @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection") - @stubs + @stubs() def test_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq): final_output_c = arvados.collection.Collection() make_output.return_value = ({},final_output_c) @@ -584,17 +602,17 @@ class TestSubmit(unittest.TestCase): job.side_effect = set_final_output exited = arvados_cwl.main( - ["--debug", "--local", "--storage-classes=foo", + ["--debug", "--local", "--storage-classes=foo", "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', {}, {"out": "zzzzz"}) + make_output.assert_called_with(u'Output from workflow submit_wf.cwl', ['foo'], '', {}, {"out": "zzzzz"}) self.assertEqual(exited, 0) @mock.patch("cwltool.task_queue.TaskQueue") @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job") @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection") - @stubs + @stubs() def test_default_storage_classes_correctly_propagate_to_make_output_collection(self, stubs, make_output, job, tq): final_output_c = arvados.collection.Collection() make_output.return_value = ({},final_output_c) @@ -606,17 +624,17 @@ class TestSubmit(unittest.TestCase): job.side_effect = set_final_output exited = arvados_cwl.main( - ["--debug", "--local", + ["--debug", "--local", "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', {}, {"out": "zzzzz"}) + make_output.assert_called_with(u'Output from workflow submit_wf.cwl', ['default'], '', {}, {"out": "zzzzz"}) self.assertEqual(exited, 0) @mock.patch("cwltool.task_queue.TaskQueue") @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job") @mock.patch("arvados_cwl.executor.ArvCwlExecutor.make_output_collection") - @stubs + @stubs() def test_storage_class_hint_to_make_output_collection(self, stubs, make_output, job, tq): final_output_c = arvados.collection.Collection() make_output.return_value = ({},final_output_c) @@ -627,14 +645,14 @@ class TestSubmit(unittest.TestCase): job.side_effect = set_final_output exited = arvados_cwl.main( - ["--debug", "--local", + ["--debug", "--local", "--disable-git", "tests/wf/submit_storage_class_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - make_output.assert_called_with(u'Output of submit_storage_class_wf.cwl', ['foo', 'bar'], '', {}, {"out": "zzzzz"}) + make_output.assert_called_with(u'Output from workflow submit_storage_class_wf.cwl', ['foo', 'bar'], '', {}, {"out": "zzzzz"}) self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_output_ttl(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600", @@ -646,7 +664,8 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", '--debug', + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', '--on-error=continue', "--intermediate-output-ttl=3600", '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -657,7 +676,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_trash_intermediate(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate", @@ -670,6 +689,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=continue', "--trash-intermediate", '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -680,7 +700,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_output_tags(self, stubs): output_tags = "tag0,tag1,tag2" @@ -694,7 +714,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], "--output-tags="+output_tags, '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -704,7 +724,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_runner_ram(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048", @@ -722,7 +742,7 @@ class TestSubmit(unittest.TestCase): @mock.patch("arvados.collection.CollectionReader") @mock.patch("time.sleep") - @stubs + @stubs() def test_submit_file_keepref(self, stubs, tm, collectionReader): collectionReader().exists.return_value = True collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt") @@ -734,7 +754,7 @@ class TestSubmit(unittest.TestCase): @mock.patch("arvados.collection.CollectionReader") @mock.patch("time.sleep") - @stubs + @stubs() def test_submit_keepref(self, stubs, tm, reader): with open("tests/wf/expect_arvworkflow.cwl") as f: reader().open().__enter__().read.return_value = f.read() @@ -795,13 +815,13 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) @mock.patch("time.sleep") - @stubs + @stubs() def test_submit_arvworkflow(self, stubs, tm): 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", + ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-git", "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) @@ -845,8 +865,7 @@ class TestSubmit(unittest.TestCase): 'requirements': [ { 'dockerPull': 'debian:buster-slim', - 'class': 'DockerRequirement', - "http://arvados.org/cwl#dockerCollectionPDH": "999999999999999999999999999999d4+99" + 'class': 'DockerRequirement' } ], 'id': '#submit_tool.cwl', @@ -870,8 +889,11 @@ class TestSubmit(unittest.TestCase): 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', - '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', + '--enable-reuse', "--collection-cache-size=256", + "--output-name=Output from workflow a test workflow", + '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], + 'output_name': 'Output from workflow a test workflow', 'cwd': '/var/spool/cwl', 'runtime_constraints': { 'API': True, @@ -891,7 +913,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs('hello container 123') + @stubs(('hello container 123', 'submit_wf.cwl')) def test_submit_container_name(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123", @@ -906,7 +928,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_missing_input(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", @@ -920,7 +942,7 @@ class TestSubmit(unittest.TestCase): stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) self.assertEqual(exited, 1) - @stubs + @stubs() def test_submit_container_project(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"} @@ -935,7 +957,8 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', "--eval-timeout=20", "--thread-count=0", '--enable-reuse', "--collection-cache-size=256", - "--output-name=Output from workflow submit_wf.cwl", '--debug', + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', '--on-error=continue', '--project-uuid='+project_uuid, '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -946,7 +969,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_eval_timeout(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60", @@ -958,6 +981,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=60.0', '--thread-count=0', '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -967,7 +991,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_collection_cache(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500", @@ -979,6 +1003,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=0', '--enable-reuse', "--collection-cache-size=500", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024 @@ -989,7 +1014,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_thread_count(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20", @@ -1001,6 +1026,7 @@ class TestSubmit(unittest.TestCase): '--no-log-timestamps', '--disable-validate', '--disable-color', '--eval-timeout=20', '--thread-count=20', '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -1010,7 +1036,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_runner_image(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123", @@ -1026,7 +1052,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_priority(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669", @@ -1042,7 +1068,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs('submit_wf_runner_resources.cwl') + @stubs(('submit_wf_runner_resources.cwl', None)) def test_submit_wf_runner_resources(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", @@ -1066,13 +1092,7 @@ class TestSubmit(unittest.TestCase): expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"]["$namespaces"] = { "arv": "http://arvados.org/cwl#", } - expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers', - '--no-log-timestamps', '--disable-validate', '--disable-color', - '--eval-timeout=20', '--thread-count=0', - '--enable-reuse', "--collection-cache-size=512", - '--output-name=Output from workflow submit_wf_runner_resources.cwl', - '--debug', '--on-error=continue', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["command"] = ["--collection-cache-size=512" if v == "--collection-cache-size=256" else v for v in expect_container["command"]] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -1136,13 +1156,16 @@ class TestSubmit(unittest.TestCase): arvados_cwl.runner.arvados_jobs_image(arvrunner, "arvados/jobs:"+arvados_cwl.__version__, arvrunner.runtimeContext)) - @stubs + @stubs() def test_submit_secrets(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"], stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + stubs.git_props["arv:gitPath"] = "sdk/cwl/tests/wf/secret_wf.cwl" + stubs.git_info["http://arvados.org/cwl#gitPath"] = "sdk/cwl/tests/wf/secret_wf.cwl" + expect_container = { "command": [ "arvados-cwl-runner", @@ -1155,8 +1178,8 @@ class TestSubmit(unittest.TestCase): '--thread-count=0', "--enable-reuse", "--collection-cache-size=256", - '--output-name=Output from workflow secret_wf.cwl' - '--debug', + '--output-name=Output from workflow secret_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + "--debug", "--on-error=continue", "/var/lib/cwl/workflow.json#main", "/var/lib/cwl/cwl.input.json" @@ -1280,11 +1303,11 @@ class TestSubmit(unittest.TestCase): "path": "/var/spool/cwl/cwl.output.json" } }, - "name": "secret_wf.cwl", - "output_name": "Output from workflow secret_wf.cwl", + "name": "secret_wf.cwl (%s)" % stubs.git_props["arv:gitDescribe"], + "output_name": "Output from workflow secret_wf.cwl (%s)" % stubs.git_props["arv:gitDescribe"], "output_path": "/var/spool/cwl", "priority": 500, - "properties": {}, + "properties": stubs.git_props, "runtime_constraints": { "API": True, "ram": 1342177280, @@ -1300,13 +1323,15 @@ class TestSubmit(unittest.TestCase): "use_existing": False } + expect_container["mounts"]["/var/lib/cwl/workflow.json"]["content"].update(stubs.git_info) + stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_request_uuid(self, stubs): stubs.api._rootDesc["remoteHosts"]["zzzzz"] = "123" stubs.expect_container_request_uuid = "zzzzz-xvhdp-yyyyyyyyyyyyyyy" @@ -1328,7 +1353,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_container_cluster_id(self, stubs): stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123" @@ -1345,7 +1370,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_validate_cluster_id(self, stubs): stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123" exited = arvados_cwl.main( @@ -1354,7 +1379,7 @@ class TestSubmit(unittest.TestCase): stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) self.assertEqual(exited, 1) - @stubs + @stubs() def test_submit_validate_project_uuid(self, stubs): # Fails with bad cluster prefix exited = arvados_cwl.main( @@ -1380,7 +1405,7 @@ class TestSubmit(unittest.TestCase): @mock.patch("arvados.collection.CollectionReader") - @stubs + @stubs() def test_submit_uuid_inputs(self, stubs, collectionReader): collectionReader().exists.return_value = True collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt") @@ -1415,7 +1440,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_mismatched_uuid_inputs(self, stubs): def list_side_effect(**kwargs): m = mock.MagicMock() @@ -1448,7 +1473,7 @@ class TestSubmit(unittest.TestCase): cwltool_logger.removeHandler(stderr_logger) @mock.patch("arvados.collection.CollectionReader") - @stubs + @stubs() def test_submit_unknown_uuid_inputs(self, stubs, collectionReader): collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt") capture_stderr = StringIO() @@ -1470,7 +1495,7 @@ class TestSubmit(unittest.TestCase): finally: cwltool_logger.removeHandler(stderr_logger) - @stubs('submit_wf_process_properties.cwl') + @stubs(('submit_wf_process_properties.cwl', None)) def test_submit_set_process_properties(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", @@ -1500,14 +1525,14 @@ class TestSubmit(unittest.TestCase): "arv": "http://arvados.org/cwl#" } - expect_container["properties"] = { + expect_container["properties"].update({ "baz": "blorp.txt", "foo": "bar", "quux": { "q1": 1, "q2": 2 } - } + }) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -1516,7 +1541,7 @@ class TestSubmit(unittest.TestCase): self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_enable_preemptible(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--enable-preemptible", @@ -1525,11 +1550,13 @@ class TestSubmit(unittest.TestCase): expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers', - '--no-log-timestamps', '--disable-validate', '--disable-color', - '--eval-timeout=20', '--thread-count=0', - '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', + '--no-log-timestamps', '--disable-validate', '--disable-color', + '--eval-timeout=20', '--thread-count=0', + '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', '--on-error=continue', '--enable-preemptible', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -1537,7 +1564,7 @@ class TestSubmit(unittest.TestCase): stubs.expect_container_request_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_submit_disable_preemptible(self, stubs): exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-preemptible", @@ -1546,11 +1573,57 @@ class TestSubmit(unittest.TestCase): expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers', - '--no-log-timestamps', '--disable-validate', '--disable-color', - '--eval-timeout=20', '--thread-count=0', - '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', + '--no-log-timestamps', '--disable-validate', '--disable-color', + '--eval-timeout=20', '--thread-count=0', + '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', '--on-error=continue', '--disable-preemptible', - '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + '/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(stubs.capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) + + @stubs() + def test_submit_container_prefer_cached_downloads(self, stubs): + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--prefer-cached-downloads", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', '--disable-color', + '--eval-timeout=20', '--thread-count=0', + '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', "--on-error=continue", '--prefer-cached-downloads', + '/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(stubs.capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) + + @stubs() + def test_submit_container_varying_url_params(self, stubs): + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--varying-url-params", "KeyId,Signature", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', + '--no-log-timestamps', '--disable-validate', '--disable-color', + '--eval-timeout=20', '--thread-count=0', + '--enable-reuse', "--collection-cache-size=256", + '--output-name=Output from workflow submit_wf.cwl (%s)' % stubs.git_props["arv:gitDescribe"], + '--debug', "--on-error=continue", "--varying-url-params=KeyId,Signature", + '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) @@ -1562,7 +1635,9 @@ class TestSubmit(unittest.TestCase): class TestCreateWorkflow(unittest.TestCase): existing_workflow_uuid = "zzzzz-7fd4e-validworkfloyml" expect_workflow = StripYAMLComments( - open("tests/wf/expect_upload_packed.cwl").read().rstrip()) + open("tests/wf/expect_upload_wrapper.cwl").read().rstrip()) + expect_workflow_altname = StripYAMLComments( + open("tests/wf/expect_upload_wrapper_altname.cwl").read().rstrip()) def setUp(self): cwltool.process._names = set() @@ -1575,7 +1650,7 @@ class TestCreateWorkflow(unittest.TestCase): handlers = [h for h in root_logger.handlers if not isinstance(h, arvados_cwl.executor.RuntimeStatusLoggingHandler)] root_logger.handlers = handlers - @stubs + @stubs() def test_create(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"} @@ -1584,6 +1659,7 @@ class TestCreateWorkflow(unittest.TestCase): ["--create-workflow", "--debug", "--api=containers", "--project-uuid", project_uuid, + "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) @@ -1605,7 +1681,7 @@ class TestCreateWorkflow(unittest.TestCase): stubs.expect_workflow_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_create_name(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"} @@ -1615,6 +1691,7 @@ class TestCreateWorkflow(unittest.TestCase): "--api=containers", "--project-uuid", project_uuid, "--name", "testing 123", + "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) @@ -1626,7 +1703,7 @@ class TestCreateWorkflow(unittest.TestCase): "owner_uuid": project_uuid, "name": "testing 123", "description": "", - "definition": self.expect_workflow, + "definition": self.expect_workflow_altname, } } stubs.api.workflows().create.assert_called_with( @@ -1637,7 +1714,7 @@ class TestCreateWorkflow(unittest.TestCase): self.assertEqual(exited, 0) - @stubs + @stubs() def test_update(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.workflows().get().execute.return_value = {"owner_uuid": project_uuid} @@ -1645,6 +1722,7 @@ class TestCreateWorkflow(unittest.TestCase): exited = arvados_cwl.main( ["--update-workflow", self.existing_workflow_uuid, "--debug", + "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) @@ -1664,7 +1742,7 @@ class TestCreateWorkflow(unittest.TestCase): self.assertEqual(exited, 0) - @stubs + @stubs() def test_update_name(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.workflows().get().execute.return_value = {"owner_uuid": project_uuid} @@ -1672,6 +1750,7 @@ class TestCreateWorkflow(unittest.TestCase): exited = arvados_cwl.main( ["--update-workflow", self.existing_workflow_uuid, "--debug", "--name", "testing 123", + "--disable-git", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) @@ -1679,7 +1758,7 @@ class TestCreateWorkflow(unittest.TestCase): "workflow": { "name": "testing 123", "description": "", - "definition": self.expect_workflow, + "definition": self.expect_workflow_altname, "owner_uuid": project_uuid } } @@ -1690,7 +1769,7 @@ class TestCreateWorkflow(unittest.TestCase): self.existing_workflow_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_create_collection_per_tool(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"} @@ -1699,10 +1778,11 @@ class TestCreateWorkflow(unittest.TestCase): ["--create-workflow", "--debug", "--api=containers", "--project-uuid", project_uuid, + "--disable-git", "tests/collection_per_tool/collection_per_tool.cwl"], stubs.capture_stdout, sys.stderr, api_client=stubs.api) - toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl" + toolfile = "tests/collection_per_tool/collection_per_tool_wrapper.cwl" expect_workflow = StripYAMLComments(open(toolfile).read().rstrip()) body = { @@ -1720,7 +1800,7 @@ class TestCreateWorkflow(unittest.TestCase): stubs.expect_workflow_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_create_with_imports(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"} @@ -1739,7 +1819,7 @@ class TestCreateWorkflow(unittest.TestCase): stubs.expect_workflow_uuid + '\n') self.assertEqual(exited, 0) - @stubs + @stubs() def test_create_with_no_input(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' stubs.api.groups().get().execute.return_value = {"group_class": "project"}