Skip to content

Commit

Permalink
Have the rqd process carefully create log directories with correct pe…
Browse files Browse the repository at this point in the history
…rmissions.
  • Loading branch information
donalm committed Feb 6, 2021
1 parent 8179af8 commit 781d2de
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rqd/rqd/rqconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
RQD_TIMEOUT = 10000
DEFAULT_FACILITY = 'cloud'

# REBELLION CUSTOM VALUE - GID for vfxartists group
DEFAULT_FILESYSTEM_GROUP_ID=38731

# GRPC VALUES
RQD_GRPC_MAX_WORKERS = 10
RQD_GRPC_PORT = 8444
Expand Down
79 changes: 77 additions & 2 deletions rqd/rqd/rqcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from builtins import str
from builtins import object
import grp
import logging as log
import os
import platform
Expand Down Expand Up @@ -409,6 +410,81 @@ def runUnknown(self):
"""The steps required to handle a frame under an unknown OS"""
pass

def make_directory_for_frame(self, runFrame):
directory = runFrame.log_dir
head, tails = self.get_base_filepath(directory)
try:
os.makedirs(directory)
os.chmod(directory, 0o2770)
except Exception as e:
already_exists_error = 17
if hasattr(e, "errno") and e.errno == already_exists_error:
pass
elif not os.access(directory, os.F_OK):
err = "Unable to access: {}, mkdir failed with: {}".format(
directory, e
)
log.info(err)
raise RuntimeError(err)

try:
groupinfo = grp.getgrnam(runFrame.show)
gid = groupinfo.gr_gid
except Exception:
gid = rqd.rqconstants.DEFAULT_FILESYSTEM_GROUP_ID

"""
The directories we created will not be group-writeable, so we should
fix that and ensure the group is set correctly.
"""
fragment = head
for tail in tails:
fragment = os.path.join(fragment, tail)
try:
os.chown(fragment, -1, gid)
except Exception as e:
log.info(
"Failed to chown {}: {}".format(
fragment,
e
)
)

try:
os.chmod(fragment, 0o2770)
except Exception as e:
log.info(
"Failed to chmod {}: {}".format(
fragment,
e
)
)

def get_base_filepath(self, filepath):
"""
Return the prefix of a filepath that already exists, and any remaining path fragments as a list
"""
if filepath[0] != os.sep:
raise nfs_exceptions.NFSValueError(
"not an absolute path: {}".format(filepath), 103
)

head = filepath
tails = []
while True:
if not head:
msg = "failed to find base filepath of {}"
raise nfs_exceptions.NFSValueError(msg.format(filepath), 104)

if os.path.exists(head):
basepath = head
tails = list(reversed(tails))
return basepath, tails

head, tail = head.rsplit(os.sep, 1)
tails.append(tail)


def run(self):
"""Thread initialization"""
log.info("Monitor frame started for frameId=%s", self.frameId)
Expand Down Expand Up @@ -441,8 +517,7 @@ def run(self):
# Attempting mkdir for missing logdir
msg = "No Error"
try:
os.makedirs(runFrame.log_dir)
os.chmod(runFrame.log_dir, 0o777)
self.make_directory_for_frame(runFrame)
except Exception as e:
# This is expected to fail when called in abq
# But the directory should now be visible
Expand Down

0 comments on commit 781d2de

Please sign in to comment.