X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b77893f2a8ae755f22615054f2c267d990995e1c..94d277295c4a8d331622e4077ace1eb4570d54e5:/sdk/cwl/tests/test_container.py diff --git a/sdk/cwl/tests/test_container.py b/sdk/cwl/tests/test_container.py index ad69371605..3f8a32816d 100644 --- a/sdk/cwl/tests/test_container.py +++ b/sdk/cwl/tests/test_container.py @@ -1,4 +1,9 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + import arvados_cwl +import arvados_cwl.context from arvados_cwl.arvdocker import arv_docker_clear_cache import logging import mock @@ -6,6 +11,7 @@ import unittest import os import functools import cwltool.process +import cwltool.secrets from schema_salad.ref_resolver import Loader from schema_salad.sourceline import cmap @@ -15,9 +21,30 @@ if not os.getenv('ARVADOS_DEBUG'): logging.getLogger('arvados.cwl-runner').setLevel(logging.WARN) logging.getLogger('arvados.arv-run').setLevel(logging.WARN) - class TestContainer(unittest.TestCase): + def helper(self, runner, enable_reuse=True): + 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)) + loadingContext = arvados_cwl.context.ArvLoadingContext( + {"avsc_names": avsc_names, + "basedir": "", + "make_fs_access": make_fs_access, + "loader": Loader({}), + "metadata": {"cwlVersion": "v1.0"}}) + runtimeContext = arvados_cwl.context.ArvRuntimeContext( + {"work_api": "containers", + "basedir": "", + "name": "test_run_"+str(enable_reuse), + "make_fs_access": make_fs_access, + "tmpdir": "/tmp", + "enable_reuse": enable_reuse, + "priority": 500}) + + return loadingContext, runtimeContext + # 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") @@ -28,26 +55,29 @@ class TestContainer(unittest.TestCase): runner = mock.MagicMock() runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() 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.0") - tool = cmap({ "inputs": [], "outputs": [], "baseCommand": "ls", - "arguments": [{"valueFrom": "$(runtime.outdir)"}] + "arguments": [{"valueFrom": "$(runtime.outdir)"}], + "id": "#", + "class": "CommandLineTool" }) - make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, api_client=runner.api) - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="containers", avsc_names=avsc_names, - basedir="", make_fs_access=make_fs_access, loader=Loader({})) + + loadingContext, runtimeContext = self.helper(runner, enable_reuse) + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) arvtool.formatgraph = None - for j in arvtool.job({}, mock.MagicMock(), basedir="", name="test_run_"+str(enable_reuse), - make_fs_access=make_fs_access, tmpdir="/tmp"): - j.run(enable_reuse=enable_reuse) + + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) runner.api.container_requests().create.assert_called_with( body=JsonDiffMatcher({ 'environment': { @@ -60,18 +90,25 @@ class TestContainer(unittest.TestCase): 'ram': 1073741824 }, 'use_existing': enable_reuse, - 'priority': 1, + 'priority': 500, 'mounts': { - '/var/spool/cwl': {'kind': 'tmp'} + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 + }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } }, 'state': 'Committed', + 'output_name': 'Output for step test_run_'+str(enable_reuse), 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', 'output_path': '/var/spool/cwl', + 'output_ttl': 0, 'container_image': 'arvados/jobs', 'command': ['ls', '/var/spool/cwl'], 'cwd': '/var/spool/cwl', 'scheduling_parameters': {}, 'properties': {}, + 'secret_mounts': {} })) # The test passes some fields in builder.resources @@ -82,7 +119,8 @@ class TestContainer(unittest.TestCase): runner = mock.MagicMock() runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" runner.ignore_docker_for_reuse = False - document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0") + runner.intermediate_output_ttl = 3600 + runner.secret_store = cwltool.secrets.SecretStore() keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -95,7 +133,8 @@ class TestContainer(unittest.TestCase): "class": "ResourceRequirement", "coresMin": 3, "ramMin": 3000, - "tmpdirMin": 4000 + "tmpdirMin": 4000, + "outdirMin": 5000 }, { "class": "http://arvados.org/cwl#RuntimeConstraints", "keep_cache": 512 @@ -104,47 +143,61 @@ class TestContainer(unittest.TestCase): }, { "class": "http://arvados.org/cwl#PartitionRequirement", "partition": "blurb" + }, { + "class": "http://arvados.org/cwl#IntermediateOutput", + "outputTTL": 7200 + }, { + "class": "http://arvados.org/cwl#ReuseRequirement", + "enableReuse": False }], - "baseCommand": "ls" + "baseCommand": "ls", + "id": "#", + "class": "CommandLineTool" }) - make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, api_client=runner.api) - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="containers", - avsc_names=avsc_names, make_fs_access=make_fs_access, - loader=Loader({})) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_resource_requirements" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) arvtool.formatgraph = None - for j in arvtool.job({}, mock.MagicMock(), basedir="", name="test_resource_requirements", - make_fs_access=make_fs_access, tmpdir="/tmp"): - j.run() + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) call_args, call_kwargs = runner.api.container_requests().create.call_args call_body_expected = { - 'environment': { - 'HOME': '/var/spool/cwl', - 'TMPDIR': '/tmp' - }, - 'name': 'test_resource_requirements', - 'runtime_constraints': { - 'vcpus': 3, - 'ram': 3145728000, - 'keep_cache_ram': 536870912, - 'API': True - }, - 'use_existing': True, - 'priority': 1, - 'mounts': { - '/var/spool/cwl': {'kind': 'tmp'} - }, - 'state': 'Committed', - 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', - 'output_path': '/var/spool/cwl', - 'container_image': 'arvados/jobs', - 'command': ['ls'], - 'cwd': '/var/spool/cwl', - 'scheduling_parameters': { - 'partitions': ['blurb'] - }, - 'properties': {} + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_resource_requirements', + 'runtime_constraints': { + 'vcpus': 3, + 'ram': 3145728000, + 'keep_cache_ram': 536870912, + 'API': True + }, + 'use_existing': False, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 4194304000 }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 5242880000 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_resource_requirements', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 7200, + 'container_image': 'arvados/jobs', + 'command': ['ls'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': { + 'partitions': ['blurb'] + }, + 'properties': {}, + 'secret_mounts': {} } call_body = call_kwargs.get('body', None) @@ -162,7 +215,8 @@ class TestContainer(unittest.TestCase): runner = mock.MagicMock() runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" runner.ignore_docker_for_reuse = False - document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0") + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] runner.api.collections().get().execute.return_value = { @@ -206,16 +260,18 @@ class TestContainer(unittest.TestCase): "location": "keep:99999999999999999999999999999995+99/subdir" } ] }], - "baseCommand": "ls" + "baseCommand": "ls", + "id": "#", + "class": "CommandLineTool" }) - make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, api_client=runner.api) - arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="containers", - avsc_names=avsc_names, make_fs_access=make_fs_access, - loader=Loader({})) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_initial_work_dir" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) arvtool.formatgraph = None - for j in arvtool.job({}, mock.MagicMock(), basedir="", name="test_initial_work_dir", - make_fs_access=make_fs_access, tmpdir="/tmp"): - j.run() + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) call_args, call_kwargs = runner.api.container_requests().create.call_args @@ -225,49 +281,55 @@ class TestContainer(unittest.TestCase): vwdmock.copy.assert_has_calls([mock.call('subdir', 'subdir', source_collection=sourcemock)]) call_body_expected = { - 'environment': { - 'HOME': '/var/spool/cwl', - 'TMPDIR': '/tmp' + 'environment': { + 'HOME': '/var/spool/cwl', + 'TMPDIR': '/tmp' + }, + 'name': 'test_initial_work_dir', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 1073741824 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 }, + '/var/spool/cwl/foo': { + 'kind': 'collection', + 'path': 'foo', + 'portable_data_hash': '99999999999999999999999999999996+99' }, - 'name': 'test_initial_work_dir', - 'runtime_constraints': { - 'vcpus': 1, - 'ram': 1073741824 - }, - 'use_existing': True, - 'priority': 1, - 'mounts': { - '/var/spool/cwl': {'kind': 'tmp'}, - '/var/spool/cwl/foo': { - 'kind': 'collection', - 'path': 'foo', - 'portable_data_hash': '99999999999999999999999999999996+99' - }, - '/var/spool/cwl/foo2': { - 'kind': 'collection', - 'path': 'foo2', - 'portable_data_hash': '99999999999999999999999999999996+99' - }, - '/var/spool/cwl/filename': { - 'kind': 'collection', - 'path': 'filename', - 'portable_data_hash': '99999999999999999999999999999996+99' - }, - '/var/spool/cwl/subdir': { - 'kind': 'collection', - 'path': 'subdir', - 'portable_data_hash': '99999999999999999999999999999996+99' - } + '/var/spool/cwl/foo2': { + 'kind': 'collection', + 'path': 'foo2', + 'portable_data_hash': '99999999999999999999999999999996+99' }, - 'state': 'Committed', - 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', - 'output_path': '/var/spool/cwl', - 'container_image': 'arvados/jobs', - 'command': ['ls'], - 'cwd': '/var/spool/cwl', - 'scheduling_parameters': { + '/var/spool/cwl/filename': { + 'kind': 'collection', + 'path': 'filename', + 'portable_data_hash': '99999999999999999999999999999996+99' }, - 'properties': {} + '/var/spool/cwl/subdir': { + 'kind': 'collection', + 'path': 'subdir', + 'portable_data_hash': '99999999999999999999999999999996+99' + } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_initial_work_dir', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': 'arvados/jobs', + 'command': ['ls'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': { + }, + 'properties': {}, + 'secret_mounts': {} } call_body = call_kwargs.get('body', None) @@ -275,6 +337,88 @@ class TestContainer(unittest.TestCase): for key in call_body: self.assertEqual(call_body_expected.get(key), call_body.get(key)) + + # 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.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + + 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.0") + + tool = cmap({ + "inputs": [], + "outputs": [], + "baseCommand": "ls", + "stdout": "stdout.txt", + "stderr": "stderr.txt", + "stdin": "/keep/99999999999999999999999999999996+99/file.txt", + "arguments": [{"valueFrom": "$(runtime.outdir)"}], + "id": "#", + "class": "CommandLineTool" + }) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_run_redirect" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, 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_redirect', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 1073741824 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 }, + "stderr": { + "kind": "file", + "path": "/var/spool/cwl/stderr.txt" + }, + "stdin": { + "kind": "collection", + "path": "file.txt", + "portable_data_hash": "99999999999999999999999999999996+99" + }, + "stdout": { + "kind": "file", + "path": "/var/spool/cwl/stdout.txt" + }, + }, + 'state': 'Committed', + "output_name": "Output for step test_run_redirect", + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': 'arvados/jobs', + 'command': ['ls', '/var/spool/cwl'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + 'secret_mounts': {} + })) + @mock.patch("arvados.collection.Collection") def test_done(self, col): api = mock.MagicMock() @@ -284,6 +428,8 @@ class TestContainer(unittest.TestCase): runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" runner.num_retries = 0 runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() runner.api.containers().get().execute.return_value = {"state":"Complete", "output": "abc+123", @@ -291,13 +437,18 @@ class TestContainer(unittest.TestCase): col().open.return_value = [] - arvjob = arvados_cwl.ArvadosContainer(runner) - arvjob.name = "testjob" - arvjob.builder = mock.MagicMock() + arvjob = arvados_cwl.ArvadosContainer(runner, + mock.MagicMock(), + {}, + None, + [], + [], + "testjob") arvjob.output_callback = mock.MagicMock() arvjob.collect_outputs = mock.MagicMock() arvjob.successCodes = [0] arvjob.outdir = "/var/spool/cwl" + arvjob.output_ttl = 3600 arvjob.collect_outputs.return_value = {"out": "stuff"} @@ -306,10 +457,243 @@ class TestContainer(unittest.TestCase): "log_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1", "output_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2", "uuid": "zzzzz-xvhdp-zzzzzzzzzzzzzzz", - "container_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz" + "container_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz", + "modified_at": "2017-05-26T12:01:22Z" }) self.assertFalse(api.collections().create.called) arvjob.collect_outputs.assert_called_with("keep:abc+123") arvjob.output_callback.assert_called_with({"out": "stuff"}, "success") + runner.add_intermediate_output.assert_called_with("zzzzz-4zz18-zzzzzzzzzzzzzz2") + + # 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_mounts(self, keepdocker): + arv_docker_clear_cache() + + runner = mock.MagicMock() + runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + + keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")] + runner.api.collections().get().execute.return_value = { + "portable_data_hash": "99999999999999999999999999999994+99", + "manifest_text": ". 99999999999999999999999999999994+99 0:0:file1 0:0:file2"} + + document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0") + + tool = cmap({ + "inputs": [ + {"id": "p1", + "type": "Directory"} + ], + "outputs": [], + "baseCommand": "ls", + "arguments": [{"valueFrom": "$(runtime.outdir)"}], + "id": "#", + "class": "CommandLineTool" + }) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_run_mounts" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool.formatgraph = None + job_order = { + "p1": { + "class": "Directory", + "location": "keep:99999999999999999999999999999994+44", + "listing": [ + { + "class": "File", + "location": "keep:99999999999999999999999999999994+44/file1", + }, + { + "class": "File", + "location": "keep:99999999999999999999999999999994+44/file2", + } + ] + } + } + for j in arvtool.job(job_order, 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_mounts', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 1073741824 + }, + 'use_existing': True, + 'priority': 500, + 'mounts': { + "/keep/99999999999999999999999999999994+44": { + "kind": "collection", + "portable_data_hash": "99999999999999999999999999999994+44" + }, + '/tmp': {'kind': 'tmp', + "capacity": 1073741824 }, + '/var/spool/cwl': {'kind': 'tmp', + "capacity": 1073741824 } + }, + 'state': 'Committed', + 'output_name': 'Output for step test_run_mounts', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': 'arvados/jobs', + 'command': ['ls', '/var/spool/cwl'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + 'secret_mounts': {} + })) + + # 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() + + runner = mock.MagicMock() + runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + + 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.0") + + tool = cmap({"arguments": ["md5sum", "example.conf"], + "class": "CommandLineTool", + "hints": [ + { + "class": "http://commonwl.org/cwltool#Secrets", + "secrets": [ + "#secret_job.cwl/pw" + ] + } + ], + "id": "#secret_job.cwl", + "inputs": [ + { + "id": "#secret_job.cwl/pw", + "type": "string" + } + ], + "outputs": [ + ], + "requirements": [ + { + "class": "InitialWorkDirRequirement", + "listing": [ + { + "entry": "username: user\npassword: $(inputs.pw)\n", + "entryname": "example.conf" + } + ] + } + ]}) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_secrets" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool.formatgraph = None + + job_order = {"pw": "blorp"} + runner.secret_store.store(["pw"], job_order) + + for j in arvtool.job(job_order, 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_secrets', + 'runtime_constraints': { + 'vcpus': 1, + 'ram': 1073741824 + }, + '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_secrets', + 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz', + 'output_path': '/var/spool/cwl', + 'output_ttl': 0, + 'container_image': 'arvados/jobs', + 'command': ['md5sum', 'example.conf'], + 'cwd': '/var/spool/cwl', + 'scheduling_parameters': {}, + 'properties': {}, + "secret_mounts": { + "/var/spool/cwl/example.conf": { + "content": "username: user\npassword: blorp\n", + "kind": "text" + } + } + })) + + # 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.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz" + runner.ignore_docker_for_reuse = False + runner.intermediate_output_ttl = 0 + runner.secret_store = cwltool.secrets.SecretStore() + + 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": "#", + "class": "CommandLineTool", + "hints": [ + { + "class": "http://commonwl.org/cwltool#TimeLimit", + "timelimit": 42 + } + ] + }) + + loadingContext, runtimeContext = self.helper(runner) + runtimeContext.name = "test_timelimit" + + arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext) + arvtool.formatgraph = None + + for j in arvtool.job({}, mock.MagicMock(), runtimeContext): + j.run(runtimeContext) + + _, kwargs = runner.api.container_requests().create.call_args + self.assertEqual(42, kwargs['body']['scheduling_parameters'].get('max_run_time'))