3 import arvados.collection
15 from .matcher import JsonDiffMatcher
19 @functools.wraps(func)
20 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
21 @mock.patch("arvados.collection.KeepClient")
22 @mock.patch("arvados.events.subscribe")
23 def wrapped(self, events, keep_client, keepdocker, *args, **kwargs):
28 stubs.keepdocker = keepdocker
29 stubs.keep_client = keep_client
31 def putstub(p, **kwargs):
32 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
33 stubs.keep_client().put.side_effect = putstub
34 stubs.keep_client.put.side_effect = putstub
36 stubs.keepdocker.return_value = [("zzzzz-4zz18-zzzzzzzzzzzzzz3", "")]
37 stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
40 stubs.api = mock.MagicMock()
41 stubs.api.users().current().execute.return_value = {
42 "uuid": stubs.fake_user_uuid,
44 stubs.api.collections().list().execute.return_value = {"items": []}
45 stubs.api.collections().create().execute.side_effect = ({
46 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
47 "portable_data_hash": "99999999999999999999999999999991+99",
50 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
51 "portable_data_hash": "99999999999999999999999999999992+99",
52 "manifest_text": "./tool 00000000000000000000000000000000+0 0:0:submit_tool.cwl 0:0:blub.txt"
55 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz4",
56 "portable_data_hash": "99999999999999999999999999999994+99",
60 "uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz5",
61 "portable_data_hash": "99999999999999999999999999999995+99",
64 stubs.api.collections().get().execute.return_value = {
65 "portable_data_hash": "99999999999999999999999999999993+99", "manifest_text": "./tool 00000000000000000000000000000000+0 0:0:submit_tool.cwl 0:0:blub.txt"}
67 stubs.expect_job_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
68 stubs.api.jobs().create().execute.return_value = {
69 "uuid": stubs.expect_job_uuid,
73 stubs.expect_container_request_uuid = "zzzzz-xvhdp-zzzzzzzzzzzzzzz"
74 stubs.api.container_requests().create().execute.return_value = {
75 "uuid": stubs.expect_container_request_uuid,
76 "container_uuid": "zzzzz-dz642-zzzzzzzzzzzzzzz",
80 stubs.expect_pipeline_template_uuid = "zzzzz-d1hrv-zzzzzzzzzzzzzzz"
81 stubs.api.pipeline_templates().create().execute.return_value = {
82 "uuid": stubs.expect_pipeline_template_uuid,
84 stubs.expect_job_spec = {
85 'runtime_constraints': {
86 'docker_image': 'arvados/jobs'
88 'script_parameters': {
90 'basename': 'blorp.txt',
91 'location': 'keep:99999999999999999999999999999994+99/blorp.txt',
95 'basename': '99999999999999999999999999999998+99',
96 'location': 'keep:99999999999999999999999999999998+99',
100 'basename': 'anonymous',
102 "basename": "renamed.txt",
104 "location": "keep:99999999999999999999999999999998+99/file1.txt"
109 '99999999999999999999999999999991+99/wf/submit_wf.cwl'
111 'repository': 'arvados',
112 'script_version': 'master',
113 'script': 'cwl-runner'
116 stubs.expect_container_spec = {
123 '/var/lib/cwl/workflow': {
124 'portable_data_hash': '99999999999999999999999999999991+99',
128 'path': '/var/spool/cwl/cwl.output.json',
131 '/var/lib/cwl/job/cwl.input.json': {
132 'portable_data_hash': 'd20d7cddd1984f105dd3702c7f125afb+60/cwl.input.json',
136 'state': 'Committed',
137 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
138 'command': ['arvados-cwl-runner', '--local', '--api=containers', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/job/cwl.input.json'],
139 'name': 'submit_wf.cwl',
140 'container_image': '99999999999999999999999999999993+99',
141 'output_path': '/var/spool/cwl',
142 'cwd': '/var/spool/cwl',
143 'runtime_constraints': {
150 stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
151 stubs.api.workflows().create().execute.return_value = {
152 "uuid": stubs.expect_workflow_uuid,
155 return func(self, stubs, *args, **kwargs)
159 class TestSubmit(unittest.TestCase):
161 def test_submit(self, stubs):
162 capture_stdout = cStringIO.StringIO()
163 exited = arvados_cwl.main(
164 ["--submit", "--no-wait",
165 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
166 capture_stdout, sys.stderr, api_client=stubs.api)
167 self.assertEqual(exited, 0)
169 stubs.api.collections().create.assert_has_calls([
173 './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
174 '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
175 'cc2ffb940e60adf1b2b282c67587e43d+413 0:413:submit_wf.cwl\n',
176 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
177 'name': 'submit_wf.cwl',
178 }, ensure_unique_name=True),
179 mock.call().execute(),
180 mock.call(body={'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
181 '0:0:blub.txt 0:0:submit_tool.cwl\n',
182 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
183 'replication_desired': None,
184 'name': 'New collection'
185 }, ensure_unique_name=True),
186 mock.call().execute(num_retries=4),
189 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
190 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
192 }, ensure_unique_name=True),
193 mock.call().execute()])
195 expect_job = copy.deepcopy(stubs.expect_job_spec)
196 expect_job["owner_uuid"] = stubs.fake_user_uuid
197 stubs.api.jobs().create.assert_called_with(
200 self.assertEqual(capture_stdout.getvalue(),
201 stubs.expect_job_uuid + '\n')
204 def test_submit_with_project_uuid(self, stubs):
205 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
207 exited = arvados_cwl.main(
208 ["--submit", "--no-wait",
209 "--project-uuid", project_uuid,
210 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
211 sys.stdout, sys.stderr, api_client=stubs.api)
212 self.assertEqual(exited, 0)
214 expect_body = copy.deepcopy(stubs.expect_job_spec)
215 expect_body["owner_uuid"] = project_uuid
216 stubs.api.jobs().create.assert_called_with(
221 def test_submit_container(self, stubs):
222 capture_stdout = cStringIO.StringIO()
224 exited = arvados_cwl.main(
225 ["--submit", "--no-wait", "--api=containers", "--debug",
226 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
227 capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client)
228 self.assertEqual(exited, 0)
230 logging.exception("")
232 stubs.api.collections().create.assert_has_calls([
236 './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
237 '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
238 'cc2ffb940e60adf1b2b282c67587e43d+413 0:413:submit_wf.cwl\n',
239 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
240 'name': 'submit_wf.cwl',
241 }, ensure_unique_name=True),
242 mock.call().execute(),
243 mock.call(body={'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
244 '0:0:blub.txt 0:0:submit_tool.cwl\n',
245 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
246 'name': 'New collection',
247 'replication_desired': None,
248 }, ensure_unique_name=True),
249 mock.call().execute(num_retries=4),
252 '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
253 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
255 }, ensure_unique_name=True),
256 mock.call().execute()])
258 expect_container = copy.deepcopy(stubs.expect_container_spec)
259 expect_container["owner_uuid"] = stubs.fake_user_uuid
260 stubs.api.container_requests().create.assert_called_with(
261 body=expect_container)
262 self.assertEqual(capture_stdout.getvalue(),
263 stubs.expect_container_request_uuid + '\n')
266 class TestCreateTemplate(unittest.TestCase):
268 def test_create(self, stubs):
269 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
271 capture_stdout = cStringIO.StringIO()
273 exited = arvados_cwl.main(
274 ["--create-template", "--debug",
275 "--project-uuid", project_uuid,
276 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
277 capture_stdout, sys.stderr, api_client=stubs.api)
278 self.assertEqual(exited, 0)
280 stubs.api.pipeline_instances().create.refute_called()
281 stubs.api.jobs().create.refute_called()
283 expect_component = copy.deepcopy(stubs.expect_job_spec)
284 expect_component['script_parameters']['x'] = {
288 'value': '99999999999999999999999999999994+99/blorp.txt',
290 expect_component['script_parameters']['y'] = {
291 'dataclass': 'Collection',
294 'value': '99999999999999999999999999999998+99',
296 expect_component['script_parameters']['z'] = {
297 'dataclass': 'Collection',
303 "submit_wf.cwl": expect_component,
305 "name": "submit_wf.cwl",
306 "owner_uuid": project_uuid,
308 stubs.api.pipeline_templates().create.assert_called_with(
309 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
311 self.assertEqual(capture_stdout.getvalue(),
312 stubs.expect_pipeline_template_uuid + '\n')
315 class TestCreateWorkflow(unittest.TestCase):
317 def test_create(self, stubs):
318 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
320 capture_stdout = cStringIO.StringIO()
322 exited = arvados_cwl.main(
323 ["--create-workflow", "--debug",
324 "--project-uuid", project_uuid,
325 "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
326 capture_stdout, sys.stderr, api_client=stubs.api)
327 self.assertEqual(exited, 0)
329 stubs.api.pipeline_templates().create.refute_called()
330 stubs.api.container_requests().create.refute_called()
332 with open("tests/wf/expect_packed.cwl") as f:
333 expect_workflow = f.read()
337 "owner_uuid": project_uuid,
338 "name": "submit_wf.cwl",
340 "definition": expect_workflow
343 stubs.api.workflows().create.assert_called_with(
344 body=JsonDiffMatcher(body))
346 self.assertEqual(capture_stdout.getvalue(),
347 stubs.expect_workflow_uuid + '\n')
350 class TestTemplateInputs(unittest.TestCase):
354 'runtime_constraints': {
355 'docker_image': 'arvados/jobs',
357 'script_parameters': {
359 '99999999999999999999999999999991+99/'
360 'wf/inputs_test.cwl',
361 'optionalFloatInput': None,
366 'title': "It's a file; we expect to find some characters in it.",
367 'description': 'If there were anything further to say, it would be said here,\nor here.'
371 'dataclass': 'number',
373 'title': 'Floats like a duck',
377 'optionalFloatInput': {
378 'type': ['null', 'float'],
379 'dataclass': 'number',
384 'dataclass': 'boolean',
386 'title': 'True or false?',
389 'repository': 'arvados',
390 'script_version': 'master',
391 'script': 'cwl-runner',
394 "name": "inputs_test.cwl",
398 def test_inputs_empty(self, stubs):
399 exited = arvados_cwl.main(
400 ["--create-template", "--no-wait",
401 "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
402 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
403 self.assertEqual(exited, 0)
405 expect_template = copy.deepcopy(self.expect_template)
406 expect_template["owner_uuid"] = stubs.fake_user_uuid
408 stubs.api.pipeline_templates().create.assert_called_with(
409 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
412 def test_inputs(self, stubs):
413 exited = arvados_cwl.main(
414 ["--create-template", "--no-wait",
415 "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
416 cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
417 self.assertEqual(exited, 0)
419 self.expect_template["owner_uuid"] = stubs.fake_user_uuid
421 expect_template = copy.deepcopy(self.expect_template)
422 expect_template["owner_uuid"] = stubs.fake_user_uuid
423 params = expect_template[
424 "components"]["inputs_test.cwl"]["script_parameters"]
425 params["fileInput"]["value"] = '99999999999999999999999999999994+99/blorp.txt'
426 params["floatInput"]["value"] = 1.234
427 params["boolInput"]["value"] = True
429 stubs.api.pipeline_templates().create.assert_called_with(
430 body=JsonDiffMatcher(expect_template), ensure_unique_name=True)