Skip to content
Snippets Groups Projects

Report error if dirs `/data/user` `/data/scratch` are not created.

1 file
+ 20
10
Compare changes
  • Side-by-side
  • Inline
+ 20
10
#!/usr/bin/env python
#!/usr/bin/env python
 
import os
import sys
import sys
import json
import json
import shutil
import shutil
@@ -19,7 +20,9 @@ def dir_verify(ch, method, properties, body):
@@ -19,7 +20,9 @@ def dir_verify(ch, method, properties, body):
msg = json.loads(body)
msg = json.loads(body)
username = msg['username']
username = msg['username']
msg['task'] = task
msg['task'] = task
msg['success'] = False
msg['success'] = True
 
 
missing_dirs = []
try:
try:
for d in dirs:
for d in dirs:
@@ -30,17 +33,24 @@ def dir_verify(ch, method, properties, body):
@@ -30,17 +33,24 @@ def dir_verify(ch, method, properties, body):
else:
else:
if not path.exists():
if not path.exists():
# Make sure folder exists and with right permission
# check if dirs exist and record any missing dirs
path.mkdir(mode=0o700, parents=True, exist_ok=True)
missing_dirs.append(path)
msg['success'] = False
# Make sure ownership is correct
msg['errmsg'] = f"Error: missing dirs {missing_dirs}"
shutil.chown(path, int(msg['uid']), int(msg['gid']))
logger.info(f'{path} does not exist')
else:
logger.debug(f'{path} created')
# check existing dirs for correct ownership and permissions
status = os.stat(path)
msg['success'] = True
mask = oct(status.st_mode)[-3:]
 
uid = str(status.st_uid)
 
gid = str(status.st_gid)
 
if mask!='700' or uid!=msg['uid'] or gid!=msg['gid']:
 
msg['success'] = False
 
msg['errmsg'] = f"Error: dir {path} permissions or ownership are wrong"
except Exception as exception:
except Exception as exception:
 
msg['success'] = False
 
msg['errmsg'] = "Exception raised, check the logs for stack trace"
logger.error('', exc_info=True)
logger.error('', exc_info=True)
# send confirm message
# send confirm message
Loading