Skip to content

Commit

Permalink
Fix 4755 (#4758)
Browse files Browse the repository at this point in the history
* better variable name undoScram

* unset scram env before calling gfal*. Fixes #4755

* fix bug pointed out by Leonardo in #4758 (comment)
  • Loading branch information
belforte authored and lecriste committed Apr 23, 2018
1 parent c7c4fdd commit 57c32a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/python/CRABClient/ClientUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ def getUserDN():
"""
Retrieve the user DN from the proxy.
"""
scram_cmd = 'which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`'
undoScram = 'which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`'
## Check if there is a proxy.
cmd = scram_cmd + "; voms-proxy-info"
cmd = undoScram + "; voms-proxy-info"
process = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
stdout, stderr = process.communicate()
if process.returncode or not stdout:
Expand All @@ -474,7 +474,7 @@ def getUserDN():
msg += "\n Stderr:\n %s" % (str(stderr).replace('\n', '\n '))
raise ProxyException(msg)
## Retrieve DN from proxy.
cmd = scram_cmd + "; voms-proxy-info -identity"
cmd = undoScram + "; voms-proxy-info -identity"
process = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
stdout, stderr = process.communicate()
if process.returncode or not stdout:
Expand Down
30 changes: 17 additions & 13 deletions src/python/CRABClient/Commands/checkwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,29 @@ def __call__(self):
## Check that the location where we want to check write permission
## is one where the user will be allowed to stageout.
self.logger.info("Validating LFN %s..." % (self.lfnsaddprefix))
msg = "Refusing to check write permission in %s, because this is not an allowed LFN for stageout." % (self.lfnsaddprefix)
msg += "\nThe LFN must start with either"
msg += " '/store/user/<username>/' or '/store/group/<groupname>/'"
msg += " (or '/store/local/<something>/' if publication is off),"
msg += " where username is your username as registered in SiteDB"
msg += " (i.e. the username of your CERN primary account)."
msg += "\nLFN %s is not valid." % (self.lfnsaddprefix)
# if an error message is needed later, prepare it now to keep code below tidy
errMsg = "Refusing to check write permission in %s, because this is not an allowed LFN for stageout." % (self.lfnsaddprefix)
errMsg += "\nThe LFN must start with either"
errMsg += " '/store/user/<username>/' or '/store/group/<groupname>/'"
errMsg += " (or '/store/local/<something>/' if publication is off),"
errMsg += " where username is your username as registered in SiteDB"
errMsg += " (i.e. the username of your CERN primary account)."
errMsg += "\nLFN %s is not valid." % (self.lfnsaddprefix)

if not username and self.lfnsaddprefix.startswith('/store/user/'):
username = getUserDNandUsernameFromSiteDB(self.logger).get('username')
if not checkOutLFN(self.lfnsaddprefix, username):
self.logger.info(msg)
self.logger.info(errMsg)
return {'status': 'FAILED'}
else:
self.logger.info("LFN %s is valid." % (self.lfnsaddprefix))

cp_cmd = ""
if cmd_exist("gfal-copy") and cmd_exist("gfal-rm") and self.command in [None, "GFAL"]:
self.logger.info("Will use `gfal-copy`, `gfal-rm` commands for checking write permissions")
cp_cmd = "env -i X509_USER_PROXY=%s gfal-copy -p -v -t 180 " % os.path.abspath(self.proxyfilename)
delfile_cmd = "env -i X509_USER_PROXY=%s gfal-rm -v -t 180 " % os.path.abspath(self.proxyfilename)
deldir_cmd = "env -i X509_USER_PROXY=%s gfal-rm -r -v -t 180 " % os.path.abspath(self.proxyfilename)
cp_cmd = "gfal-copy -p -v -t 180 "
delfile_cmd = "gfal-rm -v -t 180 "
deldir_cmd = "gfal-rm -r -v -t 180 "
if self.checksum:
cp_cmd += "-K %s " % self.checksum
elif cmd_exist("lcg-cp") and cmd_exist("lcg-del"):
Expand Down Expand Up @@ -184,7 +186,8 @@ def cp(self, pfn, command):
abspath = os.path.abspath(self.filename)
if cmd_exist("gfal-copy") and self.command in [None, "GFAL"]:
abspath = "file://" + abspath
cpcmd = command + abspath + " '" + pfn + "'"
undoScram = "which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`"
cpcmd = undoScram + "; " + command + abspath + " '" + pfn + "'"
self.logger.info('Executing command: %s' % cpcmd)
self.logger.info('Please wait...')
cpprocess = subprocess.Popen(cpcmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
Expand All @@ -202,7 +205,8 @@ def cp(self, pfn, command):

def delete(self, pfn, command):

rmcmd = command + "'" + pfn + "'"
undoScram = "which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`"
rmcmd = undoScram + "; " + command + "'" + pfn + "'"
self.logger.info('Executing command: %s' % rmcmd)
self.logger.info('Please wait...')
delprocess = subprocess.Popen(rmcmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
Expand Down
8 changes: 5 additions & 3 deletions src/python/CRABClient/Commands/remote_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __call__(self):
command = ""
if cmd_exist("gfal-copy") and self.options.command not in ["LCG"]:
self.logger.info("Will use `gfal-copy` command for file transfers")
command = "env -i X509_USER_PROXY=%s gfal-copy -v " % os.path.abspath(self.proxyfilename)
command = "gfal-copy -v "
if self.options.checksum:
command += "-K %s " % self.options.checksum
command += " -T "
Expand Down Expand Up @@ -140,14 +140,16 @@ def __call__(self):
continue

##### Creating the command
# better to execut grid commands in the pre-CMS environment
undoScram = "which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`"

# timeout based on file size and download speed * 2
maxtime = srmtimeout if not 'size' in myfile or myfile['size'] == 0 else int(ceil(2*myfile['size']/downspeed))
localsrmtimeout = minsrmtimeout if maxtime < minsrmtimeout else maxtime # do not want a too short timeout

timeout = " --srm-timeout "
if cmd_exist("gfal-copy") and self.options.command not in ["LCG"]:
timeout = " -t "
cmd = '%s %s %s %%s' % (command, timeout + str(localsrmtimeout) + ' ', myfile['pfn'])
cmd = undoScram + '; %s %s %s %%s' % (command, timeout + str(localsrmtimeout) + ' ', myfile['pfn'])
if url_input:
cmd = cmd % localFilename
else:
Expand Down
8 changes: 4 additions & 4 deletions src/python/CRABClient/UserUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def getUsernameFromSiteDB():
https://cmsweb.cern.ch/sitedb/data/prod/whoami
using the users proxy.
"""
scram_cmd = "which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`"
undoScram = "which scram >/dev/null 2>&1 && eval `scram unsetenv -sh`"
## Check if there is a proxy.
cmd = scram_cmd + "; voms-proxy-info"
cmd = undoScram + "; voms-proxy-info"
process = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
stdout, stderr = process.communicate()
if process.returncode or not stdout:
Expand All @@ -56,7 +56,7 @@ def getUsernameFromSiteDB():
raise ProxyException(msg)
## Check if proxy is valid.
#proxyTimeLeft = [x[x.find(':')+2:] for x in stdout.split('\n') if 'timeleft' in x][0]
cmd = scram_cmd + "; voms-proxy-info -timeleft"
cmd = undoScram + "; voms-proxy-info -timeleft"
process = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
stdout, stderr = process.communicate()
if process.returncode or not stdout:
Expand All @@ -72,7 +72,7 @@ def getUsernameFromSiteDB():
msg += "\nProxy time left = %s seconds. Please renew your proxy." % (proxyTimeLeft)
raise ProxyException(msg)
## Retrieve proxy file location.
cmd = scram_cmd + "; voms-proxy-info -path"
cmd = undoScram + "; voms-proxy-info -path"
process = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
stdout, stderr = process.communicate()
if process.returncode or not stdout:
Expand Down

0 comments on commit 57c32a7

Please sign in to comment.