Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #47 from ubeda/UpdateConfig
Browse files Browse the repository at this point in the history
FIX: fixes in VirtualMachineConfigUpdater
  • Loading branch information
graciani committed Jun 21, 2013
2 parents 1fa3d10 + 406096a commit 995725c
Showing 1 changed file with 62 additions and 26 deletions.
88 changes: 62 additions & 26 deletions WorkloadManagementSystem/Agent/VirtualMachineConfigUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
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 VirtualMachineConfiguUpdater( AgentModule ):
class VirtualMachineConfigUpdater( AgentModule ):

def __init__( self, *args, **kwargs ):
""" Constructor
Expand All @@ -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 ):
Expand All @@ -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 Update: %s' % self.cfgToUpdate )

return S_OK()


return S_OK()
def execute( self ):
""" execute
Expand All @@ -61,24 +61,56 @@ 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()

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( gConfig.diracConfigFilePath )
releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )
localCFG.loadFromFile( self.cfgToUpdate )
releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )[ 'value' ]

if pilotVersion > releaseVersion:
self.log.info( 'PilotVersion : %s' % pilotVersion )
self.log.info( 'ReleaseVersion : %s' % releaseVersion )

if LooseVersion( pilotVersion ) > LooseVersion( releaseVersion ):

self.log.info( 'UPDATING %s > %s' % ( pilotVersion, releaseVersion ) )

localCFG.setOption( 'LocalSite/ReleaseVersion', pilotVersion )
localCFG.writeToFile( gConfig.diracConfigFilePath )
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
Expand All @@ -96,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()

Expand Down

0 comments on commit 995725c

Please sign in to comment.