Skip to content

Commit

Permalink
fix: several fixes for return codes of DIRAC scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Jan 28, 2025
1 parent 83beaee commit aba9943
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/DIRAC/FrameworkSystem/scripts/dirac_admin_get_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import os

import DIRAC
from DIRAC import gLogger, S_OK, S_ERROR
from DIRAC import S_ERROR, S_OK, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
from DIRAC.Core.Base.Script import Script
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
from DIRAC.ConfigurationSystem.Client.Helpers import Registry


class Params:
Expand Down
7 changes: 3 additions & 4 deletions src/DIRAC/FrameworkSystem/scripts/dirac_admin_proxy_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
Example:
$ dirac-admin-proxy-upload
"""
import sys

from DIRAC import exit as dExit
from DIRAC.Core.Base.Script import Script
from DIRAC.FrameworkSystem.Client.ProxyUpload import CLIParams, uploadProxy

Expand All @@ -25,8 +24,8 @@ def main():
retVal = uploadProxy(cliParams)
if not retVal["OK"]:
print(retVal["Message"])
sys.exit(1)
sys.exit(0)
dExit(1)
dExit(0)


if __name__ == "__main__":
Expand Down
9 changes: 4 additions & 5 deletions src/DIRAC/FrameworkSystem/scripts/dirac_proxy_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main():
Script.disableCS()
Script.parseCommandLine()

from DIRAC import gLogger
from DIRAC import gLogger, exit as dExit
from DIRAC.Core.Security.ProxyInfo import getProxyInfo, getProxyStepsInfo
from DIRAC.Core.Security.ProxyInfo import formatProxyInfoAsString, formatProxyStepsInfoAsString
from DIRAC.Core.Security import VOMS
Expand All @@ -86,7 +86,7 @@ def main():
result = getProxyInfo(params.proxyLoc, not params.vomsEnabled)
if not result["OK"]:
gLogger.error(result["Message"])
sys.exit(1)
dExit(1)
infoDict = result["Value"]
gLogger.notice(formatProxyInfoAsString(infoDict))
if not infoDict["isProxy"]:
Expand All @@ -100,12 +100,13 @@ def main():

def invalidProxy(msg):
gLogger.error("Invalid proxy:", msg)
sys.exit(1)
dExit(1)

if params.uploadedInfo:
result = gProxyManager.getUserProxiesInfo()
if not result["OK"]:
gLogger.error("Could not retrieve the uploaded proxies info", result["Message"])
dExit(1)
else:
uploadedInfo = result["Value"]
if not uploadedInfo:
Expand Down Expand Up @@ -150,8 +151,6 @@ def invalidProxy(msg):
if int(result["Value"].strip()) == 0:
invalidProxy("VOMS attributes are expired")

sys.exit(0)


if __name__ == "__main__":
main()
9 changes: 6 additions & 3 deletions src/DIRAC/Interfaces/scripts/dirac_admin_list_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def printUsersInGroup(group=False):
print("All users registered:")
for username in result["Value"]:
print(f" {username}")
else:
print(result["Message"])
DIRAC.exit(1)

def describeUsersInGroup(group=False):
result = diracAdmin.csListUsers(group)
Expand All @@ -55,6 +58,9 @@ def describeUsersInGroup(group=False):
print("All users registered:")
result = diracAdmin.csDescribeUsers(result["Value"])
print(diracAdmin.pPrint.pformat(result["Value"]))
else:
print(result["Message"])
DIRAC.exit(1)

for group in args:
if "all" in args:
Expand All @@ -64,9 +70,6 @@ def describeUsersInGroup(group=False):
else:
describeUsersInGroup(group)

for error in errorList:
print("ERROR %s: %s" % error)

DIRAC.exit(exitCode)


Expand Down
4 changes: 1 addition & 3 deletions src/DIRAC/Interfaces/scripts/dirac_admin_pilot_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def main():
diracAdmin = DiracAdmin()

result = diracAdmin.getPilotSummary()
if result["OK"]:
DIRAC.exit(0)
else:
if not result["OK"]:
print(result["Message"])
DIRAC.exit(2)

Expand Down
4 changes: 1 addition & 3 deletions src/DIRAC/Interfaces/scripts/dirac_admin_service_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def main():

diracAdmin = DiracAdmin()
result = diracAdmin.getServicePorts(setup, printOutput=True)
if result["OK"]:
DIRAC.exit(0)
else:
if not result["OK"]:
print(result["Message"])
DIRAC.exit(2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
usersCFG = CFG().loadFromFile(args[0])
except Exception as e:
errorList.append(("file open", f"Can't parse file {args[0]}: {str(e)}"))
errorCode = 1
exitCode = 1
else:
if not diracAdmin.csSyncUsersWithCFG(usersCFG):
errorList.append(("modify users", f"Cannot sync with {args[0]}"))
Expand Down
1 change: 0 additions & 1 deletion src/DIRAC/Interfaces/scripts/dirac_dms_lfn_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def main():

dirac = Dirac()
exitCode = 0
errorList = []

if len(lfns) == 1:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main():
exitCode = 2
elif not result["OK"]:
print("ERROR: ", result["Message"])
exitCode = 2
exitCode = 1

DIRAC.exit(exitCode)

Expand Down
5 changes: 1 addition & 4 deletions src/DIRAC/Interfaces/scripts/dirac_repo_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ def main():

dirac = Dirac(withRepo=True, repoLocation=repoLocation)

exitCode = 0
result = dirac.monitorRepository(printOutput=True)
if not result["OK"]:
print("ERROR: ", result["Message"])
exitCode = 2

DIRAC.exit(exitCode)
DIRAC.exit(2)


if __name__ == "__main__":
Expand Down
9 changes: 3 additions & 6 deletions src/DIRAC/Interfaces/scripts/dirac_wms_job_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
$ dirac-wms-job-status 2
JobID=2 Status=Done; MinorStatus=Execution Complete; Site=EELA.UTFSM.cl;
"""
import os
import datetime
import os

from DIRAC.Core.Base.Script import Script


Expand All @@ -28,7 +29,6 @@ def main():
from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

dirac = Dirac()
exitCode = 0

jobs = []
for key, value in sws:
Expand Down Expand Up @@ -58,12 +58,9 @@ def main():
print("JobID=" + str(job), end=" ")
for status in result["Value"][job].items():
print("%s=%s;" % status, end=" ")
print()
else:
exitCode = 2
print(f"ERROR: {result['Message']}")

DIRACExit(exitCode)
DIRACExit(2)


if __name__ == "__main__":
Expand Down

0 comments on commit aba9943

Please sign in to comment.