From 274e95e937b89d45c169fbf6c51673a37eeac474 Mon Sep 17 00:00:00 2001 From: ubeda Date: Wed, 19 Jun 2013 14:35:34 +0200 Subject: [PATCH 1/3] FIX: bugfixes --- .../Agent/VirtualMachineConfigUpdater.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py index 81793822..4bf643c2 100644 --- a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py +++ b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py @@ -17,7 +17,7 @@ __RCSID__ = '$Id: $' -class VirtualMachineConfiguUpdater( AgentModule ): +class VirtualMachineConfigUpdater( AgentModule ): def __init__( self, *args, **kwargs ): """ Constructor @@ -61,21 +61,28 @@ def execute( self ): return S_OK() pilotVersion = self.opHelper.getValue( 'Pilot/Version', '' ) - localCFG = CFG() + if not pilotVersion: + self.log.error( 'There is no pilot version on the CS' ) + return S_OK() + + localCFG = CFG() #load local CFG - localCFG.loadFromFile( gConfig.diracConfigFilePath ) - releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' ) + localCFG.loadFromFile( '/opt/dirac/etc/dirac.cfg' ) + releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )[ 'value' ] + self.log.info( 'PilotVersion : %s' % pilotVersion ) + self.log.info( 'ReleaseVersion : %s' % releaseVersion ) + if pilotVersion > releaseVersion: self.log.info( 'UPDATING %s > %s' % ( pilotVersion, releaseVersion ) ) localCFG.setOption( 'LocalSite/ReleaseVersion', pilotVersion ) - localCFG.writeToFile( gConfig.diracConfigFilePath ) + localCFG.writeToFile( '/opt/dirac/etc/dirac.cfg' ) self.touchStopAgents() - + return S_OK() From 20d8469c8e7365873c14fcf25aea7377b7673e07 Mon Sep 17 00:00:00 2001 From: ubeda Date: Thu, 20 Jun 2013 09:49:09 +0200 Subject: [PATCH 2/3] FIX: wrong logic, using AgentModule methods instead of cooking them --- .../Agent/VirtualMachineConfigUpdater.py | 73 +++++++++++++------ 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py index 4bf643c2..b4f4e317 100644 --- a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py +++ b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py @@ -9,12 +9,15 @@ import glob import os -from DIRAC import gConfig, S_OK, rootPath +from distutils.version import LooseVersion + +from DIRAC import gConfig, S_ERROR, S_OK from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.CFG import CFG -__RCSID__ = '$Id: $' +__RCSID__ = '$Id: $' +AGENT_NAME = 'WorkloadManagement/VirtualMachineConfigUpdater' class VirtualMachineConfigUpdater( AgentModule ): @@ -27,8 +30,8 @@ def __init__( self, *args, **kwargs ): AgentModule.__init__( self, *args, **kwargs ) self.opHelper = None - self.controlPath = '' self.stopAgentPath = '' + self.cfgToUpdate = '' def initialize( self ): @@ -38,18 +41,15 @@ def initialize( self ): self.opHelper = Operations() - # Set control path - instancePath = gConfig.getValue( '/LocalSite/InstancePath', rootPath ) - self.controlPath = os.path.join( instancePath, 'control', '*', '*' ) - self.stopAgentPath = os.path.join( self.controlPath, 'stop_agent' ) - - self.log.info( 'Instance path: %s' % instancePath ) - self.log.info( 'Control path: %s' % self.controlPath ) + self.stopAgentPath = self.am_getStopAgentFile().replace( AGENT_NAME, '*/*' ) + self.cfgToUpdate = self.am_getOption( 'cfgToUpdate', gConfig.diracConfigFilePath ) + self.log.info( 'Stop Agent path: %s' % self.stopAgentPath ) + self.log.info( 'Config To Updte: %s' % self.cfgToUpdate ) - return S_OK() - - + return S_OK() + + def execute( self ): """ execute @@ -64,28 +64,53 @@ def execute( self ): if not pilotVersion: self.log.error( 'There is no pilot version on the CS' ) return S_OK() + + pilotVersion = self.getNewestPilotVersion() + if not pilotVersion[ 'OK' ]: + self.log.error( pilotVersion[ 'Message' ] ) + return S_ERROR( pilotVersion[ 'Message' ] ) + pilotVersion = pilotVersion[ 'Value' ] localCFG = CFG() #load local CFG - localCFG.loadFromFile( '/opt/dirac/etc/dirac.cfg' ) + localCFG.loadFromFile( self.cfgToUpdate ) releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )[ 'value' ] self.log.info( 'PilotVersion : %s' % pilotVersion ) self.log.info( 'ReleaseVersion : %s' % releaseVersion ) - if pilotVersion > releaseVersion: + if LooseVersion( pilotVersion ) > LooseVersion( releaseVersion ): self.log.info( 'UPDATING %s > %s' % ( pilotVersion, releaseVersion ) ) localCFG.setOption( 'LocalSite/ReleaseVersion', pilotVersion ) - localCFG.writeToFile( '/opt/dirac/etc/dirac.cfg' ) + localCFG.writeToFile( self.cfgToUpdate ) self.touchStopAgents() + else: + + self.log.info( 'Nothing to do' ) + return S_OK() + + def getNewestPilotVersion( self ): + """ getNewestPilotVersion + + """ + + pilotVersion = self.opHelper.getValue( 'Pilot/Version', [] ) + if not pilotVersion: + return S_ERROR( 'Empty pilot version' ) + + pilotVersion = [ LooseVersion( pV ) for pV in pilotVersion ] + pilotVersion.sort() + + return S_OK( pilotVersion.pop().vstring ) + def findStopAgents( self ): """ findStopAgents @@ -103,14 +128,18 @@ def touchStopAgents( self ): """ - controlAgents = glob.glob( self.controlPath ) - for controlAgent in controlAgents: + stopAgentDirs = glob.glob( self.stopAgentPath.replace( 'stop_agent' , '' ) ) + for stopAgentDir in stopAgentDirs: + + # Do not restart itself + if AGENT_NAME in stopAgentDir: + continue - stopAgent = os.path.join( controlAgent, 'stop_agent' ) + stopAgentFile = os.path.join( stopAgentDir, 'stop_agent' ) - with file( stopAgent, 'a' ): - os.utime( stopAgent, None ) - self.log.info( 'Written stop_agent in: %s' % stopAgent ) + with file( stopAgentFile, 'a' ): + os.utime( stopAgentFile, None ) + self.log.info( 'Written stop_agent in: %s' % stopAgentFile ) return S_OK() From 406096a6a5535df225536a6300c43200e87c9dc2 Mon Sep 17 00:00:00 2001 From: ubeda Date: Thu, 20 Jun 2013 09:50:18 +0200 Subject: [PATCH 3/3] Little typo in comment --- WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py index b4f4e317..9df2413a 100644 --- a/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py +++ b/WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py @@ -45,7 +45,7 @@ def initialize( self ): self.cfgToUpdate = self.am_getOption( 'cfgToUpdate', gConfig.diracConfigFilePath ) self.log.info( 'Stop Agent path: %s' % self.stopAgentPath ) - self.log.info( 'Config To Updte: %s' % self.cfgToUpdate ) + self.log.info( 'Config To Update: %s' % self.cfgToUpdate ) return S_OK()