X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/35658af99f09f2f6768583d65246429f789fc5a2..c110a9aeed738f1b2dd456950a8ee3018cd97fed:/sdk/cwl/tests/test_container.py?ds=sidebyside diff --git a/sdk/cwl/tests/test_container.py b/sdk/cwl/tests/test_container.py index 3374e1c13f..bfffe6eacb 100644 --- a/sdk/cwl/tests/test_container.py +++ b/sdk/cwl/tests/test_container.py @@ -18,6 +18,8 @@ import os import functools import cwltool.process import cwltool.secrets +import cwltool.load_tool +from cwltool.update import INTERNAL_VERSION from schema_salad.ref_resolver import Loader from schema_salad.sourceline import cmap @@ -58,18 +60,23 @@ class TestContainer(unittest.TestCase): def setUp(self): cwltool.process._names = set() + arv_docker_clear_cache() def helper(self, runner, enable_reuse=True): - document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.1") + document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema(INTERNAL_VERSION) make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, collection_cache=arvados_cwl.CollectionCache(runner.api, None, 0)) + fs_access = mock.MagicMock() + fs_access.exists.return_value = True + loadingContext = arvados_cwl.context.ArvLoadingContext( {"avsc_names": avsc_names, "basedir": "", "make_fs_access": make_fs_access, - "loader": Loader({}), - "metadata": {"cwlVersion": "v1.1", "http://commonwl.org/cwltool#original_cwlVersion": "v1.0"}}) + "construct_tool_object": runner.arv_make_tool, + "fetcher_constructor": functools.partial(arvados_cwl.CollectionFetcher, api_client=runner.api, fs_access=fs_access) + }) runtimeContext = arvados_cwl.context.ArvRuntimeContext( {"work_api": "containers", "basedir": "", @@ -81,6 +88,11 @@ class TestContainer(unittest.TestCase): "project_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz" }) + if isinstance(runner, mock.MagicMock): + def make_tool(toolpath_object, loadingContext): + return arvados_cwl.ArvadosCommandTool(runner, toolpath_object, loadingContext) + runner.arv_make_tool.side_effect = make_tool + return loadingContext, runtimeContext # Helper function to set up the ArvCwlExecutor to use the containers api @@ -110,6 +122,7 @@ class TestContainer(unittest.TestCase): runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -120,13 +133,14 @@ class TestContainer(unittest.TestCase): "outputs": [], "baseCommand": "ls", "arguments": [{"valueFrom": "$(runtime.outdir)"}], - "id": "#", - "class": "CommandLineTool" + "id": "", + "class": "CommandLineTool", + "cwlVersion": "v1.2" }) loadingContext, runtimeContext = self.helper(runner, enable_reuse) - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None for j in arvtool.job({}, mock.MagicMock(), runtimeContext): @@ -140,7 +154,7 @@ class TestContainer(unittest.TestCase): 'name': 'test_run_'+str(enable_reuse), 'runtime_constraints': { 'vcpus': 1, - 'ram': 1073741824 + 'ram': 268435456 }, 'use_existing': enable_reuse, 'priority': 500, @@ -161,18 +175,20 @@ class TestContainer(unittest.TestCase): 'cwd': '/var/spool/cwl', 'scheduling_parameters': {}, 'properties': {}, - 'secret_mounts': {} + 'secret_mounts': {}, + 'output_storage_classes': ["default"] })) # The test passes some fields in builder.resources # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} @mock.patch("arvados.commands.keepdocker.list_images_in_arv") def test_resource_requirements(self, keepdocker): - arv_docker_clear_cache() + arvados_cwl.add_arv_hints() runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 3600 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -199,18 +215,19 @@ class TestContainer(unittest.TestCase): "class": "http://arvados.org/cwl#IntermediateOutput", "outputTTL": 7200 }, { - "class": "http://arvados.org/cwl#ReuseRequirement", + "class": "WorkReuse", "enableReuse": False }], "baseCommand": "ls", - "id": "#", - "class": "CommandLineTool" + "id": "", + "class": "CommandLineTool", + "cwlVersion": "v1.2" }) loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_resource_requirements" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None for j in arvtool.job({}, mock.MagicMock(), runtimeContext): j.run(runtimeContext) @@ -249,7 +266,8 @@ class TestContainer(unittest.TestCase): 'partitions': ['blurb'] }, 'properties': {}, - 'secret_mounts': {} + 'secret_mounts': {}, + 'output_storage_classes': ["default"] } call_body = call_kwargs.get('body', None) @@ -263,11 +281,11 @@ class TestContainer(unittest.TestCase): @mock.patch("arvados.commands.keepdocker.list_images_in_arv") @mock.patch("arvados.collection.Collection") def test_initial_work_dir(self, collection_mock, keepdocker): - arv_docker_clear_cache() runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -311,14 +329,16 @@ class TestContainer(unittest.TestCase): } ] }], "baseCommand": "ls", - "id": "#", - "class": "CommandLineTool" + "class": "CommandLineTool", + "cwlVersion": "v1.2", + "id": "" }) loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_initial_work_dir" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) + arvtool.formatgraph = None for j in arvtool.job({}, mock.MagicMock(), runtimeContext): j.run(runtimeContext) @@ -338,7 +358,7 @@ class TestContainer(unittest.TestCase): 'name': 'test_initial_work_dir', 'runtime_constraints': { 'vcpus': 1, - 'ram': 1073741824 + 'ram': 268435456 }, 'use_existing': True, 'priority': 500, @@ -379,7 +399,8 @@ class TestContainer(unittest.TestCase): 'scheduling_parameters': { }, 'properties': {}, - 'secret_mounts': {} + 'secret_mounts': {}, + 'output_storage_classes': ["default"] } call_body = call_kwargs.get('body', None) @@ -391,18 +412,17 @@ class TestContainer(unittest.TestCase): # Test redirecting stdin/stdout/stderr @mock.patch("arvados.commands.keepdocker.list_images_in_arv") def test_redirects(self, keepdocker): - arv_docker_clear_cache() - runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { "portable_data_hash": "99999999999999999999999999999993+99"} - document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.1") + document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema(INTERNAL_VERSION) tool = cmap({ "inputs": [], @@ -412,14 +432,15 @@ class TestContainer(unittest.TestCase): "stderr": "stderr.txt", "stdin": "/keep/99999999999999999999999999999996+99/file.txt", "arguments": [{"valueFrom": "$(runtime.outdir)"}], - "id": "#", - "class": "CommandLineTool" + "id": "", + "class": "CommandLineTool", + "cwlVersion": "v1.2" }) loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_run_redirect" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None for j in arvtool.job({}, mock.MagicMock(), runtimeContext): j.run(runtimeContext) @@ -432,7 +453,7 @@ class TestContainer(unittest.TestCase): 'name': 'test_run_redirect', 'runtime_constraints': { 'vcpus': 1, - 'ram': 1073741824 + 'ram': 268435456 }, 'use_existing': True, 'priority': 500, @@ -465,7 +486,8 @@ class TestContainer(unittest.TestCase): 'cwd': '/var/spool/cwl', 'scheduling_parameters': {}, 'properties': {}, - 'secret_mounts': {} + 'secret_mounts': {}, + 'output_storage_classes': ["default"] })) @mock.patch("arvados.collection.Collection") @@ -534,6 +556,25 @@ class TestContainer(unittest.TestCase): except RuntimeError: self.fail("RuntimeStatusLoggingHandler should not be called recursively") + + # Test to make sure that an exception raised from + # get_current_container doesn't cause the logger to raise an + # exception + @mock.patch("arvados_cwl.util.get_current_container") + def test_runtime_status_get_current_container_exception(self, gcc_mock): + self.setup_and_test_container_executor_and_logging(gcc_mock) + root_logger = logging.getLogger('') + + # get_current_container is invoked when we call + # runtime_status_update, it is going to also raise an + # exception. + gcc_mock.side_effect = Exception("Second Error") + try: + root_logger.error("First Error") + except Exception: + self.fail("Exception in logger should not propagate") + self.assertTrue(gcc_mock.called) + @mock.patch("arvados_cwl.ArvCwlExecutor.runtime_status_update") @mock.patch("arvados_cwl.util.get_current_container") @mock.patch("arvados.collection.CollectionReader") @@ -597,12 +638,11 @@ class TestContainer(unittest.TestCase): # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} @mock.patch("arvados.commands.keepdocker.list_images_in_arv") def test_mounts(self, keepdocker): - arv_docker_clear_cache() - runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -619,14 +659,15 @@ class TestContainer(unittest.TestCase): "outputs": [], "baseCommand": "ls", "arguments": [{"valueFrom": "$(runtime.outdir)"}], - "id": "#", - "class": "CommandLineTool" + "id": "", + "class": "CommandLineTool", + "cwlVersion": "v1.2" }) loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_run_mounts" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None job_order = { "p1": { @@ -656,7 +697,7 @@ class TestContainer(unittest.TestCase): 'name': 'test_run_mounts', 'runtime_constraints': { 'vcpus': 1, - 'ram': 1073741824 + 'ram': 268435456 }, 'use_existing': True, 'priority': 500, @@ -681,19 +722,20 @@ class TestContainer(unittest.TestCase): 'cwd': '/var/spool/cwl', 'scheduling_parameters': {}, 'properties': {}, - 'secret_mounts': {} + 'secret_mounts': {}, + 'output_storage_classes': ["default"] })) # The test passes no builder.resources # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} @mock.patch("arvados.commands.keepdocker.list_images_in_arv") def test_secrets(self, keepdocker): - arv_docker_clear_cache() - + arvados_cwl.add_arv_hints() runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -703,6 +745,7 @@ class TestContainer(unittest.TestCase): tool = cmap({"arguments": ["md5sum", "example.conf"], "class": "CommandLineTool", + "cwlVersion": "v1.2", "hints": [ { "class": "http://commonwl.org/cwltool#Secrets", @@ -711,7 +754,7 @@ class TestContainer(unittest.TestCase): ] } ], - "id": "#secret_job.cwl", + "id": "", "inputs": [ { "id": "#secret_job.cwl/pw", @@ -735,7 +778,7 @@ class TestContainer(unittest.TestCase): loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_secrets" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None job_order = {"pw": "blorp"} @@ -752,7 +795,7 @@ class TestContainer(unittest.TestCase): 'name': 'test_secrets', 'runtime_constraints': { 'vcpus': 1, - 'ram': 1073741824 + 'ram': 268435456 }, 'use_existing': True, 'priority': 500, @@ -778,19 +821,19 @@ class TestContainer(unittest.TestCase): "content": "username: user\npassword: blorp\n", "kind": "text" } - } + }, + 'output_storage_classes': ["default"] })) # The test passes no builder.resources # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} @mock.patch("arvados.commands.keepdocker.list_images_in_arv") def test_timelimit(self, keepdocker): - arv_docker_clear_cache() - runner = mock.MagicMock() runner.ignore_docker_for_reuse = False runner.intermediate_output_ttl = 0 runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -801,7 +844,8 @@ class TestContainer(unittest.TestCase): "outputs": [], "baseCommand": "ls", "arguments": [{"valueFrom": "$(runtime.outdir)"}], - "id": "#", + "id": "", + "cwlVersion": "v1.2", "class": "CommandLineTool", "hints": [ { @@ -814,7 +858,7 @@ class TestContainer(unittest.TestCase): loadingContext, runtimeContext = self.helper(runner) runtimeContext.name = "test_timelimit" - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) arvtool.formatgraph = None for j in arvtool.job({}, mock.MagicMock(), runtimeContext): @@ -824,12 +868,375 @@ class TestContainer(unittest.TestCase): self.assertEqual(42, kwargs['body']['scheduling_parameters'].get('max_run_time')) + # The test passes no builder.resources + # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} + @mock.patch("arvados.commands.keepdocker.list_images_in_arv") + def test_setting_storage_class(self, keepdocker): + arv_docker_clear_cache() + + runner = mock.MagicMock() + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} + + keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] + runner.api.collections().get().execute.return_value = { + "portable_data_hash": "99999999999999999999999999999993+99"} + + tool = cmap({ + "inputs": [], + "outputs": [], + "baseCommand": "ls", + "arguments": [{"valueFrom": "$(runtime.outdir)"}], + "id": "", + "cwlVersion": "v1.2", + "class": "CommandLineTool", + "hints": [ + { + "class": "http://arvados.org/cwl#OutputStorageClass", + "finalStorageClass": ["baz_sc", "qux_sc"], + "intermediateStorageClass": ["foo_sc", "bar_sc"] + } + ] + }) + + loadingContext, runtimeContext = self.helper(runner, True) + + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) + arvtool.formatgraph = None + + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + runner.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher({ + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_run_True', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 268435456 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 + }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_run_True', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': '99999999999999999999999999999993+99', + 'command': ['ls', '/var/spool/cwl'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + 'secret_mounts': {}, + 'output_storage_classes': ["foo_sc", "bar_sc"] + })) + + + # The test passes no builder.resources + # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} + @mock.patch("arvados.commands.keepdocker.list_images_in_arv") + def test_setting_process_properties(self, keepdocker): + arv_docker_clear_cache() + + runner = mock.MagicMock() + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} + + keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] + runner.api.collections().get().execute.return_value = { + "portable_data_hash": "99999999999999999999999999999993+99"} + + tool = cmap({ + "inputs": [ + {"id": "x", "type": "string"}], + "outputs": [], + "baseCommand": "ls", + "arguments": [{"valueFrom": "$(runtime.outdir)"}], + "id": "", + "class": "CommandLineTool", + "cwlVersion": "v1.2", + "hints": [ + { + "class": "http://arvados.org/cwl#ProcessProperties", + "processProperties": [ + {"propertyName": "foo", + "propertyValue": "bar"}, + {"propertyName": "baz", + "propertyValue": "$(inputs.x)"}, + {"propertyName": "quux", + "propertyValue": { + "q1": 1, + "q2": 2 + } + } + ], + } + ] + }) + + loadingContext, runtimeContext = self.helper(runner, True) + + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) + arvtool.formatgraph = None + + for j in arvtool.job({"x": "blorp"}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + runner.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher({ + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_run_True', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 268435456 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 + }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_run_True', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': '99999999999999999999999999999993+99', + 'command': ['ls', '/var/spool/cwl'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': { + "baz": "blorp", + "foo": "bar", + "quux": { + "q1": 1, + "q2": 2 + } + }, + 'secret_mounts': {}, + 'output_storage_classes': ["default"] + })) + + + # The test passes no builder.resources + # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} + @mock.patch("arvados.commands.keepdocker.list_images_in_arv") + def test_cuda_requirement(self, keepdocker): + arvados_cwl.add_arv_hints() + arv_docker_clear_cache() + + runner = mock.MagicMock() + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} + + keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] + runner.api.collections().get().execute.return_value = { + "portable_data_hash": "99999999999999999999999999999993+99"} + + test_cwl_req = [{ + "class": "http://commonwl.org/cwltool#CUDARequirement", + "cudaVersionMin": "11.0", + "cudaComputeCapability": "9.0", + }, { + "class": "http://commonwl.org/cwltool#CUDARequirement", + "cudaVersionMin": "11.0", + "cudaComputeCapability": "9.0", + "cudaDeviceCountMin": 2 + }, { + "class": "http://commonwl.org/cwltool#CUDARequirement", + "cudaVersionMin": "11.0", + "cudaComputeCapability": ["4.0", "5.0"], + "cudaDeviceCountMin": 2 + }] + + test_arv_req = [{ + 'device_count': 1, + 'driver_version': "11.0", + 'hardware_capability': "9.0" + }, { + 'device_count': 2, + 'driver_version': "11.0", + 'hardware_capability': "9.0" + }, { + 'device_count': 2, + 'driver_version': "11.0", + 'hardware_capability': "4.0" + }] + + for test_case in range(0, len(test_cwl_req)): + + tool = cmap({ + "inputs": [], + "outputs": [], + "baseCommand": "nvidia-smi", + "arguments": [], + "id": "", + "cwlVersion": "v1.2", + "class": "CommandLineTool", + "requirements": [test_cwl_req[test_case]] + }) + + loadingContext, runtimeContext = self.helper(runner, True) + + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) + arvtool.formatgraph = None + + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + runner.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher({ + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_run_True' + ("" if test_case == 0 else "_"+str(test_case+1)), + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 268435456, + 'cuda': test_arv_req[test_case] + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 + }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_run_True' + ("" if test_case == 0 else "_"+str(test_case+1)), + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': '99999999999999999999999999999993+99', + 'command': ['nvidia-smi'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + 'secret_mounts': {}, + 'output_storage_classes': ["default"] + })) + + + # The test passes no builder.resources + # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024} + @mock.patch("arvados_cwl.arvdocker.determine_image_id") + @mock.patch("arvados.commands.keepdocker.list_images_in_arv") + def test_match_local_docker(self, keepdocker, determine_image_id): + arvados_cwl.add_arv_hints() + arv_docker_clear_cache() + + runner = mock.MagicMock() + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + runner.api._rootDesc = {"revision": "20210628"} + + keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz4", {"dockerhash": "456"}), + ("zzzzz-4zz18-zzzzzzzzzzzzzz3", {"dockerhash": "123"})] + determine_image_id.side_effect = lambda x: "123" + def execute(uuid): + ex = mock.MagicMock() + lookup = {"zzzzz-4zz18-zzzzzzzzzzzzzz4": {"portable_data_hash": "99999999999999999999999999999994+99"}, + "zzzzz-4zz18-zzzzzzzzzzzzzz3": {"portable_data_hash": "99999999999999999999999999999993+99"}} + ex.execute.return_value = lookup[uuid] + return ex + runner.api.collections().get.side_effect = execute + + tool = cmap({ + "inputs": [], + "outputs": [], + "baseCommand": "echo", + "arguments": [], + "id": "", + "cwlVersion": "v1.2", + "class": "CommandLineTool" + }) + + loadingContext, runtimeContext = self.helper(runner, True) + + arvtool = cwltool.load_tool.load_tool(tool, loadingContext) + arvtool.formatgraph = None + + container_request = { + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_run_True', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 268435456 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 + }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_run_True', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': '99999999999999999999999999999994+99', + 'command': ['echo'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + 'secret_mounts': {}, + 'output_storage_classes': ["default"] + } + + runtimeContext.match_local_docker = False + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + runner.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(container_request)) + + arv_docker_clear_cache() + runtimeContext.match_local_docker = True + container_request['container_image'] = '99999999999999999999999999999993+99' + container_request['name'] = 'test_run_True_2' + container_request['output_name'] = 'Output for step test_run_True_2' + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + runner.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(container_request)) + + + class TestWorkflow(unittest.TestCase): def setUp(self): cwltool.process._names = set() + arv_docker_clear_cache() def helper(self, runner, enable_reuse=True): - document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.1") + document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0") make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, collection_cache=arvados_cwl.CollectionCache(runner.api, None, 0)) @@ -844,7 +1251,7 @@ class TestWorkflow(unittest.TestCase): "basedir": "", "make_fs_access": make_fs_access, "loader": document_loader, - "metadata": {"cwlVersion": "v1.1", "http://commonwl.org/cwltool#original_cwlVersion": "v1.0"}, + "metadata": {"cwlVersion": INTERNAL_VERSION, "http://commonwl.org/cwltool#original_cwlVersion": "v1.0"}, "construct_tool_object": runner.arv_make_tool}) runtimeContext = arvados_cwl.context.ArvRuntimeContext( {"work_api": "containers", @@ -863,7 +1270,6 @@ class TestWorkflow(unittest.TestCase): @mock.patch("arvados.collection.Collection") @mock.patch('arvados.commands.keepdocker.list_images_in_arv') def test_run(self, list_images_in_arv, mockcollection, mockcollectionreader): - arv_docker_clear_cache() arvados_cwl.add_arv_hints() api = mock.MagicMock() @@ -885,6 +1291,8 @@ class TestWorkflow(unittest.TestCase): loadingContext, runtimeContext = self.helper(runner) runner.fs_access = runtimeContext.make_fs_access(runtimeContext.basedir) + mockcollectionreader().exists.return_value = True + tool, metadata = loadingContext.loader.resolve_ref("tests/wf/scatter2.cwl") metadata["cwlVersion"] = tool["cwlVersion"] @@ -909,7 +1317,7 @@ class TestWorkflow(unittest.TestCase): "--no-container", "--move-outputs", "--preserve-entire-environment", - "workflow.cwl#main", + "workflow.cwl", "cwl.input.yml" ], "container_image": "99999999999999999999999999999993+99", @@ -959,7 +1367,8 @@ class TestWorkflow(unittest.TestCase): "scheduling_parameters": {}, "secret_mounts": {}, "state": "Committed", - "use_existing": True + "use_existing": True, + 'output_storage_classes': ["default"] })) mockc.open().__enter__().write.assert_has_calls([mock.call(subwf)]) mockc.open().__enter__().write.assert_has_calls([mock.call( @@ -979,7 +1388,6 @@ class TestWorkflow(unittest.TestCase): @mock.patch("arvados.collection.Collection") @mock.patch('arvados.commands.keepdocker.list_images_in_arv') def test_overall_resource_singlecontainer(self, list_images_in_arv, mockcollection, mockcollectionreader): - arv_docker_clear_cache() arvados_cwl.add_arv_hints() api = mock.MagicMock() @@ -1057,12 +1465,13 @@ class TestWorkflow(unittest.TestCase): u'--no-container', u'--move-outputs', u'--preserve-entire-environment', - u'workflow.cwl#main', + u'workflow.cwl', u'cwl.input.yml' ], 'use_existing': True, 'output_name': u'Output for step echo-subwf', - 'cwd': '/var/spool/cwl' + 'cwd': '/var/spool/cwl', + 'output_storage_classes': ["default"] })) def test_default_work_api(self):