From c646110093aa1972e4628524adac804db33573a9 Mon Sep 17 00:00:00 2001 From: Greg Daues Date: Mon, 16 Oct 2023 13:28:16 -0700 Subject: [PATCH 1/2] add user scratch as a configurable item in condor-info --- python/lsst/ctrl/execute/allocator.py | 28 +++++++++++++------- python/lsst/ctrl/execute/condorInfoConfig.py | 1 + python/lsst/ctrl/execute/slurmPlugin.py | 4 +-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/python/lsst/ctrl/execute/allocator.py b/python/lsst/ctrl/execute/allocator.py index 7f55eaf..deccaa7 100644 --- a/python/lsst/ctrl/execute/allocator.py +++ b/python/lsst/ctrl/execute/allocator.py @@ -64,22 +64,18 @@ def __init__(self, platform, opts, configuration, condorInfoFileName): self.platform = platform - # Look up the user's name and home directory in the + # Look up the user's name and home directory and scratch directory in the # $HOME/.lsst/condor-info.py file - # If the platform is lsst, and the user_name or user_home - # is not in there, then default to user running this - # command and the value of $HOME, respectively. user_name = None user_home = None + user_scratch = None for name in condorInfoConfig.platform: if name == self.platform: user_name = condorInfoConfig.platform[name].user.name user_home = condorInfoConfig.platform[name].user.home - if self.platform == "lsst": - if user_name is None: - user_name = pwd.getpwuid(os.geteuid()).pw_name - if user_home is None: - user_home = os.getenv("HOME") + user_scratch = condorInfoConfig.platform[name].user.scratch + if user_scratch is None and "SCRATCH" in os.environ: + user_scratch = os.environ["SCRATCH"] if user_name is None: raise RuntimeError( "error: %s does not specify user name for platform == %s" @@ -90,8 +86,14 @@ def __init__(self, platform, opts, configuration, condorInfoFileName): "error: %s does not specify user home for platform == %s" % (condorInfoFileName, self.platform) ) + if user_scratch is None: + raise RuntimeError( + "error: %s does not specify user scratch for platform == %s" + % (condorInfoFileName, self.platform) + ) self.defaults["USER_NAME"] = user_name self.defaults["USER_HOME"] = user_home + self.defaults["USER_SCRATCH"] = user_scratch self.commandLineDefaults = {} self.commandLineDefaults["NODE_COUNT"] = self.opts.nodeCount self.commandLineDefaults["CPUS"] = self.opts.cpus @@ -135,7 +137,7 @@ def load(self): """ tempLocalScratch = Template(self.configuration.platform.localScratch) self.defaults["LOCAL_SCRATCH"] = tempLocalScratch.substitute( - USER_NAME=self.defaults["USER_NAME"] + USER_SCRATCH=self.defaults["USER_SCRATCH"] ) # print("localScratch-> %s" % self.defaults["LOCAL_SCRATCH"]) self.defaults["SCHEDULER"] = self.configuration.platform.scheduler @@ -270,6 +272,12 @@ def getUserHome(self): """ return self.getParameter("USER_HOME") + def getUserScratch(self): + """Accessor for USER_SCRATCH + @return the value of USER_SCRATCH + """ + return self.getParameter("USER_SCRATCH") + def getHostName(self): """Accessor for HOST_NAME @return the value of HOST_NAME diff --git a/python/lsst/ctrl/execute/condorInfoConfig.py b/python/lsst/ctrl/execute/condorInfoConfig.py index 42064b0..8387fb1 100644 --- a/python/lsst/ctrl/execute/condorInfoConfig.py +++ b/python/lsst/ctrl/execute/condorInfoConfig.py @@ -39,6 +39,7 @@ class UserInfoConfig(pexConfig.Config): name = pexConfig.Field(doc="user login name", dtype=str, default=None) home = pexConfig.Field(doc="user home directory", dtype=str, default=None) + scratch = pexConfig.Field(doc="user scratch directory", dtype=str, default=None) class UserConfig(pexConfig.Config): diff --git a/python/lsst/ctrl/execute/slurmPlugin.py b/python/lsst/ctrl/execute/slurmPlugin.py index d78133e..06fa8f7 100644 --- a/python/lsst/ctrl/execute/slurmPlugin.py +++ b/python/lsst/ctrl/execute/slurmPlugin.py @@ -68,7 +68,7 @@ def submit(self, platform, platformPkgDir): # run the sbatch command template = Template(self.getLocalScratchDirectory()) - localScratchDir = template.substitute(USER_NAME=self.getUserName()) + localScratchDir = template.substitute(USER_SCRATCH=self.getUserScratch()) if not os.path.exists(localScratchDir): os.mkdir(localScratchDir) os.chdir(localScratchDir) @@ -116,7 +116,7 @@ def loadSlurm(self, name, platformPkgDir): allocationConfig = self.loadAllocationConfig(name, "slurm") template = Template(allocationConfig.platform.scratchDirectory) - scratchDir = template.substitute(USER_NAME=self.getUserName()) + scratchDir = template.substitute(USER_SCRATCH=self.getUserScratch()) self.defaults["SCRATCH_DIR"] = scratchDir self.allocationFileName = os.path.join( From 3251f3dcb751e1c0edd223e18ef82b47c7560df2 Mon Sep 17 00:00:00 2001 From: Greg Daues Date: Mon, 16 Oct 2023 13:39:04 -0700 Subject: [PATCH 2/2] white space and shorten comment --- python/lsst/ctrl/execute/allocator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lsst/ctrl/execute/allocator.py b/python/lsst/ctrl/execute/allocator.py index deccaa7..8342d81 100644 --- a/python/lsst/ctrl/execute/allocator.py +++ b/python/lsst/ctrl/execute/allocator.py @@ -64,7 +64,7 @@ def __init__(self, platform, opts, configuration, condorInfoFileName): self.platform = platform - # Look up the user's name and home directory and scratch directory in the + # Look up the user's name and home and scratch directory in the # $HOME/.lsst/condor-info.py file user_name = None user_home = None @@ -74,8 +74,8 @@ def __init__(self, platform, opts, configuration, condorInfoFileName): user_name = condorInfoConfig.platform[name].user.name user_home = condorInfoConfig.platform[name].user.home user_scratch = condorInfoConfig.platform[name].user.scratch - if user_scratch is None and "SCRATCH" in os.environ: - user_scratch = os.environ["SCRATCH"] + if user_scratch is None and "SCRATCH" in os.environ: + user_scratch = os.environ["SCRATCH"] if user_name is None: raise RuntimeError( "error: %s does not specify user name for platform == %s"