2 from arvados_cwl.arvdocker import arv_docker_clear_cache
9 from schema_salad.ref_resolver import Loader
10 from schema_salad.sourceline import cmap
12 from .matcher import JsonDiffMatcher
14 if not os.getenv('ARVADOS_DEBUG'):
15 logging.getLogger('arvados.cwl-runner').setLevel(logging.WARN)
16 logging.getLogger('arvados.arv-run').setLevel(logging.WARN)
19 class TestContainer(unittest.TestCase):
21 # The test passes no builder.resources
22 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
23 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
24 def test_run(self, keepdocker):
25 for enable_reuse in (True, False):
26 arv_docker_clear_cache()
28 runner = mock.MagicMock()
29 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
30 runner.ignore_docker_for_reuse = False
32 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
33 runner.api.collections().get().execute.return_value = {
34 "portable_data_hash": "99999999999999999999999999999993+99"}
36 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0")
42 "arguments": [{"valueFrom": "$(runtime.outdir)"}]
44 make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, api_client=runner.api)
45 arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="containers", avsc_names=avsc_names,
46 basedir="", make_fs_access=make_fs_access, loader=Loader({}))
47 arvtool.formatgraph = None
48 for j in arvtool.job({}, mock.MagicMock(), basedir="", name="test_run_"+str(enable_reuse),
49 make_fs_access=make_fs_access, tmpdir="/tmp"):
50 j.run(enable_reuse=enable_reuse)
51 runner.api.container_requests().create.assert_called_with(
52 body=JsonDiffMatcher({
54 'HOME': '/var/spool/cwl',
57 'name': 'test_run_'+str(enable_reuse),
58 'runtime_constraints': {
62 'use_existing': enable_reuse,
65 '/var/spool/cwl': {'kind': 'tmp'}
68 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
69 'output_path': '/var/spool/cwl',
70 'container_image': '99999999999999999999999999999993+99',
71 'command': ['ls', '/var/spool/cwl'],
72 'cwd': '/var/spool/cwl',
73 'scheduling_parameters': {},
77 # The test passes some fields in builder.resources
78 # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
79 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
80 def test_resource_requirements(self, keepdocker):
81 arv_docker_clear_cache()
82 runner = mock.MagicMock()
83 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
84 runner.ignore_docker_for_reuse = False
85 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("v1.0")
87 keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
88 runner.api.collections().get().execute.return_value = {
89 "portable_data_hash": "99999999999999999999999999999993+99"}
95 "class": "ResourceRequirement",
100 "class": "http://arvados.org/cwl#RuntimeConstraints",
103 "class": "http://arvados.org/cwl#APIRequirement",
105 "class": "http://arvados.org/cwl#PartitionRequirement",
110 make_fs_access=functools.partial(arvados_cwl.CollectionFsAccess, api_client=runner.api)
111 arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="containers",
112 avsc_names=avsc_names, make_fs_access=make_fs_access,
114 arvtool.formatgraph = None
115 for j in arvtool.job({}, mock.MagicMock(), basedir="", name="test_resource_requirements",
116 make_fs_access=make_fs_access, tmpdir="/tmp"):
119 call_args, call_kwargs = runner.api.container_requests().create.call_args
121 call_body_expected = {
123 'HOME': '/var/spool/cwl',
126 'name': 'test_resource_requirements',
127 'runtime_constraints': {
130 'keep_cache_ram': 512,
133 'use_existing': True,
136 '/var/spool/cwl': {'kind': 'tmp'}
138 'state': 'Committed',
139 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
140 'output_path': '/var/spool/cwl',
141 'container_image': '99999999999999999999999999999993+99',
143 'cwd': '/var/spool/cwl',
144 'scheduling_parameters': {
145 'partitions': ['blurb']
150 call_body = call_kwargs.get('body', None)
151 self.assertNotEqual(None, call_body)
152 for key in call_body:
153 self.assertEqual(call_body_expected.get(key), call_body.get(key))
155 @mock.patch("arvados.collection.Collection")
156 def test_done(self, col):
157 api = mock.MagicMock()
159 runner = mock.MagicMock()
161 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
162 runner.num_retries = 0
163 runner.ignore_docker_for_reuse = False
165 runner.api.containers().get().execute.return_value = {"state":"Complete",
169 col().open.return_value = []
171 arvjob = arvados_cwl.ArvadosContainer(runner)
172 arvjob.name = "testjob"
173 arvjob.builder = mock.MagicMock()
174 arvjob.output_callback = mock.MagicMock()
175 arvjob.collect_outputs = mock.MagicMock()
176 arvjob.successCodes = [0]
177 arvjob.outdir = "/var/spool/cwl"
179 arvjob.collect_outputs.return_value = {"out": "stuff"}
183 "log_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
184 "output_uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
185 "uuid": "zzzzz-xvhdp-zzzzzzzzzzzzzzz",
186 "container_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
189 self.assertFalse(api.collections().create.called)
191 arvjob.collect_outputs.assert_called_with("keep:abc+123")
192 arvjob.output_callback.assert_called_with({"out": "stuff"}, "success")