@@ -224,7 +224,7 @@ def _copy_inputs(test_inputs: List[str], project_path: str) -> bool:
224224 return True
225225
226226
227- def _check_exists (name : str , path : str , expected : bool ) -> bool :
227+ def _check_exists (name : str , path : str , expected : bool , fix_permissions : bool ) -> bool :
228228
229229 exists : bool = os .path .exists (path )
230230 if expected and not exists :
@@ -239,8 +239,11 @@ def _check_exists(name: str, path: str, expected: bool) -> bool:
239239 return False
240240
241241 # File exists or does not exist, as expected.
242- # If it exists we check its 'user' and group read and write permission.
243- # All files generated must be writable by the group (project).
242+ # If it exists we check its 'user' and 'group' read and write permission.
243+ #
244+ # If 'fix_permissions' is True (i.e. the DM is expected to fix (group) permissions)
245+ # the group permissions are expected to be incorrect. If False
246+ # then the group permissions are expected to be correct/
244247 if exists :
245248 stat_info : os .stat_result = os .stat (path )
246249 # Check user permissions
@@ -254,12 +257,25 @@ def _check_exists(name: str, path: str, expected: bool) -> bool:
254257 return False
255258 # Check group permissions
256259 if file_mode & S_IRGRP == 0 or file_mode & S_IWGRP == 0 :
257- print ("! FAILURE" )
258- print (
259- f'! "{ name } " exists but has incorrect group permissions'
260- f" ({ stat .filemode (file_mode )} )"
261- )
262- return False
260+ # Incorrect permissions.
261+ if not fix_permissions :
262+ # And not told to fix them!
263+ print ("! FAILURE" )
264+ print (
265+ f'! "{ name } " exists but has incorrect group permissions (fix-permissions=False)'
266+ f" ({ stat .filemode (file_mode )} )"
267+ )
268+ return False
269+ else :
270+ # Correct group permissions.
271+ if fix_permissions :
272+ # But told to fix them!
273+ print ("! FAILURE" )
274+ print (
275+ f'! "{ name } " exists but has correct group permissions (fix-permissions=True)'
276+ f" ({ stat .filemode (file_mode )} )"
277+ )
278+ return False
263279
264280 print (f"# exists ({ expected } ) [OK]" )
265281 return True
@@ -282,9 +298,13 @@ def _check_line_count(name: str, path: str, expected: int) -> bool:
282298 return True
283299
284300
285- def _check (t_compose : Compose , output_checks : DefaultMunch ) -> bool :
301+ def _check (
302+ t_compose : Compose , output_checks : DefaultMunch , fix_permissions : bool
303+ ) -> bool :
286304 """Runs the checks on the Job outputs.
287305 We currently support 'exists' and 'lineCount'.
306+ If 'fix_permissions' is True we error if the permissions are correct,
307+ if False we error if the permissions are not correct.
288308 """
289309 assert t_compose
290310 assert isinstance (t_compose , Compose )
@@ -303,7 +323,9 @@ def _check(t_compose: Compose, output_checks: DefaultMunch) -> bool:
303323 for check in output_check .checks :
304324 check_type : str = list (check .keys ())[0 ]
305325 if check_type == "exists" :
306- if not _check_exists (output_name , expected_file , check .exists ):
326+ if not _check_exists (
327+ output_name , expected_file , check .exists , fix_permissions
328+ ):
307329 return False
308330 elif check_type == "lineCount" :
309331 if not _check_line_count (output_name , expected_file , check .lineCount ):
@@ -392,6 +414,13 @@ def _test(
392414 job_image_type : str = job_definition .image ["type" ].lower ()
393415 else :
394416 job_image_type = _DEFAULT_IMAGE_TYPE
417+ # Does the image need the (group write) permissions
418+ # of files it creates fixing? Default is 'no'.
419+ # If 'yes' (true) the DM is expected to fix the permissions of the
420+ # generated files once the job has finished.
421+ job_image_fix_permissions : bool = False
422+ if "fix-permissions" in job_definition .image :
423+ job_image_fix_permissions = job_definition .image ["fix-permissions" ]
395424
396425 for job_test_name in job_definition .tests :
397426
@@ -647,7 +676,9 @@ def _test(
647676
648677 assert t_compose
649678 test_status = _check (
650- t_compose , job_definition .tests [job_test_name ].checks .outputs
679+ t_compose ,
680+ job_definition .tests [job_test_name ].checks .outputs ,
681+ job_image_fix_permissions ,
651682 )
652683
653684 # Clean-up
0 commit comments