1
- """ Definitions of a standard set of pilot commands
1
+ """Definitions of a standard set of pilot commands
2
2
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.
6
6
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.::
9
9
10
- class InstallDIRAC(CommandBase):
10
+ class InstallDIRAC(CommandBase):
11
11
12
- def __init__(self, pilotParams):
13
- CommandBase.__init__(self, pilotParams, 'Install')
14
- ...
12
+ def __init__(self, pilotParams):
13
+ CommandBase.__init__(self, pilotParams, 'Install')
14
+ ...
15
15
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.
18
18
"""
19
19
20
20
from __future__ import absolute_import , division , print_function
@@ -65,7 +65,7 @@ def __init__(self, pilotParams):
65
65
66
66
def logFinalizer (func ):
67
67
"""
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.
69
69
Finalising is triggered by a return statement or any sys.exit() call, so a file might be incomplete
70
70
if a command throws SystemExit exception with a code =! 0.
71
71
@@ -104,6 +104,7 @@ def wrapper(self):
104
104
raise
105
105
finally :
106
106
self .log .buffer .cancelTimer ()
107
+
107
108
return wrapper
108
109
109
110
@@ -206,17 +207,15 @@ def execute(self):
206
207
207
208
208
209
class InstallDIRAC (CommandBase ):
209
- """ Source from CVMFS, or install locally
210
- """
210
+ """Source from CVMFS, or install locally"""
211
211
212
212
def __init__ (self , pilotParams ):
213
213
"""c'tor"""
214
214
super (InstallDIRAC , self ).__init__ (pilotParams )
215
215
self .pp .rootPath = self .pp .pilotRootPath
216
216
217
217
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"""
220
219
221
220
retCode , output = self .executeAndGetOutput ("bash -c 'source $DIRAC_RC_PATH && env'" , self .pp .installEnv )
222
221
if retCode :
@@ -249,12 +248,12 @@ def _saveEnvInFile(self, eFile="environmentSourceDirac"):
249
248
fd .write (bl )
250
249
251
250
def _getPreinstalledEnvScript (self ):
252
- """ Get preinstalled environment script if any """
251
+ """Get preinstalled environment script if any"""
253
252
254
253
self .log .debug ("self.pp.preinstalledEnv = %s" % self .pp .preinstalledEnv )
255
254
self .log .debug ("self.pp.preinstalledEnvPrefix = %s" % self .pp .preinstalledEnvPrefix )
256
255
self .log .debug ("self.pp.CVMFS_locations = %s" % self .pp .CVMFS_locations )
257
-
256
+
258
257
preinstalledEnvScript = self .pp .preinstalledEnv
259
258
if not preinstalledEnvScript and self .pp .preinstalledEnvPrefix :
260
259
version = self .pp .releaseVersion or "pro"
@@ -265,7 +264,9 @@ def _getPreinstalledEnvScript(self):
265
264
for CVMFS_location in self .pp .CVMFS_locations :
266
265
version = self .pp .releaseVersion or "pro"
267
266
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
+ )
269
270
if os .path .isfile (preinstalledEnvScript ):
270
271
break
271
272
@@ -280,11 +281,11 @@ def _getPreinstalledEnvScript(self):
280
281
self .pp .preinstalledEnv = preinstalledEnvScript
281
282
self .pp .installEnv ["DIRAC_RC_PATH" ] = preinstalledEnvScript
282
283
283
-
284
284
def _localInstallDIRAC (self ):
285
+ """Install python3 version of DIRAC client"""
286
+
285
287
self .log .info ("Installing DIRAC locally" )
286
288
287
- """Install python3 version of DIRAC client"""
288
289
# default to limit the resources used during installation to what the pilot owns
289
290
installEnv = {
290
291
# see https://github.com/DIRACGrid/Pilot/issues/189
@@ -353,7 +354,7 @@ def _localInstallDIRAC(self):
353
354
self .pp .installEnv ["DIRAC_RC_PATH" ] = os .path .join (os .getcwd (), "diracos/diracosrc" )
354
355
self ._sourceEnvironmentFile ()
355
356
self ._saveEnvInFile ()
356
-
357
+
357
358
# 7. pip install DIRAC[pilot]
358
359
pipInstalling = "pip install %s " % self .pp .pipInstallOptions
359
360
@@ -401,7 +402,7 @@ def execute(self):
401
402
self .log .info ("NOT sourcing: starting traditional DIRAC installation" )
402
403
self ._localInstallDIRAC ()
403
404
return
404
-
405
+
405
406
# Try sourcing from CVMFS
406
407
self ._getPreinstalledEnvScript ()
407
408
if not self .pp .preinstalledEnv :
@@ -413,10 +414,8 @@ def execute(self):
413
414
# environment variables to add?
414
415
if self .pp .userEnvVariables :
415
416
# 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 )
420
419
self .pp .installEnv .update (newEnvVars )
421
420
422
421
except OSError as e :
@@ -524,8 +523,7 @@ def _getBasicsCFG(self):
524
523
self .cfg .append ('-o "/Resources/Computing/CEDefaults/VirtualOrganization=%s"' % self .pp .wnVO )
525
524
526
525
def _getSecurityCFG (self ):
527
- """ Sets security-related env variables, if needed
528
- """
526
+ """Sets security-related env variables, if needed"""
529
527
# Need to know host cert and key location in case they are needed
530
528
if self .pp .useServerCertificate :
531
529
self .cfg .append ("--UseServerCertificate" )
@@ -765,9 +763,13 @@ def execute(self):
765
763
766
764
batchSystemParams = self .pp .batchSystemInfo .get ("Parameters" , {})
767
765
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
+ )
769
769
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
+ )
771
773
772
774
self .cfg .append ('-n "%s"' % self .pp .site )
773
775
self .cfg .append ('-S "%s"' % self .pp .setup )
@@ -849,7 +851,7 @@ def execute(self):
849
851
localArchitecture = localArchitecture .strip ().split ("\n " )[- 1 ].strip ()
850
852
cfg .append ('-S "%s"' % self .pp .setup )
851
853
cfg .append ("-o /LocalSite/Architecture=%s" % localArchitecture )
852
-
854
+
853
855
# add the local platform as determined by the platform module
854
856
cfg .append ("-o /LocalSite/Platform=%s" % platform .machine ())
855
857
@@ -1123,6 +1125,8 @@ def _runNagiosProbes(self):
1123
1125
self .log .error ("Return code = %d: %s" % (retCode , str (output ).split ("\n " , 1 )[0 ]))
1124
1126
retStatus = "error"
1125
1127
1128
+ # TODO: Do something with the retStatus (for example: log it?)
1129
+
1126
1130
# report results to pilot logger too. Like this:
1127
1131
# "NagiosProbes", probeCmd, retStatus, str(retCode) + ' ' + output.split('\n',1)[0]
1128
1132
0 commit comments