Skip to content

Commit 94a25a9

Browse files
Sp4cSh1pRobin-Van-de-Merghel
Sp4cSh1p
authored andcommitted
fix: Fixed linting and documentation
1 parent aa95e04 commit 94a25a9

File tree

7 files changed

+188
-118
lines changed

7 files changed

+188
-118
lines changed

.pylintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@ init-hook='import sys; sys.path.append("$WORKSPACE/DIRAC/WorkloadManagementSyste
99
# Add <file or directory> to the black list. It should be a base name, not a
1010
# path. You may set this option multiple times.
1111
ignore=.git
12+
13+
# For unused variables
14+
[VARIABLES]
15+
dummy-variables=_
16+
17+
[MESSAGES CONTROL]
18+
disable=
19+
invalid-name,
20+
line-too-long, # would be nice to remove this one
21+
consider-using-f-string, # python2/3 support
22+
unspecified-encoding, # python2/3 support
23+
super-with-arguments, # python2/3 support
24+
redefined-builtin, # python2/3 support

Pilot/dirac-pilot.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/usr/bin/env python
22

3-
""" The dirac-pilot.py script is a steering script to execute a series of
4-
pilot commands. The commands may be provided in the pilot input sandbox, and are coded in
5-
the pilotCommands.py module or in any <EXTENSION>Commands.py module.
6-
The pilot script defines two switches in order to choose a set of commands for the pilot:
3+
"""The dirac-pilot.py script is a steering script to execute a series of
4+
pilot commands. The commands may be provided in the pilot input sandbox, and are coded in
5+
the pilotCommands.py module or in any <EXTENSION>PilotCommands.py module (e.g. "LHCbPilotCommands.py")
6+
The pilot script defines two switches in order to choose a set of commands for the pilot:
77
8-
-E, --commandExtensions value
9-
where the value is a comma separated list of extension names. Modules
10-
with names <EXTENSION>Commands.py will be searched for the commands in
11-
the order defined in the value. By default no extensions are given
12-
-X, --commands value
13-
where value is a comma separated list of pilot commands. By default
14-
the list is InstallDIRAC,ConfigureDIRAC,LaunchAgent
8+
-E, --commandExtensions value
9+
where the value is a comma separated list of extension names. Modules
10+
with names <EXTENSION>PilotCommands.py will be searched for the commands in
11+
the order defined in the value. By default no extensions are given
12+
-X, --commands value
13+
where value is a comma separated list of pilot commands. By default
14+
the list is CheckWorkerNode,InstallDIRAC,ConfigureBasics,RegisterPilot,CheckCECapabilities,CheckWNCapabilities,
15+
ConfigureSite,ConfigureArchitecture,ConfigureCPURequirements,LaunchAgent
1516
16-
The pilot script by default performs initial sanity checks on WN, installs and configures
17-
DIRAC and runs the Job Agent to execute pending workloads in the DIRAC WMS.
18-
But, as said, all the actions are actually configurable.
17+
The pilot script by default performs initial sanity checks on WN, installs and configures
18+
DIRAC and runs the DIRAC JobAgent (https://github.com/DIRACGrid/DIRAC/blob/integration/src/DIRAC/WorkloadManagementSystem/Agent/JobAgent.py) to execute pending workloads in the DIRAC WMS.
19+
But, as said, all the actions are actually configurable.
1920
"""
2021

2122
from __future__ import absolute_import, division, print_function
@@ -70,8 +71,12 @@
7071
if not sys.stdin.isatty():
7172
receivedContent = sys.stdin.read()
7273
log = RemoteLogger(
73-
pilotParams.loggerURL, "Pilot", bufsize=pilotParams.loggerBufsize,
74-
pilotUUID=pilotParams.pilotUUID, debugFlag=pilotParams.debugFlag, wnVO=pilotParams.wnVO,
74+
pilotParams.loggerURL,
75+
"Pilot",
76+
bufsize=pilotParams.loggerBufsize,
77+
pilotUUID=pilotParams.pilotUUID,
78+
debugFlag=pilotParams.debugFlag,
79+
wnVO=pilotParams.wnVO,
7580
)
7681
log.info("Remote logger activated")
7782
log.buffer.write(receivedContent)

Pilot/pilotCommands.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
""" Definitions of a standard set of pilot commands
1+
"""Definitions of a standard set of pilot commands
22
3-
Each command is represented by a class inheriting from CommandBase class.
4-
The command class constructor takes PilotParams object which is a data
5-
structure which keeps common parameters across all the pilot commands.
3+
Each command is represented by a class inheriting from CommandBase class.
4+
The command class constructor takes PilotParams object which is a data
5+
structure which keeps common parameters across all the pilot commands.
66
7-
The constructor must call the superclass constructor with the PilotParams
8-
object and the command name as arguments, e.g.::
7+
The constructor must call the superclass constructor with the PilotParams
8+
object and the command name as arguments, e.g.::
99
10-
class InstallDIRAC(CommandBase):
10+
class InstallDIRAC(CommandBase):
1111
12-
def __init__(self, pilotParams):
13-
CommandBase.__init__(self, pilotParams, 'Install')
14-
...
12+
def __init__(self, pilotParams):
13+
CommandBase.__init__(self, pilotParams, 'Install')
14+
...
1515
16-
The command class must implement execute() method for the actual command
17-
execution.
16+
The command class must implement execute() method for the actual command
17+
execution.
1818
"""
1919

2020
from __future__ import absolute_import, division, print_function
@@ -65,7 +65,7 @@ def __init__(self, pilotParams):
6565

6666
def logFinalizer(func):
6767
"""
68-
PilotCammand decorator. It marks a log file as final so no more messages should be written to it .
68+
PilotCommand decorator. It marks a log file as final so no more messages should be written to it.
6969
Finalising is triggered by a return statement or any sys.exit() call, so a file might be incomplete
7070
if a command throws SystemExit exception with a code =! 0.
7171
@@ -104,6 +104,7 @@ def wrapper(self):
104104
raise
105105
finally:
106106
self.log.buffer.cancelTimer()
107+
107108
return wrapper
108109

109110

@@ -206,17 +207,15 @@ def execute(self):
206207

207208

208209
class InstallDIRAC(CommandBase):
209-
""" Source from CVMFS, or install locally
210-
"""
210+
"""Source from CVMFS, or install locally"""
211211

212212
def __init__(self, pilotParams):
213213
"""c'tor"""
214214
super(InstallDIRAC, self).__init__(pilotParams)
215215
self.pp.rootPath = self.pp.pilotRootPath
216216

217217
def _sourceEnvironmentFile(self):
218-
"""source the $DIRAC_RC_FILE and save the created environment in self.pp.installEnv
219-
"""
218+
"""Source the $DIRAC_RC_FILE and save the created environment in self.pp.installEnv"""
220219

221220
retCode, output = self.executeAndGetOutput("bash -c 'source $DIRAC_RC_PATH && env'", self.pp.installEnv)
222221
if retCode:
@@ -249,12 +248,12 @@ def _saveEnvInFile(self, eFile="environmentSourceDirac"):
249248
fd.write(bl)
250249

251250
def _getPreinstalledEnvScript(self):
252-
""" Get preinstalled environment script if any """
251+
"""Get preinstalled environment script if any"""
253252

254253
self.log.debug("self.pp.preinstalledEnv = %s" % self.pp.preinstalledEnv)
255254
self.log.debug("self.pp.preinstalledEnvPrefix = %s" % self.pp.preinstalledEnvPrefix)
256255
self.log.debug("self.pp.CVMFS_locations = %s" % self.pp.CVMFS_locations)
257-
256+
258257
preinstalledEnvScript = self.pp.preinstalledEnv
259258
if not preinstalledEnvScript and self.pp.preinstalledEnvPrefix:
260259
version = self.pp.releaseVersion or "pro"
@@ -265,7 +264,9 @@ def _getPreinstalledEnvScript(self):
265264
for CVMFS_location in self.pp.CVMFS_locations:
266265
version = self.pp.releaseVersion or "pro"
267266
arch = platform.system() + "-" + platform.machine()
268-
preinstalledEnvScript = os.path.join(CVMFS_location, self.pp.releaseProject.lower() + "dirac", version, arch, "diracosrc")
267+
preinstalledEnvScript = os.path.join(
268+
CVMFS_location, self.pp.releaseProject.lower() + "dirac", version, arch, "diracosrc"
269+
)
269270
if os.path.isfile(preinstalledEnvScript):
270271
break
271272

@@ -280,11 +281,11 @@ def _getPreinstalledEnvScript(self):
280281
self.pp.preinstalledEnv = preinstalledEnvScript
281282
self.pp.installEnv["DIRAC_RC_PATH"] = preinstalledEnvScript
282283

283-
284284
def _localInstallDIRAC(self):
285+
"""Install python3 version of DIRAC client"""
286+
285287
self.log.info("Installing DIRAC locally")
286288

287-
"""Install python3 version of DIRAC client"""
288289
# default to limit the resources used during installation to what the pilot owns
289290
installEnv = {
290291
# see https://github.com/DIRACGrid/Pilot/issues/189
@@ -353,7 +354,7 @@ def _localInstallDIRAC(self):
353354
self.pp.installEnv["DIRAC_RC_PATH"] = os.path.join(os.getcwd(), "diracos/diracosrc")
354355
self._sourceEnvironmentFile()
355356
self._saveEnvInFile()
356-
357+
357358
# 7. pip install DIRAC[pilot]
358359
pipInstalling = "pip install %s " % self.pp.pipInstallOptions
359360

@@ -401,7 +402,7 @@ def execute(self):
401402
self.log.info("NOT sourcing: starting traditional DIRAC installation")
402403
self._localInstallDIRAC()
403404
return
404-
405+
405406
# Try sourcing from CVMFS
406407
self._getPreinstalledEnvScript()
407408
if not self.pp.preinstalledEnv:
@@ -413,10 +414,8 @@ def execute(self):
413414
# environment variables to add?
414415
if self.pp.userEnvVariables:
415416
# User-requested environment variables (comma-separated, name and value separated by ":::")
416-
newEnvVars = dict(
417-
name.split(":::", 1) for name in self.pp.userEnvVariables.replace(" ", "").split(",")
418-
)
419-
self.log.info("Adding env variable(s) to the environment", newEnvVars)
417+
newEnvVars = dict(name.split(":::", 1) for name in self.pp.userEnvVariables.replace(" ", "").split(","))
418+
self.log.info("Adding env variable(s) to the environment : %s" % newEnvVars)
420419
self.pp.installEnv.update(newEnvVars)
421420

422421
except OSError as e:
@@ -524,8 +523,7 @@ def _getBasicsCFG(self):
524523
self.cfg.append('-o "/Resources/Computing/CEDefaults/VirtualOrganization=%s"' % self.pp.wnVO)
525524

526525
def _getSecurityCFG(self):
527-
""" Sets security-related env variables, if needed
528-
"""
526+
"""Sets security-related env variables, if needed"""
529527
# Need to know host cert and key location in case they are needed
530528
if self.pp.useServerCertificate:
531529
self.cfg.append("--UseServerCertificate")
@@ -765,9 +763,13 @@ def execute(self):
765763

766764
batchSystemParams = self.pp.batchSystemInfo.get("Parameters", {})
767765
self.cfg.append("-o /LocalSite/BatchSystemInfo/Parameters/Queue=%s" % batchSystemParams.get("Queue", "Unknown"))
768-
self.cfg.append("-o /LocalSite/BatchSystemInfo/Parameters/BinaryPath=%s" % batchSystemParams.get("BinaryPath", "Unknown"))
766+
self.cfg.append(
767+
"-o /LocalSite/BatchSystemInfo/Parameters/BinaryPath=%s" % batchSystemParams.get("BinaryPath", "Unknown")
768+
)
769769
self.cfg.append("-o /LocalSite/BatchSystemInfo/Parameters/Host=%s" % batchSystemParams.get("Host", "Unknown"))
770-
self.cfg.append("-o /LocalSite/BatchSystemInfo/Parameters/InfoPath=%s" % batchSystemParams.get("InfoPath", "Unknown"))
770+
self.cfg.append(
771+
"-o /LocalSite/BatchSystemInfo/Parameters/InfoPath=%s" % batchSystemParams.get("InfoPath", "Unknown")
772+
)
771773

772774
self.cfg.append('-n "%s"' % self.pp.site)
773775
self.cfg.append('-S "%s"' % self.pp.setup)
@@ -849,7 +851,7 @@ def execute(self):
849851
localArchitecture = localArchitecture.strip().split("\n")[-1].strip()
850852
cfg.append('-S "%s"' % self.pp.setup)
851853
cfg.append("-o /LocalSite/Architecture=%s" % localArchitecture)
852-
854+
853855
# add the local platform as determined by the platform module
854856
cfg.append("-o /LocalSite/Platform=%s" % platform.machine())
855857

@@ -1123,6 +1125,8 @@ def _runNagiosProbes(self):
11231125
self.log.error("Return code = %d: %s" % (retCode, str(output).split("\n", 1)[0]))
11241126
retStatus = "error"
11251127

1128+
# TODO: Do something with the retStatus (for example: log it?)
1129+
11261130
# report results to pilot logger too. Like this:
11271131
# "NagiosProbes", probeCmd, retStatus, str(retCode) + ' ' + output.split('\n',1)[0]
11281132

0 commit comments

Comments
 (0)