1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
6 import arvados_cwl.context
7 import arvados_cwl.util
8 #from arvados_cwl.arvdocker import arv_docker_clear_cache
16 import cwltool.process
17 import cwltool.secrets
18 import cwltool.load_tool
19 from cwltool.update import INTERNAL_VERSION
20 from schema_salad.ref_resolver import Loader
21 from schema_salad.sourceline import cmap
24 from unittest import mock
26 from .matcher import JsonDiffMatcher, StripYAMLComments
27 from .mock_discovery import get_rootDesc
29 if not os.getenv('ARVADOS_DEBUG'):
30 logging.getLogger('arvados.cwl-runner').setLevel(logging.WARN)
31 logging.getLogger('arvados.arv-run').setLevel(logging.WARN)
33 class CollectionMock(object):
34 def __init__(self, vwdmock, *args, **kwargs):
35 self.vwdmock = vwdmock
38 def open(self, *args, **kwargs):
40 return self.vwdmock.open(*args, **kwargs)
42 def copy(self, *args, **kwargs):
44 self.vwdmock.copy(*args, **kwargs)
46 def save_new(self, *args, **kwargs):
52 def portable_data_hash(self):
54 return arvados.config.EMPTY_BLOCK_LOCATOR
56 return "99999999999999999999999999999996+99"
59 class TestContainer(unittest.TestCase):
62 cwltool.process._names = set()
63 #arv_docker_clear_cache()
66 root_logger = logging.getLogger('')
68 # Remove existing RuntimeStatusLoggingHandlers if they exist
69 handlers = [h for h in root_logger.handlers if not isinstance(h, arvados_cwl.executor.RuntimeStatusLoggingHandler)]
70 root_logger.handlers = handlers
72 def helper(self, runner, enable_reuse=True):
73 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema(INTERNAL_VERSION)
75 make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess,
76 collection_cache=arvados_cwl.CollectionCache(runner.api, None, 0))
77 fs_access = mock.MagicMock()
78 fs_access.exists.return_value = True
80 loadingContext = arvados_cwl.context.ArvLoadingContext(
81 {"avsc_names": avsc_names,
83 "make_fs_access": make_fs_access,
84 "construct_tool_object": runner.arv_make_tool,
85 "fetcher_constructor": functools.partial(arvados_cwl.CollectionFetcher, api_client=runner.api, fs_access=fs_access),
87 "metadata": cmap({"cwlVersion": INTERNAL_VERSION, "http://commonwl.org/cwltool#original_cwlVersion": "v1.0"}),
88 "default_docker_image": "arvados/jobs:"+arvados_cwl.__version__
90 runtimeContext = arvados_cwl.context.ArvRuntimeContext(
91 {"work_api": "containers",
93 "name": "test_run_"+str(enable_reuse),
94 "make_fs_access": make_fs_access,
97 "enable_reuse": enable_reuse,
99 "project_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
100 "workflow_eval_lock": threading.Condition(threading.RLock())
103 if isinstance(runner, mock.MagicMock):
104 def make_tool(toolpath_object, loadingContext):
105 return arvados_cwl.ArvadosCommandTool(runner, toolpath_object, loadingContext)
106 runner.arv_make_tool.side_effect = make_tool
108 return loadingContext, runtimeContext
110 # Helper function to set up the ArvCwlExecutor to use the containers api
111 # and test that the RuntimeStatusLoggingHandler is set up correctly
112 def setup_and_test_container_executor_and_logging(self, gcc_mock) :
113 api = mock.MagicMock()
114 api._rootDesc = copy.deepcopy(get_rootDesc())
116 # Make sure ArvCwlExecutor thinks it's running inside a container so it
117 # adds the logging handler that will call runtime_status_update() mock
118 self.assertFalse(gcc_mock.called)
119 runner = arvados_cwl.ArvCwlExecutor(api)
120 self.assertEqual(runner.work_api, 'containers')
121 root_logger = logging.getLogger('')
122 handlerClasses = [h.__class__ for h in root_logger.handlers]
123 self.assertTrue(arvados_cwl.RuntimeStatusLoggingHandler in handlerClasses)
126 # The test passes no builder.resources
127 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
128 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
129 def test_run(self, keepdocker):
130 for enable_reuse in (True, False):
131 #arv_docker_clear_cache()
133 runner = mock.MagicMock()
134 runner.ignore_docker_for_reuse = False
135 runner.intermediate_output_ttl = 0
136 runner.secret_store = cwltool.secrets.SecretStore()
137 runner.api._rootDesc = {"revision": "20210628"}
138 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
140 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
141 runner.api.collections().get().execute.return_value = {
142 "portable_data_hash": "99999999999999999999999999999993+99"}
148 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
150 "class": "CommandLineTool",
154 loadingContext, runtimeContext = self.helper(runner, enable_reuse)
156 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
157 arvtool.formatgraph = None
159 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
160 j.run(runtimeContext)
161 runner.api.container_requests().create.assert_called_with(
162 body=JsonDiffMatcher({
164 'HOME': '/var/spool/cwl',
167 'name': 'test_run_'+str(enable_reuse),
168 'runtime_constraints': {
172 'use_existing': enable_reuse,
175 '/tmp': {'kind': 'tmp',
176 "capacity": 1073741824
178 '/var/spool/cwl': {'kind': 'tmp',
179 "capacity": 1073741824 }
181 'state': 'Committed',
182 'output_name': 'Output from step test_run_'+str(enable_reuse),
183 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
184 'output_path': '/var/spool/cwl',
186 'container_image': '99999999999999999999999999999993+99',
187 'command': ['ls', '/var/spool/cwl'],
188 'cwd': '/var/spool/cwl',
189 'scheduling_parameters': {},
190 'properties': {'cwl_input': {}},
192 'output_storage_classes': ["default"]
195 # The test passes some fields in builder.resources
196 # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
197 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
198 def test_resource_requirements(self, keepdocker):
199 arvados_cwl.add_arv_hints()
200 runner = mock.MagicMock()
201 runner.ignore_docker_for_reuse = False
202 runner.intermediate_output_ttl = 3600
203 runner.secret_store = cwltool.secrets.SecretStore()
204 runner.api._rootDesc = {"revision": "20210628"}
205 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
207 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
208 runner.api.collections().get().execute.return_value = {
209 "portable_data_hash": "99999999999999999999999999999993+99"}
215 "class": "ResourceRequirement",
221 "class": "http://arvados.org/cwl#RuntimeConstraints",
224 "class": "http://arvados.org/cwl#APIRequirement",
226 "class": "http://arvados.org/cwl#PartitionRequirement",
229 "class": "http://arvados.org/cwl#IntermediateOutput",
232 "class": "WorkReuse",
237 "class": "CommandLineTool",
241 loadingContext, runtimeContext = self.helper(runner)
242 runtimeContext.name = "test_resource_requirements"
244 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
245 arvtool.formatgraph = None
246 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
247 j.run(runtimeContext)
249 call_args, call_kwargs = runner.api.container_requests().create.call_args
251 call_body_expected = {
253 'HOME': '/var/spool/cwl',
256 'name': 'test_resource_requirements',
257 'runtime_constraints': {
260 'keep_cache_ram': 536870912,
263 'use_existing': False,
266 '/tmp': {'kind': 'tmp',
267 "capacity": 4194304000 },
268 '/var/spool/cwl': {'kind': 'tmp',
269 "capacity": 5242880000 }
271 'state': 'Committed',
272 'output_name': 'Output from step test_resource_requirements',
273 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
274 'output_path': '/var/spool/cwl',
276 'container_image': '99999999999999999999999999999993+99',
278 'cwd': '/var/spool/cwl',
279 'scheduling_parameters': {
280 'partitions': ['blurb']
282 'properties': {'cwl_input': {}},
284 'output_storage_classes': ["default"]
287 call_body = call_kwargs.get('body', None)
288 self.assertNotEqual(None, call_body)
289 for key in call_body:
290 self.assertEqual(call_body_expected.get(key), call_body.get(key))
293 # The test passes some fields in builder.resources
294 # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
295 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
296 @mock.patch("arvados.collection.Collection")
297 def test_initial_work_dir(self, collection_mock, keepdocker):
298 runner = mock.MagicMock()
299 runner.ignore_docker_for_reuse = False
300 runner.intermediate_output_ttl = 0
301 runner.secret_store = cwltool.secrets.SecretStore()
302 runner.api._rootDesc = {"revision": "20210628"}
303 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
305 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
306 runner.api.collections().get().execute.return_value = {
307 "portable_data_hash": "99999999999999999999999999999993+99"}
309 sourcemock = mock.MagicMock()
310 def get_collection_mock(p):
312 return (sourcemock, p.split("/", 1)[1])
314 return (sourcemock, "")
315 runner.fs_access.get_collection.side_effect = get_collection_mock
317 vwdmock = mock.MagicMock()
318 collection_mock.side_effect = lambda *args, **kwargs: CollectionMock(vwdmock, *args, **kwargs)
324 "class": "InitialWorkDirRequirement",
328 "location": "keep:99999999999999999999999999999995+99/bar"
331 "class": "Directory",
333 "location": "keep:99999999999999999999999999999995+99"
337 "basename": "filename",
338 "location": "keep:99999999999999999999999999999995+99/baz/filename"
341 "class": "Directory",
342 "basename": "subdir",
343 "location": "keep:99999999999999999999999999999995+99/subdir"
347 "class": "CommandLineTool",
348 "cwlVersion": "v1.2",
352 loadingContext, runtimeContext = self.helper(runner)
353 runtimeContext.name = "test_initial_work_dir"
355 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
357 arvtool.formatgraph = None
358 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
359 j.run(runtimeContext)
361 call_args, call_kwargs = runner.api.container_requests().create.call_args
363 vwdmock.copy.assert_has_calls([mock.call('bar', 'foo', source_collection=sourcemock)])
364 vwdmock.copy.assert_has_calls([mock.call('.', 'foo2', source_collection=sourcemock)])
365 vwdmock.copy.assert_has_calls([mock.call('baz/filename', 'filename', source_collection=sourcemock)])
366 vwdmock.copy.assert_has_calls([mock.call('subdir', 'subdir', source_collection=sourcemock)])
368 call_body_expected = {
370 'HOME': '/var/spool/cwl',
373 'name': 'test_initial_work_dir',
374 'runtime_constraints': {
378 'use_existing': True,
381 '/tmp': {'kind': 'tmp',
382 "capacity": 1073741824 },
383 '/var/spool/cwl': {'kind': 'tmp',
384 "capacity": 1073741824 },
385 '/var/spool/cwl/foo': {
386 'kind': 'collection',
388 'portable_data_hash': '99999999999999999999999999999996+99'
390 '/var/spool/cwl/foo2': {
391 'kind': 'collection',
393 'portable_data_hash': '99999999999999999999999999999996+99'
395 '/var/spool/cwl/filename': {
396 'kind': 'collection',
398 'portable_data_hash': '99999999999999999999999999999996+99'
400 '/var/spool/cwl/subdir': {
401 'kind': 'collection',
403 'portable_data_hash': '99999999999999999999999999999996+99'
406 'state': 'Committed',
407 'output_name': 'Output from step test_initial_work_dir',
408 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
409 'output_path': '/var/spool/cwl',
411 'container_image': '99999999999999999999999999999993+99',
413 'cwd': '/var/spool/cwl',
414 'scheduling_parameters': {
416 'properties': {'cwl_input': {}},
418 'output_storage_classes': ["default"]
421 call_body = call_kwargs.get('body', None)
422 self.assertNotEqual(None, call_body)
423 for key in call_body:
424 self.assertEqual(call_body_expected.get(key), call_body.get(key))
427 # Test redirecting stdin/stdout/stderr
428 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
429 def test_redirects(self, keepdocker):
430 runner = mock.MagicMock()
431 runner.ignore_docker_for_reuse = False
432 runner.intermediate_output_ttl = 0
433 runner.secret_store = cwltool.secrets.SecretStore()
434 runner.api._rootDesc = {"revision": "20210628"}
435 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
437 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
438 runner.api.collections().get().execute.return_value = {
439 "portable_data_hash": "99999999999999999999999999999993+99"}
441 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema(INTERNAL_VERSION)
447 "stdout": "stdout.txt",
448 "stderr": "stderr.txt",
449 "stdin": "/keep/99999999999999999999999999999996+99/file.txt",
450 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
452 "class": "CommandLineTool",
456 loadingContext, runtimeContext = self.helper(runner)
457 runtimeContext.name = "test_run_redirect"
459 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
460 arvtool.formatgraph = None
461 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
462 j.run(runtimeContext)
463 runner.api.container_requests().create.assert_called_with(
464 body=JsonDiffMatcher({
466 'HOME': '/var/spool/cwl',
469 'name': 'test_run_redirect',
470 'runtime_constraints': {
474 'use_existing': True,
477 '/tmp': {'kind': 'tmp',
478 "capacity": 1073741824 },
479 '/var/spool/cwl': {'kind': 'tmp',
480 "capacity": 1073741824 },
483 "path": "/var/spool/cwl/stderr.txt"
486 "kind": "collection",
488 "portable_data_hash": "99999999999999999999999999999996+99"
492 "path": "/var/spool/cwl/stdout.txt"
495 'state': 'Committed',
496 "output_name": "Output from step test_run_redirect",
497 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
498 'output_path': '/var/spool/cwl',
500 'container_image': '99999999999999999999999999999993+99',
501 'command': ['ls', '/var/spool/cwl'],
502 'cwd': '/var/spool/cwl',
503 'scheduling_parameters': {},
504 'properties': {'cwl_input': {}},
506 'output_storage_classes': ["default"]
509 @mock.patch("arvados.collection.Collection")
510 def test_done(self, col):
511 api = mock.MagicMock()
513 runner = mock.MagicMock()
515 runner.num_retries = 0
516 runner.ignore_docker_for_reuse = False
517 runner.intermediate_output_ttl = 0
518 runner.secret_store = cwltool.secrets.SecretStore()
520 runner.api.container_requests().get().execute.return_value = {"container_uuid":"zzzzz-xvhdp-zzzzzzzzzzzzzzz"}
522 runner.api.containers().get().execute.return_value = {"state":"Complete",
526 # Need to noop-out the close method otherwise it gets
527 # discarded when closed and we can't call getvalue() to check
529 class NoopCloseStringIO(io.StringIO):
533 usage_report = NoopCloseStringIO()
534 def colreader_action(name, mode):
535 nonlocal usage_report
536 if name == "node.json":
537 return io.StringIO("""{
538 "ProviderType": "c5.large",
541 "IncludedScratch": 8000000000000,
544 "Preemptible": false,
547 "HardwareCapability": "",
551 if name == 'crunchstat.txt':
552 return open("tests/container_request_9tee4-xvhdp-kk0ja1cl8b2kr1y-arv-mount.txt", "rt")
553 if name == 'arv-mount.txt':
554 return open("tests/container_request_9tee4-xvhdp-kk0ja1cl8b2kr1y-crunchstat.txt", "rt")
555 if name == 'usage_report.html':
559 col().open.side_effect = colreader_action
560 col().__iter__.return_value = ['node.json', 'crunchstat.txt', 'arv-mount.txt']
562 loadingContext, runtimeContext = self.helper(runner)
564 arvjob = arvados_cwl.ArvadosContainer(runner,
573 arvjob.output_callback = mock.MagicMock()
574 arvjob.collect_outputs = mock.MagicMock()
575 arvjob.successCodes = [0]
576 arvjob.outdir = "/var/spool/cwl"
577 arvjob.output_ttl = 3600
578 arvjob.uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzz1"
580 arvjob.collect_outputs.return_value = {"out": "stuff"}
584 "log_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
585 "output_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
586 "uuid": "zzzzz-xvhdp-zzzzzzzzzzzzzzz",
587 "container_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
588 "modified_at": "2017-05-26T12:01:22Z",
593 self.assertFalse(api.collections().create.called)
594 self.assertFalse(runner.runtime_status_error.called)
596 # Assert that something was written to the usage report
597 self.assertTrue(len(usage_report.getvalue()) > 0)
599 arvjob.collect_outputs.assert_called_with("keep:abc+123", 0)
600 arvjob.output_callback.assert_called_with({"out": "stuff"}, "success")
601 runner.add_intermediate_output.assert_called_with("zzzzz-4zz18-zzzzzzzzzzzzzz2")
603 runner.api.container_requests().update.assert_called_with(uuid="zzzzz-xvhdp-zzzzzzzzzzzzzz1",
604 body={'container_request': {'properties': {'cwl_output': {'out': 'stuff'}}}})
607 # Test to make sure we dont call runtime_status_update if we already did
608 # some where higher up in the call stack
609 @mock.patch("arvados_cwl.util.get_current_container")
610 def test_recursive_runtime_status_update(self, gcc_mock):
611 self.setup_and_test_container_executor_and_logging(gcc_mock)
612 root_logger = logging.getLogger('')
614 # get_current_container is invoked when we call runtime_status_update
615 # so try and log again!
616 gcc_mock.side_effect = lambda *args: root_logger.error("Second Error")
618 root_logger.error("First Error")
620 self.fail("RuntimeStatusLoggingHandler should not be called recursively")
623 # Test to make sure that an exception raised from
624 # get_current_container doesn't cause the logger to raise an
626 @mock.patch("arvados_cwl.util.get_current_container")
627 def test_runtime_status_get_current_container_exception(self, gcc_mock):
628 self.setup_and_test_container_executor_and_logging(gcc_mock)
629 root_logger = logging.getLogger('')
631 # get_current_container is invoked when we call
632 # runtime_status_update, it is going to also raise an
634 gcc_mock.side_effect = Exception("Second Error")
636 root_logger.error("First Error")
638 self.fail("Exception in logger should not propagate")
639 self.assertTrue(gcc_mock.called)
641 @mock.patch("arvados_cwl.ArvCwlExecutor.runtime_status_update")
642 @mock.patch("arvados_cwl.util.get_current_container")
643 @mock.patch("arvados.collection.CollectionReader")
644 @mock.patch("arvados.collection.Collection")
645 def test_child_failure(self, col, reader, gcc_mock, rts_mock):
646 runner = self.setup_and_test_container_executor_and_logging(gcc_mock)
648 gcc_mock.return_value = {"uuid" : "zzzzz-dz642-zzzzzzzzzzzzzzz"}
649 self.assertTrue(gcc_mock.called)
651 runner.num_retries = 0
652 runner.ignore_docker_for_reuse = False
653 runner.intermediate_output_ttl = 0
654 runner.secret_store = cwltool.secrets.SecretStore()
655 runner.label = mock.MagicMock()
656 runner.label.return_value = '[container testjob]'
658 runner.api.containers().get().execute.return_value = {
665 col().open.return_value = []
667 loadingContext, runtimeContext = self.helper(runner)
669 arvjob = arvados_cwl.ArvadosContainer(runner,
678 arvjob.output_callback = mock.MagicMock()
679 arvjob.collect_outputs = mock.MagicMock()
680 arvjob.successCodes = [0]
681 arvjob.outdir = "/var/spool/cwl"
682 arvjob.output_ttl = 3600
683 arvjob.collect_outputs.return_value = {"out": "stuff"}
687 "log_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
688 "output_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
689 "uuid": "zzzzz-xvhdp-zzzzzzzzzzzzzzz",
690 "container_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
691 "modified_at": "2017-05-26T12:01:22Z",
695 rts_mock.assert_has_calls([
697 'arvados.cwl-runner: [container testjob] (zzzzz-xvhdp-zzzzzzzzzzzzzzz) error log:',
698 ' ** log is empty **'
701 'arvados.cwl-runner: [container testjob] unable to generate resource usage report'
703 arvjob.output_callback.assert_called_with({"out": "stuff"}, "permanentFail")
705 # The test passes no builder.resources
706 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
707 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
708 def test_mounts(self, keepdocker):
709 runner = mock.MagicMock()
710 runner.ignore_docker_for_reuse = False
711 runner.intermediate_output_ttl = 0
712 runner.secret_store = cwltool.secrets.SecretStore()
713 runner.api._rootDesc = {"revision": "20210628"}
714 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
716 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
717 runner.api.collections().get().execute.return_value = {
718 "portable_data_hash": "99999999999999999999999999999994+99",
719 "manifest_text": ". 99999999999999999999999999999994+99 0:0:file1 0:0:file2"}
721 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.1")
730 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
732 "class": "CommandLineTool",
736 loadingContext, runtimeContext = self.helper(runner)
737 runtimeContext.name = "test_run_mounts"
739 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
740 arvtool.formatgraph = None
743 "class": "Directory",
744 "location": "keep:99999999999999999999999999999994+44",
745 "http://arvados.org/cwl#collectionUUID": "zzzzz-4zz18-zzzzzzzzzzzzzzz",
749 "location": "keep:99999999999999999999999999999994+44/file1",
753 "location": "keep:99999999999999999999999999999994+44/file2",
758 for j in arvtool.job(job_order, mock.MagicMock(), runtimeContext):
759 j.run(runtimeContext)
760 runner.api.container_requests().create.assert_called_with(
761 body=JsonDiffMatcher({
763 'HOME': '/var/spool/cwl',
766 'name': 'test_run_mounts',
767 'runtime_constraints': {
771 'use_existing': True,
774 "/keep/99999999999999999999999999999994+44": {
775 "kind": "collection",
776 "portable_data_hash": "99999999999999999999999999999994+44",
777 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz"
779 '/tmp': {'kind': 'tmp',
780 "capacity": 1073741824 },
781 '/var/spool/cwl': {'kind': 'tmp',
782 "capacity": 1073741824 }
784 'state': 'Committed',
785 'output_name': 'Output from step test_run_mounts',
786 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
787 'output_path': '/var/spool/cwl',
789 'container_image': '99999999999999999999999999999994+99',
790 'command': ['ls', '/var/spool/cwl'],
791 'cwd': '/var/spool/cwl',
792 'scheduling_parameters': {},
793 'properties': {'cwl_input': {
795 "basename": "99999999999999999999999999999994+44",
796 "class": "Directory",
798 "http://arvados.org/cwl#collectionUUID": "zzzzz-4zz18-zzzzzzzzzzzzzzz",
803 "dirname": "/keep/99999999999999999999999999999994+44",
804 "location": "keep:99999999999999999999999999999994+44/file1",
807 "path": "/keep/99999999999999999999999999999994+44/file1",
813 "dirname": "/keep/99999999999999999999999999999994+44",
814 "location": "keep:99999999999999999999999999999994+44/file2",
817 "path": "/keep/99999999999999999999999999999994+44/file2",
821 "location": "keep:99999999999999999999999999999994+44",
822 "path": "/keep/99999999999999999999999999999994+44"
826 'output_storage_classes': ["default"]
829 # The test passes no builder.resources
830 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
831 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
832 def test_secrets(self, keepdocker):
833 arvados_cwl.add_arv_hints()
834 runner = mock.MagicMock()
835 runner.ignore_docker_for_reuse = False
836 runner.intermediate_output_ttl = 0
837 runner.secret_store = cwltool.secrets.SecretStore()
838 runner.api._rootDesc = {"revision": "20210628"}
839 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
841 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
842 runner.api.collections().get().execute.return_value = {
843 "portable_data_hash": "99999999999999999999999999999993+99"}
845 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.1")
847 tool = cmap({"arguments": ["md5sum", "example.conf"],
848 "class": "CommandLineTool",
849 "cwlVersion": "v1.2",
852 "class": "http://commonwl.org/cwltool#Secrets",
861 "id": "#secret_job.cwl/pw",
869 "class": "InitialWorkDirRequirement",
872 "entry": "username: user\npassword: $(inputs.pw)\n",
873 "entryname": "example.conf"
879 loadingContext, runtimeContext = self.helper(runner)
880 runtimeContext.name = "test_secrets"
882 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
883 arvtool.formatgraph = None
885 job_order = {"pw": "blorp"}
886 runner.secret_store.store(["pw"], job_order)
888 for j in arvtool.job(job_order, mock.MagicMock(), runtimeContext):
889 j.run(runtimeContext)
890 runner.api.container_requests().create.assert_called_with(
891 body=JsonDiffMatcher({
893 'HOME': '/var/spool/cwl',
896 'name': 'test_secrets',
897 'runtime_constraints': {
901 'use_existing': True,
904 '/tmp': {'kind': 'tmp',
905 "capacity": 1073741824
907 '/var/spool/cwl': {'kind': 'tmp',
908 "capacity": 1073741824 }
910 'state': 'Committed',
911 'output_name': 'Output from step test_secrets',
912 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
913 'output_path': '/var/spool/cwl',
915 'container_image': '99999999999999999999999999999993+99',
916 'command': ['md5sum', 'example.conf'],
917 'cwd': '/var/spool/cwl',
918 'scheduling_parameters': {},
919 'properties': {'cwl_input': job_order},
921 "/var/spool/cwl/example.conf": {
922 "content": "username: user\npassword: blorp\n",
926 'output_storage_classes': ["default"]
929 # The test passes no builder.resources
930 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
931 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
932 def test_timelimit(self, keepdocker):
933 runner = mock.MagicMock()
934 runner.ignore_docker_for_reuse = False
935 runner.intermediate_output_ttl = 0
936 runner.secret_store = cwltool.secrets.SecretStore()
937 runner.api._rootDesc = {"revision": "20210628"}
938 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
940 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
941 runner.api.collections().get().execute.return_value = {
942 "portable_data_hash": "99999999999999999999999999999993+99"}
948 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
950 "cwlVersion": "v1.2",
951 "class": "CommandLineTool",
954 "class": "ToolTimeLimit",
960 loadingContext, runtimeContext = self.helper(runner)
961 runtimeContext.name = "test_timelimit"
963 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
964 arvtool.formatgraph = None
966 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
967 j.run(runtimeContext)
969 _, kwargs = runner.api.container_requests().create.call_args
970 self.assertEqual(42, kwargs['body']['scheduling_parameters'].get('max_run_time'))
973 # The test passes no builder.resources
974 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
975 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
976 def test_setting_storage_class(self, keepdocker):
977 #arv_docker_clear_cache()
979 runner = mock.MagicMock()
980 runner.ignore_docker_for_reuse = False
981 runner.intermediate_output_ttl = 0
982 runner.secret_store = cwltool.secrets.SecretStore()
983 runner.api._rootDesc = {"revision": "20210628"}
984 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
986 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
987 runner.api.collections().get().execute.return_value = {
988 "portable_data_hash": "99999999999999999999999999999993+99"}
994 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
996 "cwlVersion": "v1.2",
997 "class": "CommandLineTool",
1000 "class": "http://arvados.org/cwl#OutputStorageClass",
1001 "finalStorageClass": ["baz_sc", "qux_sc"],
1002 "intermediateStorageClass": ["foo_sc", "bar_sc"]
1007 loadingContext, runtimeContext = self.helper(runner, True)
1009 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1010 arvtool.formatgraph = None
1012 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
1013 j.run(runtimeContext)
1014 runner.api.container_requests().create.assert_called_with(
1015 body=JsonDiffMatcher({
1017 'HOME': '/var/spool/cwl',
1020 'name': 'test_run_True',
1021 'runtime_constraints': {
1025 'use_existing': True,
1028 '/tmp': {'kind': 'tmp',
1029 "capacity": 1073741824
1031 '/var/spool/cwl': {'kind': 'tmp',
1032 "capacity": 1073741824 }
1034 'state': 'Committed',
1035 'output_name': 'Output from step test_run_True',
1036 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
1037 'output_path': '/var/spool/cwl',
1039 'container_image': '99999999999999999999999999999993+99',
1040 'command': ['ls', '/var/spool/cwl'],
1041 'cwd': '/var/spool/cwl',
1042 'scheduling_parameters': {},
1043 'properties': {'cwl_input': {}},
1044 'secret_mounts': {},
1045 'output_storage_classes': ["foo_sc", "bar_sc"]
1049 # The test passes no builder.resources
1050 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1051 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1052 def test_setting_process_properties(self, keepdocker):
1053 #arv_docker_clear_cache()
1055 runner = mock.MagicMock()
1056 runner.ignore_docker_for_reuse = False
1057 runner.intermediate_output_ttl = 0
1058 runner.secret_store = cwltool.secrets.SecretStore()
1059 runner.api._rootDesc = {"revision": "20210628"}
1060 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1062 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
1063 runner.api.collections().get().execute.return_value = {
1064 "portable_data_hash": "99999999999999999999999999999993+99"}
1068 {"id": "x", "type": "string"}],
1070 "baseCommand": "ls",
1071 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
1073 "class": "CommandLineTool",
1074 "cwlVersion": "v1.2",
1077 "class": "http://arvados.org/cwl#ProcessProperties",
1078 "processProperties": [
1079 {"propertyName": "foo",
1080 "propertyValue": "bar"},
1081 {"propertyName": "baz",
1082 "propertyValue": "$(inputs.x)"},
1083 {"propertyName": "quux",
1094 loadingContext, runtimeContext = self.helper(runner, True)
1096 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1097 arvtool.formatgraph = None
1099 for j in arvtool.job({"x": "blorp"}, mock.MagicMock(), runtimeContext):
1100 j.run(runtimeContext)
1101 runner.api.container_requests().create.assert_called_with(
1102 body=JsonDiffMatcher({
1104 'HOME': '/var/spool/cwl',
1107 'name': 'test_run_True',
1108 'runtime_constraints': {
1112 'use_existing': True,
1115 '/tmp': {'kind': 'tmp',
1116 "capacity": 1073741824
1118 '/var/spool/cwl': {'kind': 'tmp',
1119 "capacity": 1073741824 }
1121 'state': 'Committed',
1122 'output_name': 'Output from step test_run_True',
1123 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
1124 'output_path': '/var/spool/cwl',
1126 'container_image': '99999999999999999999999999999993+99',
1127 'command': ['ls', '/var/spool/cwl'],
1128 'cwd': '/var/spool/cwl',
1129 'scheduling_parameters': {},
1132 "cwl_input": {"x": "blorp"},
1139 'secret_mounts': {},
1140 'output_storage_classes': ["default"]
1144 # The test passes no builder.resources
1145 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1146 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1147 def test_cuda_requirement(self, keepdocker):
1148 arvados_cwl.add_arv_hints()
1149 #arv_docker_clear_cache()
1151 runner = mock.MagicMock()
1152 runner.ignore_docker_for_reuse = False
1153 runner.intermediate_output_ttl = 0
1154 runner.secret_store = cwltool.secrets.SecretStore()
1155 runner.api._rootDesc = {"revision": "20210628"}
1156 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1158 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
1159 runner.api.collections().get().execute.return_value = {
1160 "portable_data_hash": "99999999999999999999999999999993+99"}
1163 "class": "http://commonwl.org/cwltool#CUDARequirement",
1164 "cudaVersionMin": "11.0",
1165 "cudaComputeCapability": "9.0",
1167 "class": "http://commonwl.org/cwltool#CUDARequirement",
1168 "cudaVersionMin": "11.0",
1169 "cudaComputeCapability": "9.0",
1170 "cudaDeviceCountMin": 2
1172 "class": "http://commonwl.org/cwltool#CUDARequirement",
1173 "cudaVersionMin": "11.0",
1174 "cudaComputeCapability": ["4.0", "5.0"],
1175 "cudaDeviceCountMin": 2
1180 'driver_version': "11.0",
1181 'hardware_capability': "9.0"
1184 'driver_version': "11.0",
1185 'hardware_capability': "9.0"
1188 'driver_version': "11.0",
1189 'hardware_capability': "4.0"
1192 for test_case in range(0, len(test_cwl_req)):
1197 "baseCommand": "nvidia-smi",
1200 "cwlVersion": "v1.2",
1201 "class": "CommandLineTool",
1202 "requirements": [test_cwl_req[test_case]]
1205 loadingContext, runtimeContext = self.helper(runner, True)
1207 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1208 arvtool.formatgraph = None
1210 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
1211 j.run(runtimeContext)
1212 runner.api.container_requests().create.assert_called_with(
1213 body=JsonDiffMatcher({
1215 'HOME': '/var/spool/cwl',
1218 'name': 'test_run_True' + ("" if test_case == 0 else "_"+str(test_case+1)),
1219 'runtime_constraints': {
1222 'cuda': test_arv_req[test_case]
1224 'use_existing': True,
1227 '/tmp': {'kind': 'tmp',
1228 "capacity": 1073741824
1230 '/var/spool/cwl': {'kind': 'tmp',
1231 "capacity": 1073741824 }
1233 'state': 'Committed',
1234 'output_name': 'Output from step test_run_True' + ("" if test_case == 0 else "_"+str(test_case+1)),
1235 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
1236 'output_path': '/var/spool/cwl',
1238 'container_image': '99999999999999999999999999999993+99',
1239 'command': ['nvidia-smi'],
1240 'cwd': '/var/spool/cwl',
1241 'scheduling_parameters': {},
1242 'properties': {'cwl_input': {}},
1243 'secret_mounts': {},
1244 'output_storage_classes': ["default"]
1248 # The test passes no builder.resources
1249 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1250 @mock.patch("arvados_cwl.arvdocker.determine_image_id")
1251 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1252 def test_match_local_docker(self, keepdocker, determine_image_id):
1253 arvados_cwl.add_arv_hints()
1255 runner = mock.MagicMock()
1256 runner.ignore_docker_for_reuse = False
1257 runner.intermediate_output_ttl = 0
1258 runner.secret_store = cwltool.secrets.SecretStore()
1259 runner.api._rootDesc = {"revision": "20210628"}
1260 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1262 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz4", {"dockerhash": "456"}),
1263 ("zzzzz-4zz18-zzzzzzzzzzzzzz3", {"dockerhash": "123"})]
1264 determine_image_id.side_effect = lambda x: "123"
1266 ex = mock.MagicMock()
1267 lookup = {"zzzzz-4zz18-zzzzzzzzzzzzzz4": {"portable_data_hash": "99999999999999999999999999999994+99"},
1268 "zzzzz-4zz18-zzzzzzzzzzzzzz3": {"portable_data_hash": "99999999999999999999999999999993+99"}}
1269 ex.execute.return_value = lookup[uuid]
1271 runner.api.collections().get.side_effect = execute
1276 "baseCommand": "echo",
1279 "cwlVersion": "v1.0",
1280 "class": "org.w3id.cwl.cwl.CommandLineTool"
1283 loadingContext, runtimeContext = self.helper(runner, True)
1285 arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, loadingContext)
1286 arvtool.formatgraph = None
1288 container_request = {
1290 'HOME': '/var/spool/cwl',
1293 'name': 'test_run_True',
1294 'runtime_constraints': {
1298 'use_existing': True,
1301 '/tmp': {'kind': 'tmp',
1302 "capacity": 1073741824
1304 '/var/spool/cwl': {'kind': 'tmp',
1305 "capacity": 1073741824 }
1307 'state': 'Committed',
1308 'output_name': 'Output from step test_run_True',
1309 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
1310 'output_path': '/var/spool/cwl',
1312 'container_image': '99999999999999999999999999999994+99',
1313 'command': ['echo'],
1314 'cwd': '/var/spool/cwl',
1315 'scheduling_parameters': {},
1316 'properties': {'cwl_input': {}},
1317 'secret_mounts': {},
1318 'output_storage_classes': ["default"]
1321 runtimeContext.match_local_docker = False
1322 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
1323 j.run(runtimeContext)
1324 runner.api.container_requests().create.assert_called_with(
1325 body=JsonDiffMatcher(container_request))
1327 runtimeContext.cached_docker_lookups.clear()
1328 runtimeContext.match_local_docker = True
1329 container_request['container_image'] = '99999999999999999999999999999993+99'
1330 container_request['name'] = 'test_run_True_2'
1331 container_request['output_name'] = 'Output from step test_run_True_2'
1332 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
1333 j.run(runtimeContext)
1334 runner.api.container_requests().create.assert_called_with(
1335 body=JsonDiffMatcher(container_request))
1338 # The test passes no builder.resources
1339 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1340 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1341 def test_run_preemptible_hint(self, keepdocker):
1342 arvados_cwl.add_arv_hints()
1343 for enable_preemptible in (None, True, False):
1344 for preemptible_hint in (None, True, False):
1345 #arv_docker_clear_cache()
1347 runner = mock.MagicMock()
1348 runner.ignore_docker_for_reuse = False
1349 runner.intermediate_output_ttl = 0
1350 runner.secret_store = cwltool.secrets.SecretStore()
1351 runner.api._rootDesc = {"revision": "20210628"}
1352 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1354 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
1355 runner.api.collections().get().execute.return_value = {
1356 "portable_data_hash": "99999999999999999999999999999993+99"}
1358 if preemptible_hint is not None:
1360 "class": "http://arvados.org/cwl#UsePreemptible",
1361 "usePreemptible": preemptible_hint
1369 "baseCommand": "ls",
1370 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
1372 "class": "CommandLineTool",
1373 "cwlVersion": "v1.2",
1377 loadingContext, runtimeContext = self.helper(runner)
1379 runtimeContext.name = 'test_run_enable_preemptible_'+str(enable_preemptible)+str(preemptible_hint)
1380 runtimeContext.enable_preemptible = enable_preemptible
1382 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1383 arvtool.formatgraph = None
1385 # Test the interactions between --enable/disable-preemptible
1386 # and UsePreemptible hint
1388 if enable_preemptible is None:
1389 if preemptible_hint is None:
1392 sched = {'preemptible': preemptible_hint}
1394 if preemptible_hint is None:
1395 sched = {'preemptible': enable_preemptible}
1397 sched = {'preemptible': enable_preemptible and preemptible_hint}
1399 for j in arvtool.job({}, mock.MagicMock(), runtimeContext):
1400 j.run(runtimeContext)
1401 runner.api.container_requests().create.assert_called_with(
1402 body=JsonDiffMatcher({
1404 'HOME': '/var/spool/cwl',
1407 'name': runtimeContext.name,
1408 'runtime_constraints': {
1412 'use_existing': True,
1415 '/tmp': {'kind': 'tmp',
1416 "capacity": 1073741824
1418 '/var/spool/cwl': {'kind': 'tmp',
1419 "capacity": 1073741824 }
1421 'state': 'Committed',
1422 'output_name': 'Output from step '+runtimeContext.name,
1423 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
1424 'output_path': '/var/spool/cwl',
1426 'container_image': '99999999999999999999999999999993+99',
1427 'command': ['ls', '/var/spool/cwl'],
1428 'cwd': '/var/spool/cwl',
1429 'scheduling_parameters': sched,
1430 'properties': {'cwl_input': {}},
1431 'secret_mounts': {},
1432 'output_storage_classes': ["default"]
1436 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1437 def test_output_properties(self, keepdocker):
1438 arvados_cwl.add_arv_hints()
1439 for rev in ["20210628", "20220510"]:
1440 runner = mock.MagicMock()
1441 runner.ignore_docker_for_reuse = False
1442 runner.intermediate_output_ttl = 0
1443 runner.secret_store = cwltool.secrets.SecretStore()
1444 runner.api._rootDesc = {"revision": rev}
1445 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1447 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
1448 runner.api.collections().get().execute.return_value = {
1449 "portable_data_hash": "99999999999999999999999999999993+99"}
1457 "baseCommand": "ls",
1458 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
1460 "cwlVersion": "v1.2",
1461 "class": "CommandLineTool",
1464 "class": "http://arvados.org/cwl#OutputCollectionProperties",
1465 "outputProperties": {
1467 "baz": "$(inputs.inp)"
1473 loadingContext, runtimeContext = self.helper(runner)
1474 runtimeContext.name = "test_timelimit"
1476 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1477 arvtool.formatgraph = None
1479 for j in arvtool.job({"inp": "quux"}, mock.MagicMock(), runtimeContext):
1480 j.run(runtimeContext)
1482 _, kwargs = runner.api.container_requests().create.call_args
1483 if rev == "20220510":
1484 self.assertEqual({"foo": "bar", "baz": "quux"}, kwargs['body'].get('output_properties'))
1486 self.assertEqual(None, kwargs['body'].get('output_properties'))
1488 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
1489 def test_output_glob(self, keepdocker):
1490 arvados_cwl.add_arv_hints()
1491 for rev in ["20231117", "20240502"]:
1492 runner = mock.MagicMock()
1493 runner.ignore_docker_for_reuse = False
1494 runner.intermediate_output_ttl = 0
1495 runner.secret_store = cwltool.secrets.SecretStore()
1496 runner.api._rootDesc = {"revision": rev}
1497 runner.api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1499 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
1500 runner.api.collections().get().execute.return_value = {
1501 "portable_data_hash": "99999999999999999999999999999993+99"}
1520 "glob": ["*.dat", "*.bat"]
1542 "glob": "$(inputs.inp)"
1547 "baseCommand": "ls",
1548 "arguments": [{"valueFrom": "$(runtime.outdir)"}],
1550 "cwlVersion": "v1.2",
1551 "class": "CommandLineTool",
1555 loadingContext, runtimeContext = self.helper(runner)
1556 runtimeContext.name = "test_timelimit"
1558 arvtool = cwltool.load_tool.load_tool(tool, loadingContext)
1559 arvtool.formatgraph = None
1561 for j in arvtool.job({"inp": "quux"}, mock.MagicMock(), runtimeContext):
1562 j.run(runtimeContext)
1564 _, kwargs = runner.api.container_requests().create.call_args
1565 if rev == "20240502":
1566 self.assertEqual(['*.txt', '*.txt/**',
1567 '*.dat', '*.dat/**',
1568 '*.bat', '*.bat/**',
1569 '*.cat', '*.cat/**',
1571 ], kwargs['body'].get('output_glob'))
1573 self.assertEqual(None, kwargs['body'].get('output_glob'))
1576 class TestWorkflow(unittest.TestCase):
1578 cwltool.process._names = set()
1579 #arv_docker_clear_cache()
1581 def helper(self, runner, enable_reuse=True):
1582 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0")
1584 make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess,
1585 collection_cache=arvados_cwl.CollectionCache(runner.api, None, 0))
1587 document_loader.fetcher_constructor = functools.partial(arvados_cwl.CollectionFetcher, api_client=runner.api, fs_access=make_fs_access(""))
1588 document_loader.fetcher = document_loader.fetcher_constructor(document_loader.cache, document_loader.session)
1589 document_loader.fetch_text = document_loader.fetcher.fetch_text
1590 document_loader.check_exists = document_loader.fetcher.check_exists
1592 loadingContext = arvados_cwl.context.ArvLoadingContext(
1593 {"avsc_names": avsc_names,
1595 "make_fs_access": make_fs_access,
1596 "loader": document_loader,
1597 "metadata": {"cwlVersion": INTERNAL_VERSION, "http://commonwl.org/cwltool#original_cwlVersion": "v1.0"},
1598 "construct_tool_object": runner.arv_make_tool,
1599 "default_docker_image": "arvados/jobs:"+arvados_cwl.__version__})
1600 runtimeContext = arvados_cwl.context.ArvRuntimeContext(
1601 {"work_api": "containers",
1603 "name": "test_run_wf_"+str(enable_reuse),
1604 "make_fs_access": make_fs_access,
1606 "enable_reuse": enable_reuse,
1609 return loadingContext, runtimeContext
1611 # The test passes no builder.resources
1612 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1613 @mock.patch("arvados.collection.CollectionReader")
1614 @mock.patch("arvados.collection.Collection")
1615 @mock.patch('arvados.commands.keepdocker.list_images_in_arv')
1616 def test_run(self, list_images_in_arv, mockcollection, mockcollectionreader):
1617 arvados_cwl.add_arv_hints()
1619 api = mock.MagicMock()
1620 api._rootDesc = get_rootDesc()
1621 api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1623 runner = arvados_cwl.executor.ArvCwlExecutor(api)
1624 self.assertEqual(runner.work_api, 'containers')
1626 list_images_in_arv.return_value = [["zzzzz-4zz18-zzzzzzzzzzzzzzz"]]
1627 runner.api.collections().get().execute.return_value = {"portable_data_hash": "99999999999999999999999999999993+99"}
1628 runner.api.collections().list().execute.return_value = {"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz",
1629 "portable_data_hash": "99999999999999999999999999999993+99"}]}
1631 runner.api.containers().current().execute.return_value = {}
1633 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
1634 runner.ignore_docker_for_reuse = False
1635 runner.num_retries = 0
1636 runner.secret_store = cwltool.secrets.SecretStore()
1638 loadingContext, runtimeContext = self.helper(runner)
1639 runner.fs_access = runtimeContext.make_fs_access(runtimeContext.basedir)
1641 mockcollectionreader().exists.return_value = True
1643 tool, metadata = loadingContext.loader.resolve_ref("tests/wf/scatter2.cwl")
1644 metadata["cwlVersion"] = tool["cwlVersion"]
1646 mockc = mock.MagicMock()
1647 mockcollection.side_effect = lambda *args, **kwargs: CollectionMock(mockc, *args, **kwargs)
1648 mockcollectionreader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "token.txt")
1650 arvtool = arvados_cwl.ArvadosWorkflow(runner, tool, loadingContext)
1651 arvtool.formatgraph = None
1652 it = arvtool.job({}, mock.MagicMock(), runtimeContext)
1654 next(it).run(runtimeContext)
1655 next(it).run(runtimeContext)
1657 with open("tests/wf/scatter2_subwf.cwl") as f:
1658 subwf = StripYAMLComments(f.read()).rstrip()
1660 runner.api.container_requests().create.assert_called_with(
1661 body=JsonDiffMatcher({
1666 "--preserve-entire-environment",
1670 "container_image": "99999999999999999999999999999993+99",
1671 "cwd": "/var/spool/cwl",
1673 "HOME": "/var/spool/cwl",
1677 "/keep/99999999999999999999999999999999+118": {
1678 "kind": "collection",
1679 "portable_data_hash": "99999999999999999999999999999999+118"
1682 "capacity": 1073741824,
1686 "capacity": 1073741824,
1689 "/var/spool/cwl/cwl.input.yml": {
1690 "kind": "collection",
1691 "path": "cwl.input.yml",
1692 "portable_data_hash": "99999999999999999999999999999996+99"
1694 "/var/spool/cwl/workflow.cwl": {
1695 "kind": "collection",
1696 "path": "workflow.cwl",
1697 "portable_data_hash": "99999999999999999999999999999996+99"
1701 "path": "/var/spool/cwl/cwl.output.json"
1704 "name": "scatterstep",
1705 "output_name": "Output from step scatterstep",
1706 "output_path": "/var/spool/cwl",
1709 "properties": {'cwl_input': {
1711 "basename": "token.txt",
1713 "dirname": "/keep/99999999999999999999999999999999+118",
1714 "location": "keep:99999999999999999999999999999999+118/token.txt",
1716 "nameroot": "token",
1717 "path": "/keep/99999999999999999999999999999999+118/token.txt",
1722 "runtime_constraints": {
1726 "scheduling_parameters": {},
1727 "secret_mounts": {},
1728 "state": "Committed",
1729 "use_existing": True,
1730 'output_storage_classes': ["default"]
1732 mockc.open().__enter__().write.assert_has_calls([mock.call(subwf)])
1733 mockc.open().__enter__().write.assert_has_calls([mock.call(
1736 "basename": "token.txt",
1738 "location": "/keep/99999999999999999999999999999999+118/token.txt",
1744 # The test passes no builder.resources
1745 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
1746 @mock.patch("arvados.collection.CollectionReader")
1747 @mock.patch("arvados.collection.Collection")
1748 @mock.patch('arvados.commands.keepdocker.list_images_in_arv')
1749 def test_overall_resource_singlecontainer(self, list_images_in_arv, mockcollection, mockcollectionreader):
1750 arvados_cwl.add_arv_hints()
1752 api = mock.MagicMock()
1753 api._rootDesc = get_rootDesc()
1754 api.config.return_value = {"Containers": {"DefaultKeepCacheRAM": 256<<20}}
1756 runner = arvados_cwl.executor.ArvCwlExecutor(api)
1757 self.assertEqual(runner.work_api, 'containers')
1759 list_images_in_arv.return_value = [["zzzzz-4zz18-zzzzzzzzzzzzzzz"]]
1760 runner.api.collections().get().execute.return_value = {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz",
1761 "portable_data_hash": "99999999999999999999999999999993+99"}
1762 runner.api.collections().list().execute.return_value = {"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz",
1763 "portable_data_hash": "99999999999999999999999999999993+99"}]}
1765 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
1766 runner.ignore_docker_for_reuse = False
1767 runner.num_retries = 0
1768 runner.secret_store = cwltool.secrets.SecretStore()
1770 loadingContext, runtimeContext = self.helper(runner)
1771 runner.fs_access = runtimeContext.make_fs_access(runtimeContext.basedir)
1772 loadingContext.do_update = True
1773 tool, metadata = loadingContext.loader.resolve_ref("tests/wf/echo-wf.cwl")
1775 mockcollection.side_effect = lambda *args, **kwargs: CollectionMock(mock.MagicMock(), *args, **kwargs)
1777 arvtool = arvados_cwl.ArvadosWorkflow(runner, tool, loadingContext)
1778 arvtool.formatgraph = None
1779 it = arvtool.job({}, mock.MagicMock(), runtimeContext)
1781 next(it).run(runtimeContext)
1782 next(it).run(runtimeContext)
1784 with open("tests/wf/echo-subwf.cwl") as f:
1785 subwf = StripYAMLComments(f.read())
1787 runner.api.container_requests().create.assert_called_with(
1788 body=JsonDiffMatcher({
1790 'environment': {'HOME': '/var/spool/cwl', 'TMPDIR': '/tmp'},
1791 'scheduling_parameters': {},
1792 'name': u'echo-subwf',
1793 'secret_mounts': {},
1794 'runtime_constraints': {'API': True, 'vcpus': 3, 'ram': 1073741824},
1795 'properties': {'cwl_input': {}},
1798 '/var/spool/cwl/cwl.input.yml': {
1799 'portable_data_hash': '99999999999999999999999999999996+99',
1800 'kind': 'collection',
1801 'path': 'cwl.input.yml'
1803 '/var/spool/cwl/workflow.cwl': {
1804 'portable_data_hash': '99999999999999999999999999999996+99',
1805 'kind': 'collection',
1806 'path': 'workflow.cwl'
1809 'path': '/var/spool/cwl/cwl.output.json',
1814 'capacity': 1073741824
1815 }, '/var/spool/cwl': {
1817 'capacity': 3221225472
1820 'state': 'Committed',
1821 'output_path': '/var/spool/cwl',
1822 'container_image': '99999999999999999999999999999993+99',
1827 u'--preserve-entire-environment',
1831 'use_existing': True,
1832 'output_name': u'Output from step echo-subwf',
1833 'cwd': '/var/spool/cwl',
1834 'output_storage_classes': ["default"]
1837 def test_default_work_api(self):
1838 arvados_cwl.add_arv_hints()
1840 api = mock.MagicMock()
1841 api._rootDesc = copy.deepcopy(get_rootDesc())
1842 runner = arvados_cwl.executor.ArvCwlExecutor(api)
1843 self.assertEqual(runner.work_api, 'containers')