8 if not os.getenv('ARVADOS_DEBUG'):
9 logging.getLogger('arvados.cwl-runner').setLevel(logging.WARN)
10 logging.getLogger('arvados.arv-run').setLevel(logging.WARN)
13 class TestJob(unittest.TestCase):
15 # The test passes no builder.resources
16 # Hence the default resources will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
18 runner = mock.MagicMock()
19 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
20 runner.ignore_docker_for_reuse = False
21 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("draft-3")
27 "arguments": [{"valueFrom": "$(runtime.outdir)"}]
29 arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="jobs", avsc_names=avsc_names, basedir="")
30 arvtool.formatgraph = None
31 for j in arvtool.job({}, mock.MagicMock(), basedir=""):
33 runner.api.jobs().create.assert_called_with(
35 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
36 'runtime_constraints': {},
37 'script_parameters': {
39 'task.env': {'TMPDIR': '$(task.tmpdir)'},
40 'command': ['ls', '$(task.outdir)']
43 'script_version': 'master',
44 'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
45 'repository': 'arvados',
46 'script': 'crunchrunner',
47 'runtime_constraints': {
48 'docker_image': 'arvados/jobs',
49 'min_cores_per_node': 1,
50 'min_ram_mb_per_node': 1024,
51 'min_scratch_mb_per_node': 2048 # tmpdirSize + outdirSize
55 filters=[['repository', '=', 'arvados'],
56 ['script', '=', 'crunchrunner'],
57 ['script_version', 'in git', '9e5b98e8f5f4727856b53447191f9c06e3da2ba6'],
58 ['docker_image_locator', 'in docker', 'arvados/jobs']]
61 # The test passes some fields in builder.resources
62 # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
63 def test_resource_requirements(self):
64 runner = mock.MagicMock()
65 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
66 runner.ignore_docker_for_reuse = False
67 document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema("draft-3")
73 "class": "ResourceRequirement",
80 arvtool = arvados_cwl.ArvadosCommandTool(runner, tool, work_api="jobs", avsc_names=avsc_names)
81 arvtool.formatgraph = None
82 for j in arvtool.job({}, mock.MagicMock(), basedir=""):
84 runner.api.jobs().create.assert_called_with(
86 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
87 'runtime_constraints': {},
88 'script_parameters': {
90 'task.env': {'TMPDIR': '$(task.tmpdir)'},
94 'script_version': 'master',
95 'minimum_script_version': '9e5b98e8f5f4727856b53447191f9c06e3da2ba6',
96 'repository': 'arvados',
97 'script': 'crunchrunner',
98 'runtime_constraints': {
99 'docker_image': 'arvados/jobs',
100 'min_cores_per_node': 3,
101 'min_ram_mb_per_node': 3000,
102 'min_scratch_mb_per_node': 5024 # tmpdirSize + outdirSize
106 filters=[['repository', '=', 'arvados'],
107 ['script', '=', 'crunchrunner'],
108 ['script_version', 'in git', '9e5b98e8f5f4727856b53447191f9c06e3da2ba6'],
109 ['docker_image_locator', 'in docker', 'arvados/jobs']])
111 @mock.patch("arvados.collection.Collection")
112 def test_done(self, col):
113 api = mock.MagicMock()
115 runner = mock.MagicMock()
117 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
118 runner.num_retries = 0
119 runner.ignore_docker_for_reuse = False
121 col().open.return_value = []
122 api.collections().list().execute.side_effect = ({"items": []},
123 {"items": [{"manifest_text": "XYZ"}]})
125 arvjob = arvados_cwl.ArvadosJob(runner)
126 arvjob.name = "testjob"
127 arvjob.builder = mock.MagicMock()
128 arvjob.output_callback = mock.MagicMock()
129 arvjob.collect_outputs = mock.MagicMock()
133 "output": "99999999999999999999999999999993+99",
134 "log": "99999999999999999999999999999994+99",
135 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
138 api.collections().list.assert_has_calls([
140 mock.call(filters=[['owner_uuid', '=', 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'],
141 ['portable_data_hash', '=', '99999999999999999999999999999993+99'],
142 ['name', '=', 'Output 9999999 of testjob']]),
143 mock.call().execute(num_retries=0),
144 mock.call(limit=1, filters=[['portable_data_hash', '=', '99999999999999999999999999999993+99']],
145 select=['manifest_text']),
146 mock.call().execute(num_retries=0)])
148 api.collections().create.assert_called_with(
149 ensure_unique_name=True,
150 body={'portable_data_hash': '99999999999999999999999999999993+99',
151 'manifest_text': 'XYZ',
152 'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
153 'name': 'Output 9999999 of testjob'})
155 @mock.patch("arvados.collection.Collection")
156 def test_done_use_existing_collection(self, col):
157 api = mock.MagicMock()
159 runner = mock.MagicMock()
161 runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
162 runner.num_retries = 0
164 col().open.return_value = []
165 api.collections().list().execute.side_effect = ({"items": [{"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2"}]},)
167 arvjob = arvados_cwl.ArvadosJob(runner)
168 arvjob.name = "testjob"
169 arvjob.builder = mock.MagicMock()
170 arvjob.output_callback = mock.MagicMock()
171 arvjob.collect_outputs = mock.MagicMock()
175 "output": "99999999999999999999999999999993+99",
176 "log": "99999999999999999999999999999994+99",
177 "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
180 api.collections().list.assert_has_calls([
182 mock.call(filters=[['owner_uuid', '=', 'zzzzz-8i9sb-zzzzzzzzzzzzzzz'],
183 ['portable_data_hash', '=', '99999999999999999999999999999993+99'],
184 ['name', '=', 'Output 9999999 of testjob']]),
185 mock.call().execute(num_retries=0)])
187 self.assertFalse(api.collections().create.called)