From a1fcc427ff3e9c2c59ef874d73fc0efc2557fdf4 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 10:58:15 +0100 Subject: [PATCH 01/33] Added macro on top --- ResourceStatusSystem/Utilities/CS.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ResourceStatusSystem/Utilities/CS.py b/ResourceStatusSystem/Utilities/CS.py index b5c02e18f6e..779ead0aff4 100644 --- a/ResourceStatusSystem/Utilities/CS.py +++ b/ResourceStatusSystem/Utilities/CS.py @@ -1,23 +1,26 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' CS + + This module offers "helpers" to access the CS, and do some processing. + +''' import itertools -from DIRAC import S_OK, S_ERROR, gConfig -from DIRAC.Core.Utilities import List +from DIRAC import S_OK, S_ERROR, gConfig +from DIRAC.Core.Utilities import List +from DIRAC.ResourceStatusSystem.Utilities import Utils -from DIRAC.ResourceStatusSystem.Utilities import Utils +__RCSID__ = '$Id: $' -g_BaseRegistrySection = "/Registry" -g_BaseResourcesSection = "/Resources" -g_BaseOperationsSection = "/Operations" -g_BaseConfigSection = "/Operations/RSSConfiguration" +g_BaseRegistrySection = '/Registry' +g_BaseResourcesSection = '/Resources' +g_BaseOperationsSection = '/Operations' +g_BaseConfigSection = '/Operations/RSSConfiguration' ### CS HELPER FUNCTIONS -class CSError(Exception): +class CSError( Exception ): pass def getValue(v, default): From 1c53d2379b396d8ff5db35a4a54c48288a696f99 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 11:28:45 +0100 Subject: [PATCH 02/33] pyLint changes --- ResourceStatusSystem/Utilities/CS.py | 106 ++++++++++++--------- ResourceStatusSystem/Utilities/__init__.py | 9 +- 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/ResourceStatusSystem/Utilities/CS.py b/ResourceStatusSystem/Utilities/CS.py index 779ead0aff4..593e8a6710a 100644 --- a/ResourceStatusSystem/Utilities/CS.py +++ b/ResourceStatusSystem/Utilities/CS.py @@ -21,93 +21,102 @@ ### CS HELPER FUNCTIONS class CSError( Exception ): + ''' To be removed ''' pass -def getValue(v, default): - """Wrapper around gConfig.getValue. Returns typed values""" - res = gConfig.getValue(v, default) - if Utils.isiterable(res): - return [Utils.typedobj_of_string(e) for e in res] +def getValue( val, default ): + '''Wrapper around gConfig.getValue. Returns typed values''' + res = gConfig.getValue( val, default ) + if Utils.isiterable( res ): + return [ Utils.typedobj_of_string(e) for e in res ] else: - return Utils.typedobj_of_string(res) + return Utils.typedobj_of_string( res ) -def getTypedDictRootedAt(relpath = "", root = g_BaseConfigSection): - """Gives the configuration rooted at path in a Python dict. The +def getTypedDictRootedAt( relpath = "", root = g_BaseConfigSection ): + '''Gives the configuration rooted at path in a Python dict. The result is a Python dictionnary that reflects the structure of the - config file.""" - def getTypedDictRootedAt(path): + config file.''' + def getTypedDictRootedAt( path ): retval = {} - opts = gConfig.getOptionsDict(path) - secs = gConfig.getSections(path) + opts = gConfig.getOptionsDict( path ) + secs = gConfig.getSections( path ) - if not opts['OK']: - raise CSError, opts['Message'] - if not secs['OK']: - raise CSError, secs['Message'] + if not opts[ 'OK' ]: + raise CSError, opts[ 'Message' ] + if not secs[ 'OK' ]: + raise CSError, secs[ 'Message' ] - opts = opts['Value'] - secs = secs['Value'] + opts = opts[ 'Value' ] + secs = secs[ 'Value' ] for k in opts: - if opts[k].find(",") > -1: - retval[k] = [Utils.typedobj_of_string(e) for e in List.fromChar(opts[k])] + if opts[ k ].find( "," ) > -1: + retval[ k ] = [ Utils.typedobj_of_string(e) for e in List.fromChar(opts[k]) ] else: - retval[k] = Utils.typedobj_of_string(opts[k]) + retval[ k ] = Utils.typedobj_of_string( opts[ k ] ) for i in secs: - retval[i] = getTypedDictRootedAt(path + "/" + i) + retval[ i ] = getTypedDictRootedAt( path + "/" + i ) return retval - return getTypedDictRootedAt(root + "/" + relpath) + return getTypedDictRootedAt( root + "/" + relpath ) ################################################################################ # Mail functions ####################### def getOperationMails( op ): - return gConfig.getValue("%s/EMail/%s" %(g_BaseOperationsSection, op) ,"") + ''' Get emails from Operations section''' + return gConfig.getValue( "%s/EMail/%s" % (g_BaseOperationsSection, op) ,"" ) # Setup functions #################### def getSetup(): - return gConfig.getValue("DIRAC/Setup", "") + ''' Get setup in which we are running''' + return gConfig.getValue( "DIRAC/Setup", "" ) # VOMS functions #################### def getVOMSEndpoints(): - return Utils.unpack(gConfig.getSections("%s/VOMS/Servers/lhcb/" % g_BaseRegistrySection)) + ''' Get VOMS endpoints ''' + return Utils.unpack( gConfig.getSections( "%s/VOMS/Servers/lhcb/" % g_BaseRegistrySection ) ) # Sites functions ################### -def getSites( grids = ('LCG', 'DIRAC') ): - if isinstance(grids, basestring): - grids = (grids,) +def getSites( grids = ( 'LCG', 'DIRAC' ) ): + ''' Get sites from CS ''' + if isinstance( grids, basestring ): + grids = ( grids, ) sites = [Utils.unpack(gConfig.getSections('%s/Sites/%s' % ( g_BaseResourcesSection, grid ), True)) for grid in grids] return Utils.list_flatten(sites) -def getSiteTiers(sites): - return [getValue("%s/Sites/%s/%s/MoUTierLevel" - % (g_BaseResourcesSection, site.split(".")[0], site), 2) for site in sites] +def getSiteTiers( sites ): + ''' Get tiers from CS ''' + return [ getValue("%s/Sites/%s/%s/MoUTierLevel" + % (g_BaseResourcesSection, site.split(".")[0], site), 2) for site in sites ] -def getSiteTier(site): - return getSiteTiers([site])[0] +def getSiteTier( site ): + ''' Get tier from site ''' + return getSiteTiers( [ site ] )[ 0 ] -def getT1s(grids = 'LCG'): - sites = getSites(grids) - tiers = getSiteTiers(sites) - pairs = itertools.izip(sites, tiers) - return [s for (s, t) in pairs if t == 1] +def getT1s( grids = 'LCG' ): + ''' Get Tier 1s ''' + sites = getSites( grids ) + tiers = getSiteTiers( sites ) + pairs = itertools.izip( sites, tiers ) + return [ s for (s, t) in pairs if t == 1 ] # LFC functions ##################### def getLFCSites(): + ''' Get LFC sites ''' return Utils.unpack(gConfig.getSections('%s/FileCatalogs/LcgFileCatalogCombined' % g_BaseResourcesSection, True)) -def getLFCNode( sites = None, - readable = ('ReadOnly', 'ReadWrite')): +def getLFCNode( sites = None, readable = ( 'ReadOnly', 'ReadWrite' ) ): + ''' Get LFC node ''' if sites is None: sites = getLFCSites() @@ -126,34 +135,42 @@ def getLFCURL(site, mode): # Storage Elements functions ######## def getSEs(): + ''' Get StorageElements ''' return Utils.unpack(gConfig.getSections("/Resources/StorageElements")) -def getSEHost(SE): +def getSEHost( SE ): + ''' Get StorageElement host ''' return gConfig.getValue('%s/StorageElements/%s/AccessProtocol.1/Host' % (g_BaseResourcesSection, SE), "") def getSENodes(): + ''' Get StorageElement nodes ''' nodes = [getSEHost(SE) for SE in getSEs()] return [n for n in nodes if n != ""] -def getSEStatus(SE, accessType): +def getSEStatus( SE, accessType ): + ''' Get StorageElement status ''' return gConfig.getValue("%s/StorageElements/%s/%s" % (g_BaseResourcesSection, SE, accessType), "") def getSEToken(SE): + ''' Get StorageElement token ''' return gConfig.getValue("/Resources/StorageElements/%s/AccessProtocol.1/SpaceToken" % SE, "") # Space Tokens functions ############ def getSpaceTokens(): + ''' Get Space Tokens ''' return ["LHCb_USER", "LHCb-Disk", "LHCb-Tape"] def getSpaceTokenEndpoints(): + ''' Get Space Token Endpoints ''' return getTypedDictRootedAt(root="", relpath="/Resources/Shares/Disk") # CE functions ###################### def getCEType( site, ce, grid = 'LCG' ): + ''' Get CE types ''' res = gConfig.getValue('%s/Sites/%s/%s/CEs/%s/CEType' % (g_BaseResourcesSection, grid, site, ce), "CE") return "CREAMCE" if res == "CREAM" else "CE" @@ -161,7 +178,8 @@ def getCEType( site, ce, grid = 'LCG' ): # CondDB functions ################## def getCondDBs(): + ''' Get CondDB''' return Utils.unpack(gConfig.getSections("%s/CondDB" % g_BaseResourcesSection)) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/__init__.py b/ResourceStatusSystem/Utilities/__init__.py index ec8fc0efce6..1866d9edbb3 100644 --- a/ResourceStatusSystem/Utilities/__init__.py +++ b/ResourceStatusSystem/Utilities/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Utilities package +''' -""" - DIRAC.ResourceStatusSystem.Utilities package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From b21dc4d03a21ca5eca81d1b8835d9a4dcf44a9ad Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 11:54:39 +0100 Subject: [PATCH 03/33] pyLint changes --- ResourceStatusSystem/Utilities/Decorators.py | 10 +++++--- ResourceStatusSystem/Utilities/Exceptions.py | 13 +++++----- ResourceStatusSystem/Utilities/InfoGetter.py | 12 ++++++--- ResourceStatusSystem/Utilities/MySQLMonkey.py | 16 +++++++----- ResourceStatusSystem/Utilities/NodeTree.py | 14 +++++++---- ResourceStatusSystem/Utilities/Publisher.py | 25 ++++++++++--------- .../Utilities/Synchronizer.py | 20 +++++++-------- ResourceStatusSystem/Utilities/Utils.py | 17 ++++++++++--- 8 files changed, 76 insertions(+), 51 deletions(-) diff --git a/ResourceStatusSystem/Utilities/Decorators.py b/ResourceStatusSystem/Utilities/Decorators.py index 941cb17bdf9..062cd2ecc97 100644 --- a/ResourceStatusSystem/Utilities/Decorators.py +++ b/ResourceStatusSystem/Utilities/Decorators.py @@ -1,12 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Decorators + + Syntactic sugar used in the RSS, only in the DB. Eventually will dissapear. + +''' import types from DIRAC import S_ERROR +__RCSID__ = '$Id: $' + class BaseDec( object ): def __init__( self, f ): diff --git a/ResourceStatusSystem/Utilities/Exceptions.py b/ResourceStatusSystem/Utilities/Exceptions.py index 963d3640873..1c1d13f1794 100644 --- a/ResourceStatusSystem/Utilities/Exceptions.py +++ b/ResourceStatusSystem/Utilities/Exceptions.py @@ -1,16 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Exceptions -""" - collects: - - exceptions -""" + RSS Exceptions. Will be obsolete soon. + +''' from DIRAC.ResourceStatusSystem import ValidRes, ValidStatus, ValidSiteType, \ ValidServiceType, ValidResourceType +__RCSID__ = '$Id: $' + class RSSDBException( Exception ): """ DB exception diff --git a/ResourceStatusSystem/Utilities/InfoGetter.py b/ResourceStatusSystem/Utilities/InfoGetter.py index 6809c5f3cca..b10b4157749 100644 --- a/ResourceStatusSystem/Utilities/InfoGetter.py +++ b/ResourceStatusSystem/Utilities/InfoGetter.py @@ -1,7 +1,9 @@ -################################################################################ -# $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +# $HeadURL: $ +''' InfoGetter + + Module used to map the policies with the CS. + +''' import copy @@ -9,6 +11,8 @@ from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem import views_panels +__RCSID__ = '$Id: $' + class InfoGetter: """ Class InfoGetter is in charge of getting information from the RSS Configurations """ diff --git a/ResourceStatusSystem/Utilities/MySQLMonkey.py b/ResourceStatusSystem/Utilities/MySQLMonkey.py index 642cda2800e..0693e919450 100644 --- a/ResourceStatusSystem/Utilities/MySQLMonkey.py +++ b/ResourceStatusSystem/Utilities/MySQLMonkey.py @@ -1,15 +1,19 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' MySQLMonkey -from DIRAC import S_OK#, S_ERROR -from DIRAC.ResourceStatusSystem.Utilities.Exceptions import RSSDBException + Module that generates SQL statemens in the fly out of two dictionaries. -from datetime import datetime +''' import re +from datetime import datetime + +from DIRAC import S_OK +from DIRAC.ResourceStatusSystem.Utilities.Exceptions import RSSDBException + +__RCSID__ = '$Id: $' + ################################################################################ # MySQL Monkey ################################################################################ diff --git a/ResourceStatusSystem/Utilities/NodeTree.py b/ResourceStatusSystem/Utilities/NodeTree.py index c965603b597..89569b7d6d2 100644 --- a/ResourceStatusSystem/Utilities/NodeTree.py +++ b/ResourceStatusSystem/Utilities/NodeTree.py @@ -1,3 +1,10 @@ +# $HeadURL $ +''' Node + + Module used to inspect the DB. Will be obsolete soon. + +''' + class Node( object ): def __init__( self, name, level, cLevel, pLevel ): @@ -55,8 +62,5 @@ def setChildren( self, child, level = None ): # msg += ','.join( [ '<%s>' % k for k in self._levels[ self.childrenLevel ].keys() ] ) # return msg - - - - - \ No newline at end of file +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Utilities/Publisher.py b/ResourceStatusSystem/Utilities/Publisher.py index 7ed8061fd31..5c548e00357 100644 --- a/ResourceStatusSystem/Utilities/Publisher.py +++ b/ResourceStatusSystem/Utilities/Publisher.py @@ -1,26 +1,27 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +''' Publisher + + Module not used. Will be back to life whenever the portal is ready. + +''' import copy import threading -from DIRAC import gLogger - +from DIRAC import gLogger +from DIRAC.Core.DISET.RPCClient import RPCClient from DIRAC.Core.Utilities.ThreadPool import ThreadPool from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName -from DIRAC.ResourceStatusSystem.Utilities.CS import getStorageElementStatus - from DIRAC.ResourceStatusSystem import ValidRes -from DIRAC.ResourceStatusSystem.Utilities import Utils - -from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB -from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB +from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB +from DIRAC.ResourceStatusSystem.Utilities import Utils +from DIRAC.ResourceStatusSystem.Utilities.CS import getStorageElementStatus from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter -from DIRAC.Core.DISET.RPCClient import RPCClient + +__RCSID__ = '$Id: $' class Publisher: """ diff --git a/ResourceStatusSystem/Utilities/Synchronizer.py b/ResourceStatusSystem/Utilities/Synchronizer.py index 1d56d83222e..62ff347828e 100644 --- a/ResourceStatusSystem/Utilities/Synchronizer.py +++ b/ResourceStatusSystem/Utilities/Synchronizer.py @@ -1,21 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - This module contains a class to synchronize the content of the DataBase with what is the CS -""" +''' Synchronizer + + Module that keeps in sync the CS and the RSS database. + +''' from DIRAC import gLogger, S_OK +from DIRAC.Core.LCG.GOCDBClient import GOCDBClient from DIRAC.Core.Utilities.SiteCEMapping import getSiteCEMapping from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName, getDIRACSiteName - -from DIRAC.ResourceStatusSystem.Utilities import CS, Utils -from DIRAC.Core.LCG.GOCDBClient import GOCDBClient - from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +from DIRAC.ResourceStatusSystem.Utilities import CS, Utils + +__RCSID__ = '$Id: $' -class Synchronizer(object): +class Synchronizer( object ): def __init__( self, rsClient = None, rmClient = None ): diff --git a/ResourceStatusSystem/Utilities/Utils.py b/ResourceStatusSystem/Utilities/Utils.py index 9b59cb6ef71..d94fa6ff5b9 100644 --- a/ResourceStatusSystem/Utilities/Utils.py +++ b/ResourceStatusSystem/Utilities/Utils.py @@ -1,10 +1,16 @@ -""" - This module collects utility functions -""" +# $HeadURL $ +''' Utils + + Module that collects utility functions. + +''' -from DIRAC import gConfig import collections +from DIRAC import gConfig + +__RCSID__ = '$Id: $' + ############################################################################# # useful functions ############################################################################# @@ -227,3 +233,6 @@ def xml_append(doc, tag, value_=None, elt_=None, **kw): return elt_.appendChild(new_elt) else: return doc.documentElement.appendChild(new_elt) + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From 1ccbf4a529c1938812b86d9e0b0f67aa54f5d8b7 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 12:20:31 +0100 Subject: [PATCH 04/33] macro heads on top --- .../Agent/CacheCleanerAgent.py | 24 +++++++++++-------- .../Agent/CacheFeederAgent.py | 13 ++++++---- .../Agent/RSInspectorAgent.py | 12 ++++++---- .../Agent/SSInspectorAgent.py | 13 ++++++---- .../Agent/SeSInspectorAgent.py | 13 ++++++---- .../Agent/StElInspectorAgent.py | 13 ++++++---- ResourceStatusSystem/Agent/TokenAgent.py | 13 ++++++---- ResourceStatusSystem/Agent/__init__.py | 10 ++++---- 8 files changed, 66 insertions(+), 45 deletions(-) diff --git a/ResourceStatusSystem/Agent/CacheCleanerAgent.py b/ResourceStatusSystem/Agent/CacheCleanerAgent.py index c5756066826..7744dd505e8 100644 --- a/ResourceStatusSystem/Agent/CacheCleanerAgent.py +++ b/ResourceStatusSystem/Agent/CacheCleanerAgent.py @@ -1,18 +1,22 @@ -################################################################################ # $HeadURL$ -################################################################################ -__RCSID__ = "$Id$" -AGENT_NAME = 'ResourceStatus/CleanerAgent' +''' CacheCleanerAgent -from datetime import datetime,timedelta + This agent cleans the history tables, and the cache ones if entries older + than a certan period. -from DIRAC import S_OK, S_ERROR -from DIRAC.Core.Base.AgentModule import AgentModule +''' -from DIRAC.ResourceStatusSystem import ValidRes +from datetime import datetime,timedelta + +from DIRAC import S_OK, S_ERROR +from DIRAC.Core.Base.AgentModule import AgentModule +from DIRAC.ResourceStatusSystem import ValidRes from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/CleanerAgent' + class CacheCleanerAgent( AgentModule ): ''' The CacheCleanerAgent tidies up the ResourceStatusDB, namely: @@ -35,8 +39,8 @@ def initialize( self ): try: - self.rsClient = ResourceStatusClient() - self.rmClient = ResourceManagementClient() + self.rsClient = ResourceStatusClient() + self.rmClient = ResourceManagementClient() self.historyTables = [ '%sHistory' % x for x in ValidRes ] return S_OK() diff --git a/ResourceStatusSystem/Agent/CacheFeederAgent.py b/ResourceStatusSystem/Agent/CacheFeederAgent.py index c44204add4a..706507cba51 100644 --- a/ResourceStatusSystem/Agent/CacheFeederAgent.py +++ b/ResourceStatusSystem/Agent/CacheFeederAgent.py @@ -1,19 +1,22 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/CacheFeederAgent' +''' CacheFeederAgent + + This agent feeds the Cache tables with the outputs of the cache commands. + +''' from datetime import datetime from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule - from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/CacheFeederAgent' + class CacheFeederAgent( AgentModule ): ''' The CacheFeederAgent feeds the cache tables for the client and the accounting. diff --git a/ResourceStatusSystem/Agent/RSInspectorAgent.py b/ResourceStatusSystem/Agent/RSInspectorAgent.py index 52e6c35a71b..6258f24a150 100644 --- a/ResourceStatusSystem/Agent/RSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/RSInspectorAgent.py @@ -1,8 +1,9 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/RSInspectorAgent' +''' RSInspectorAgent + + This agent inspect Resources, and evaluates policies that apply. + +''' import Queue, time @@ -16,6 +17,9 @@ from DIRAC.ResourceStatusSystem.Utilities.Utils import where from DIRAC.ResourceStatusSystem.Utilities import CS +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/RSInspectorAgent' + class RSInspectorAgent( AgentModule ): """ The RSInspector agent ( ResourceInspectorAgent ) is one of the four diff --git a/ResourceStatusSystem/Agent/SSInspectorAgent.py b/ResourceStatusSystem/Agent/SSInspectorAgent.py index d5094c91ba5..e97c1083512 100644 --- a/ResourceStatusSystem/Agent/SSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SSInspectorAgent.py @@ -1,21 +1,24 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/SSInspectorAgent' +''' SSInspectorAgent + + This agent inspect Sites, and evaluates policies that apply. + +''' import Queue, time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/SSInspectorAgent' + class SSInspectorAgent( AgentModule ): """ The SSInspector agent ( SiteInspectorAgent ) is one of the four diff --git a/ResourceStatusSystem/Agent/SeSInspectorAgent.py b/ResourceStatusSystem/Agent/SeSInspectorAgent.py index 2b5146359d6..8383d8f9b35 100644 --- a/ResourceStatusSystem/Agent/SeSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SeSInspectorAgent.py @@ -1,21 +1,24 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/SeSInspectorAgent' +''' SeSInspectorAgent + + This agent inspect Services, and evaluates policies that apply. + +''' import Queue, time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/SeSInspectorAgent' + class SeSInspectorAgent( AgentModule ): """ The SeSInspector agent ( ServiceInspectorAgent ) is one of the four diff --git a/ResourceStatusSystem/Agent/StElInspectorAgent.py b/ResourceStatusSystem/Agent/StElInspectorAgent.py index fd9138d291f..9d1c7dbc390 100644 --- a/ResourceStatusSystem/Agent/StElInspectorAgent.py +++ b/ResourceStatusSystem/Agent/StElInspectorAgent.py @@ -1,21 +1,24 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/StElInspectorAgent' +''' StElInspectorAgent + + This agent inspect Sites, and evaluates policies that apply. + +''' import Queue, time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities.ThreadPool import ThreadPool - from DIRAC.ResourceStatusSystem.Utilities import CS from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Command import knownAPIs from DIRAC.ResourceStatusSystem.PolicySystem.PEP import PEP from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/StElInspectorAgent' + class StElInspectorAgent( AgentModule ): """ The StElInspector agent ( StorageElementInspectorAgent ) is one of the four diff --git a/ResourceStatusSystem/Agent/TokenAgent.py b/ResourceStatusSystem/Agent/TokenAgent.py index 8f7b553b353..43a63c08b79 100644 --- a/ResourceStatusSystem/Agent/TokenAgent.py +++ b/ResourceStatusSystem/Agent/TokenAgent.py @@ -1,20 +1,23 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" -AGENT_NAME = 'ResourceStatus/TokenAgent' +''' TokenAgent + + This agent inspect all elements, and resets their tokens if necessary. + +''' import datetime from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.FrameworkSystem.Client.NotificationClient import NotificationClient - from DIRAC.ResourceStatusSystem import ValidRes from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP +__RCSID__ = '$Id: $' +AGENT_NAME = 'ResourceStatus/TokenAgent' + class TokenAgent( AgentModule ): """ TokenAgent is in charge of checking tokens assigned on resources. diff --git a/ResourceStatusSystem/Agent/__init__.py b/ResourceStatusSystem/Agent/__init__.py index 7b97895241e..07891df4909 100644 --- a/ResourceStatusSystem/Agent/__init__.py +++ b/ResourceStatusSystem/Agent/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" - -""" +''' DIRAC.ResourceStatusSystem.Agent package -""" +''' + +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From a0654a07f9e81833785bdc1900b0a8ec0a1bd581 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 12:27:16 +0100 Subject: [PATCH 05/33] pyLint modifications --- ResourceStatusSystem/Agent/__init__.py | 4 ++-- ResourceStatusSystem/Client/JobsClient.py | 10 +++++++--- ResourceStatusSystem/Client/PilotsClient.py | 10 +++++++--- .../Client/ResourceManagementClient.py | 12 ++++++++---- ResourceStatusSystem/Client/ResourceStatus.py | 13 +++++++++---- .../Client/ResourceStatusClient.py | 18 +++++++++++------- ResourceStatusSystem/Client/__init__.py | 10 ++++------ 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/ResourceStatusSystem/Agent/__init__.py b/ResourceStatusSystem/Agent/__init__.py index 07891df4909..e8dab8b5837 100644 --- a/ResourceStatusSystem/Agent/__init__.py +++ b/ResourceStatusSystem/Agent/__init__.py @@ -1,6 +1,6 @@ # $HeadURL $ -''' - DIRAC.ResourceStatusSystem.Agent package +''' DIRAC.ResourceStatusSystem.Agent package + ''' __RCSID__ = '$Id: $' diff --git a/ResourceStatusSystem/Client/JobsClient.py b/ResourceStatusSystem/Client/JobsClient.py index 7ba465b075a..5d5b7782595 100644 --- a/ResourceStatusSystem/Client/JobsClient.py +++ b/ResourceStatusSystem/Client/JobsClient.py @@ -1,7 +1,11 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' JobsClient + + Module to get jobs stats. + +''' + +__RCSID__ = '$Id: $' class JobsClient( object ): """ diff --git a/ResourceStatusSystem/Client/PilotsClient.py b/ResourceStatusSystem/Client/PilotsClient.py index 646ace652cb..3026a718074 100644 --- a/ResourceStatusSystem/Client/PilotsClient.py +++ b/ResourceStatusSystem/Client/PilotsClient.py @@ -1,7 +1,11 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' PilotsClient + + Module to get pilots stats. + +''' + +__RCSID__ = '$Id: $' class PilotsClient( object ): """ diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 868436a26fa..bdc07345280 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -1,13 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementClient + + Client to interact with the ResourceManagementDB. + +''' + +from datetime import datetime from DIRAC import gLogger from DIRAC.Core.DISET.RPCClient import RPCClient from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB -from datetime import datetime +__RCSID__ = '$Id: $' class ResourceManagementClient: """ diff --git a/ResourceStatusSystem/Client/ResourceStatus.py b/ResourceStatusSystem/Client/ResourceStatus.py index 9d3db1a1ef4..78be9a965f8 100644 --- a/ResourceStatusSystem/Client/ResourceStatus.py +++ b/ResourceStatusSystem/Client/ResourceStatus.py @@ -1,7 +1,9 @@ -################################################################################ # $HeadURL: $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatus + + Module use to switch between the CS and the RSS. + +''' import datetime @@ -9,6 +11,8 @@ from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient +__RCSID__ = '$Id: $' + def getStorageElementStatus( elementName, statusType = None, default = None ): ''' Helper with dual access, tries to get information from the RSS for the given @@ -226,4 +230,5 @@ def __getDictFromList( l ): res[ site ][ sType ] = status return res -################################################################################ \ No newline at end of file +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 5147daac180..be6f7006309 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -1,7 +1,13 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusClient + + Client to interact with the ResourceStatusDB. + +''' + +import sys + +from datetime import datetime, timedelta from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RPCClient import RPCClient @@ -10,10 +16,8 @@ ValidStatusTypes, ValidSiteType, ValidServiceType, ValidResourceType from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB from DIRAC.ResourceStatusSystem.Utilities.NodeTree import Node - -from datetime import datetime, timedelta - -import sys + +__RCSID__ = '$Id: $' class ResourceStatusClient: """ diff --git a/ResourceStatusSystem/Client/__init__.py b/ResourceStatusSystem/Client/__init__.py index 8bd3e7c4ca8..4a1c119cfc8 100644 --- a/ResourceStatusSystem/Client/__init__.py +++ b/ResourceStatusSystem/Client/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Client package + +''' -""" - DIRAC.ResourceStatusSystem.Client package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF From 8f146c5da733622a00bdd7ea02ab5cdfa4335552 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 12:54:04 +0100 Subject: [PATCH 06/33] pyLint changes ( cosmetic ) --- .../Command/AccountingCache_Command.py | 13 ++++---- .../Command/ClientsCache_Command.py | 15 +++++----- .../Command/ClientsInvoker.py | 30 ++++++++++++------- ResourceStatusSystem/Command/Command.py | 24 ++++++--------- ResourceStatusSystem/Command/CommandCaller.py | 22 +++++--------- .../Command/DIRACAccounting_Command.py | 13 ++++---- .../Command/DoNothing_Command.py | 22 ++++++++------ .../Command/GGUSTickets_Command.py | 17 +++++------ .../Command/GOCDBStatus_Command.py | 12 ++++---- ResourceStatusSystem/Command/Jobs_Command.py | 13 ++++---- ResourceStatusSystem/Command/MacroCommand.py | 24 +++++++-------- .../Command/Macros_Command.py | 27 ++++++++--------- .../Command/Pilots_Command.py | 15 +++++----- ResourceStatusSystem/Command/RS_Command.py | 11 +++---- ResourceStatusSystem/Command/__init__.py | 9 ++---- ResourceStatusSystem/Command/knownAPIs.py | 9 ++++-- 16 files changed, 131 insertions(+), 145 deletions(-) diff --git a/ResourceStatusSystem/Command/AccountingCache_Command.py b/ResourceStatusSystem/Command/AccountingCache_Command.py index 4eac5891c9c..dd4badaf04d 100644 --- a/ResourceStatusSystem/Command/AccountingCache_Command.py +++ b/ResourceStatusSystem/Command/AccountingCache_Command.py @@ -1,21 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' AccountingCacheCommand + The AccountingCache_Command class is a command module that collects command classes to store accounting results in the accounting cache. -""" + +''' from datetime import datetime, timedelta from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/ClientsCache_Command.py b/ResourceStatusSystem/Command/ClientsCache_Command.py index 9c88331dfa4..25b801c2f20 100644 --- a/ResourceStatusSystem/Command/ClientsCache_Command.py +++ b/ResourceStatusSystem/Command/ClientsCache_Command.py @@ -1,22 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ClientsCache_Command -""" - The ClientsCache_Command class is a command module to know about collective clients results - (to be cached) -""" + The ClientsCache_Command class is a command module to know about collective + clients results (to be cached). + +''' import datetime from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName, getDIRACSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/ClientsInvoker.py b/ResourceStatusSystem/Command/ClientsInvoker.py index 8c37269497e..146b18b82c6 100644 --- a/ResourceStatusSystem/Command/ClientsInvoker.py +++ b/ResourceStatusSystem/Command/ClientsInvoker.py @@ -1,21 +1,29 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' ClientsInvoker + + Commands invoker. + +''' +__RCSID__ = '$Id: $' class ClientsInvoker: - """ + ''' Clients Invoker is the invoker for commands to be executed on clients - """ + ''' + + def __init__( self ): + ''' Constructor + ''' + self.command = None - def setCommand(self, c): - """ Set command to c - """ - self.command = c + def setCommand( self, command ): + ''' Set command to command + ''' + self.command = command def doCommand(self): - """ Call command.doCommand - """ + ''' Call command.doCommand + ''' return self.command.doCommand() ################################################################################ diff --git a/ResourceStatusSystem/Command/Command.py b/ResourceStatusSystem/Command/Command.py index bc4c7b42f64..18ecef265d1 100644 --- a/ResourceStatusSystem/Command/Command.py +++ b/ResourceStatusSystem/Command/Command.py @@ -1,10 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' Command + + Base class for all commands. + +''' from DIRAC import gLogger +__RCSID__ = '$Id: $' + class Command( object ): """ The Command class is a simple base class for all the commands @@ -12,8 +16,8 @@ class Command( object ): """ def __init__( self ): - self.args = None - self.APIs = {} + self.args = None + self.APIs = {} ################################################################################ @@ -48,15 +52,5 @@ def doCommand( self ): if self.args is None: gLogger.error( "Before, set `self.args` with `self.setArgs(a)` function." ) -################################################################################ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -################################################################################ - -''' - HOW DOES THIS WORK. - - will come soon... -''' - ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/CommandCaller.py b/ResourceStatusSystem/Command/CommandCaller.py index d81d114a5df..13d5241c449 100644 --- a/ResourceStatusSystem/Command/CommandCaller.py +++ b/ResourceStatusSystem/Command/CommandCaller.py @@ -1,12 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' CommandCaller + + Module that loads commands and executes them. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker +__RCSID__ = '$Id: $' + class CommandCaller: """ Module used for calling policies. Its class is used for invoking @@ -64,14 +68,4 @@ def _innerCall(self, c, a):#, clientIn = None): return res ################################################################################ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -################################################################################ - -''' - HOW DOES THIS WORK. - - will come soon... -''' - -################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/DIRACAccounting_Command.py b/ResourceStatusSystem/Command/DIRACAccounting_Command.py index 5267e2e8bba..95ac76cb848 100644 --- a/ResourceStatusSystem/Command/DIRACAccounting_Command.py +++ b/ResourceStatusSystem/Command/DIRACAccounting_Command.py @@ -1,21 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' DIRACAccounting_Command + The DIRACAccounting_Command class is a command class to interrogate the DIRAC Accounting. -""" + +''' from datetime import datetime, timedelta from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/DoNothing_Command.py b/ResourceStatusSystem/Command/DoNothing_Command.py index beec79ccca3..31fd3853e5a 100644 --- a/ResourceStatusSystem/Command/DoNothing_Command.py +++ b/ResourceStatusSystem/Command/DoNothing_Command.py @@ -1,18 +1,22 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' DoNothing_Command + + Demo Command. + +''' from DIRAC.ResourceStatusSystem.Command.Command import * -class DoNothing_Command(Command): +__RCSID__ = '$Id: $' + +class DoNothing_Command( Command ): - def doCommand(self): - """ - """ - super(DoNothing_Command, self).doCommand() + def doCommand( self ): + ''' Do nothing. + ''' + super( DoNothing_Command, self ).doCommand() - return {'Result':None} + return { 'Result' : None } doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__ diff --git a/ResourceStatusSystem/Command/GGUSTickets_Command.py b/ResourceStatusSystem/Command/GGUSTickets_Command.py index fc3c65b92ee..05e036b9739 100644 --- a/ResourceStatusSystem/Command/GGUSTickets_Command.py +++ b/ResourceStatusSystem/Command/GGUSTickets_Command.py @@ -1,20 +1,19 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' GGUSTickets_Command + The GGUSTickets_Command class is a command class to know about - the number of active present opened tickets -""" + the number of active present opened tickets. + +''' import urllib2 from DIRAC import gLogger, S_OK, S_ERROR -from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * +from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs + +__RCSID__ = '$Id: $' def callClient( name, clientIn ): diff --git a/ResourceStatusSystem/Command/GOCDBStatus_Command.py b/ResourceStatusSystem/Command/GOCDBStatus_Command.py index 9eeeb554e0a..e9953fb3742 100644 --- a/ResourceStatusSystem/Command/GOCDBStatus_Command.py +++ b/ResourceStatusSystem/Command/GOCDBStatus_Command.py @@ -1,23 +1,21 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' GOCDBStatus_Command The GOCDBStatus_Command class is a command class to know about present downtimes -""" +''' import urllib2 + from datetime import datetime from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.Utilities.SitesDIRACGOCDBmapping import getGOCSiteName - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import convertTime +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/Jobs_Command.py b/ResourceStatusSystem/Command/Jobs_Command.py index 147c60ce831..7bf0d9878e2 100644 --- a/ResourceStatusSystem/Command/Jobs_Command.py +++ b/ResourceStatusSystem/Command/Jobs_Command.py @@ -1,19 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' Jobs_Command + The Jobs_Command class is a command class to know about present jobs efficiency -""" + +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import * from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/MacroCommand.py b/ResourceStatusSystem/Command/MacroCommand.py index 283bb3a7ef1..cbc15b21602 100644 --- a/ResourceStatusSystem/Command/MacroCommand.py +++ b/ResourceStatusSystem/Command/MacroCommand.py @@ -1,26 +1,26 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' MacroCommand + The MacroCommand class is a macro class for all the macro commands for interacting with multiple commands -""" + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Command.Command import Command -class MacroCommand(Command): +__RCSID__ = '$Id: $' + +class MacroCommand( Command ): - def __init__(self): + def __init__( self ): self.commands = None self.args = None self.clients = None ################################################################################ - def setCommands(self, commandsListIn = None): + def setCommands( self, commandsListIn = None ): """ Method to be called as first at every MacroCommand instantiation. @@ -35,7 +35,7 @@ def setCommands(self, commandsListIn = None): ################################################################################ - def setArgs(self, argsListIn = None): + def setArgs( self, argsListIn = None ): """ Set the arguments of the commands. @@ -61,7 +61,7 @@ def setArgs(self, argsListIn = None): ################################################################################ - def setClient(self, clientListIn = None): + def setClient( self, clientListIn = None ): """ Set `self.clients`. If not set, a standard client will be instantiated. Then, set the clients used by the commands. @@ -87,7 +87,7 @@ def setClient(self, clientListIn = None): ################################################################################ - def doCommand(self): + def doCommand( self ): """ Calls command.doCommand for every command in the list of self.commands """ diff --git a/ResourceStatusSystem/Command/Macros_Command.py b/ResourceStatusSystem/Command/Macros_Command.py index 6744c5a7f4d..9e2a1c808b8 100644 --- a/ResourceStatusSystem/Command/Macros_Command.py +++ b/ResourceStatusSystem/Command/Macros_Command.py @@ -1,6 +1,13 @@ +# $HeadURL $ +''' MacrosCommand + +''' + from DIRAC.ResourceStatusSystem.Command.MacroCommand import MacroCommand -class TransferQualityOnSE_Command(MacroCommand): +__RCSID__ = '$Id: $' + +class TransferQualityOnSE_Command( MacroCommand ): def doCommand(self): #da decidere quali comandi @@ -12,20 +19,7 @@ def doCommand(self): # # return super(TransferQualityOnSE_Command, self).doCommand() pass - - - - - - - - - - - - - #from DIRAC.ResourceStatusSystem.Command.Command import Command # #class ProvaMacro_Command(MacroCommand): @@ -45,4 +39,7 @@ def doCommand(self): # #class provaCommand2(Command): # def doCommand(self): -# print "comando 2" \ No newline at end of file +# print "comando 2" + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/Pilots_Command.py b/ResourceStatusSystem/Command/Pilots_Command.py index 03e7d4fe3e9..169b9681e97 100644 --- a/ResourceStatusSystem/Command/Pilots_Command.py +++ b/ResourceStatusSystem/Command/Pilots_Command.py @@ -1,19 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" - -""" +''' Pilots_Command + The Pilots_Command class is a command class to know about - present pilots efficiency -""" + present pilots efficiency. + +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import Command from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities.Utils import where +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/RS_Command.py b/ResourceStatusSystem/Command/RS_Command.py index 4dab276d082..dc3ef58c3b4 100644 --- a/ResourceStatusSystem/Command/RS_Command.py +++ b/ResourceStatusSystem/Command/RS_Command.py @@ -1,19 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" -RS_Command -""" +''' RS_Command -__RCSID__ = "$Id: $" +''' from DIRAC import gLogger, S_OK, S_ERROR - from DIRAC.ResourceStatusSystem.Command.Command import Command from DIRAC.ResourceStatusSystem.Command.knownAPIs import initAPIs from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem import ValidRes +__RCSID__ = '$Id: $' + ################################################################################ ################################################################################ diff --git a/ResourceStatusSystem/Command/__init__.py b/ResourceStatusSystem/Command/__init__.py index 4414492c465..9ae08a8da74 100644 --- a/ResourceStatusSystem/Command/__init__.py +++ b/ResourceStatusSystem/Command/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Command package +''' -""" - DIRAC.ResourceStatusSystem.Command package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Command/knownAPIs.py b/ResourceStatusSystem/Command/knownAPIs.py index 46f92ad1925..c6b09dcd4b8 100644 --- a/ResourceStatusSystem/Command/knownAPIs.py +++ b/ResourceStatusSystem/Command/knownAPIs.py @@ -1,11 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' knownAPIs + + Module used to speed up API instantiation. + +''' from DIRAC import gLogger from DIRAC.Core.DISET.RPCClient import RPCClient +__RCSID__ = '$Id: $' ''' Here are all known and relevant APIs for the ResourceStatusSystem Commands From 4ac94927ad66c2f82e710eccdba0f22ac6ec08c2 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 12:57:02 +0100 Subject: [PATCH 07/33] pyLint changes ( cosmetic ) --- ResourceStatusSystem/DB/ResourceManagementDB.py | 12 ++++++++---- ResourceStatusSystem/DB/ResourceStatusDB.py | 12 ++++++++---- ResourceStatusSystem/DB/__init__.py | 9 +++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ResourceStatusSystem/DB/ResourceManagementDB.py b/ResourceStatusSystem/DB/ResourceManagementDB.py index 4232a60eea4..0b153f5fa99 100644 --- a/ResourceStatusSystem/DB/ResourceManagementDB.py +++ b/ResourceStatusSystem/DB/ResourceManagementDB.py @@ -1,10 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementDB + + Module that provides basic methods to access the ResourceManagementDB. + +''' from DIRAC.ResourceStatusSystem.Utilities.MySQLMonkey import MySQLMonkey -from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes +from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes + +__RCSID__ = '$Id: $' class ResourceManagementDB(object): """ diff --git a/ResourceStatusSystem/DB/ResourceStatusDB.py b/ResourceStatusSystem/DB/ResourceStatusDB.py index b6fa0a2ebef..0606ac2a039 100644 --- a/ResourceStatusSystem/DB/ResourceStatusDB.py +++ b/ResourceStatusSystem/DB/ResourceStatusDB.py @@ -1,11 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusDB + + Module that provides basic methods to access the ResourceStatusDB. + +''' from DIRAC.ResourceStatusSystem.Utilities.MySQLMonkey import MySQLMonkey from DIRAC.ResourceStatusSystem.Utilities.Decorators import CheckDBExecution, ValidateDBTypes +__RCSID__ = '$Id: $' + class ResourceStatusDB( object ): """ The ResourceStatusDB class is a front-end to the ResourceStatusDB MySQL db. @@ -360,4 +364,4 @@ def inspectSchema( self ): ## SEName = [ x[0] for x in SEName ] ## self.updateStorageElementStatus( storageElementName = SEName, lastCheckTime = znever ) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/DB/__init__.py b/ResourceStatusSystem/DB/__init__.py index 24b8f9ca31b..cb1b07f996e 100644 --- a/ResourceStatusSystem/DB/__init__.py +++ b/ResourceStatusSystem/DB/__init__.py @@ -1,11 +1,8 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.DB package +''' -""" - DIRAC.ResourceStatusSystem.DB package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From ee7001eb2e550b6af61fcebbb2552e7fb92f7edb Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 13:00:59 +0100 Subject: [PATCH 08/33] pyLint changes ( cosmetic ) --- .../Policy/AlwaysFalse_Policy.py | 19 ++++++++++------- ResourceStatusSystem/Policy/Configurations.py | 19 +++++++++++------ ResourceStatusSystem/Policy/DT_Policy.py | 21 +++++++++++-------- ResourceStatusSystem/Policy/__init__.py | 8 +++++++ 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py b/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py index 7a74459932d..4a41fd41c88 100644 --- a/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py +++ b/ResourceStatusSystem/Policy/AlwaysFalse_Policy.py @@ -1,14 +1,14 @@ -######################################################################## -# $HeadURL: -######################################################################## - -""" The AlwaysFalse_Policy class is a policy class that... checks nothing! -""" - -__RCSID__ = "$Id: " +# $HeadURL $ +''' AlwaysFalse_Policy + + The AlwaysFalse_Policy class is a policy class that... checks nothing! + +''' from DIRAC.ResourceStatusSystem.PolicySystem.PolicyBase import PolicyBase +__RCSID__ = '$Id: $' + class AlwaysFalse_Policy( PolicyBase ): def evaluate( self, commandIn = None, knownInfo = None ): @@ -25,3 +25,6 @@ def evaluate( self, commandIn = None, knownInfo = None ): return { 'Status' : 'Active', 'Reason' : 'This is the AlwasyFalse policy' } evaluate.__doc__ = PolicyBase.evaluate.__doc__ + evaluate.__doc__ + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/Configurations.py b/ResourceStatusSystem/Policy/Configurations.py index 5d8eef9b288..252be941295 100644 --- a/ResourceStatusSystem/Policy/Configurations.py +++ b/ResourceStatusSystem/Policy/Configurations.py @@ -1,15 +1,18 @@ -""" DIRAC.ResourceStatusSystem.Policy.Configurations Module +# $HeadURL $ +''' Configurations - collects everything needed to configure policies -""" - -__RCSID__ = "$Id: " + Collects everything needed to configure policies. + +''' from DIRAC.ResourceStatusSystem.Utilities import CS -pp = CS.getTypedDictRootedAt("PolicyParameters") +__RCSID__ = '$Id: $' + +pp = CS.getTypedDictRootedAt( 'PolicyParameters' ) Policies = { + 'DT_OnGoing_Only' : { 'Description' : "Ongoing down-times", @@ -37,4 +40,8 @@ 'commandIn' : None, 'args' : None } + } + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/DT_Policy.py b/ResourceStatusSystem/Policy/DT_Policy.py index e63206626ba..984d228427c 100644 --- a/ResourceStatusSystem/Policy/DT_Policy.py +++ b/ResourceStatusSystem/Policy/DT_Policy.py @@ -1,18 +1,18 @@ -######################################################################## # $HeadURL: -######################################################################## +''' DT_Policy -""" The DT_Policy class is a policy class satisfied when a site is in downtime, - or when a downtime is revoked -""" - -__RCSID__ = "$Id: " + The DT_Policy class is a policy class satisfied when a site is in downtime, + or when a downtime is revoked. + +''' from DIRAC.ResourceStatusSystem.PolicySystem.PolicyBase import PolicyBase -class DT_Policy(PolicyBase): +__RCSID__ = '$Id: $' + +class DT_Policy( PolicyBase ): - def evaluate(self): + def evaluate( self ): """ Evaluate policy on possible ongoing or scheduled downtimes. @@ -55,3 +55,6 @@ def evaluate(self): return result evaluate.__doc__ = PolicyBase.evaluate.__doc__ + evaluate.__doc__ + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/Policy/__init__.py b/ResourceStatusSystem/Policy/__init__.py index e69de29bb2d..cbc8d7371e9 100644 --- a/ResourceStatusSystem/Policy/__init__.py +++ b/ResourceStatusSystem/Policy/__init__.py @@ -0,0 +1,8 @@ +# $HeadURL $ +''' DIRAC.ResourceStatusSystem.Policy package +''' + +__RCSID__ = '$Id: $' + +################################################################################ +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From fb52f9c0bb16c0e85c871f7b69a5e02f2224d68c Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 13:10:09 +0100 Subject: [PATCH 09/33] pyLint changes ( cosmetic ) --- .../PolicySystem/Actions/ActionBase.py | 17 +++++------ .../PolicySystem/Actions/AlarmAction.py | 17 +++++------ .../PolicySystem/Actions/EmptyAction.py | 18 ++++++------ .../PolicySystem/Actions/RealBanAction.py | 13 +++++---- .../PolicySystem/Actions/ResourceAction.py | 23 ++++++++------- .../PolicySystem/Actions/__init__.py | 10 +++---- ResourceStatusSystem/PolicySystem/PDP.py | 18 +++++++----- ResourceStatusSystem/PolicySystem/PEP.py | 28 +++++++++---------- .../PolicySystem/PolicyBase.py | 17 ++++++----- .../PolicySystem/PolicyCaller.py | 15 ++++++---- ResourceStatusSystem/PolicySystem/Status.py | 15 ++++++---- ResourceStatusSystem/PolicySystem/__init__.py | 10 +++---- 12 files changed, 108 insertions(+), 93 deletions(-) diff --git a/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py b/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py index 58dc4752f8b..b456a80c509 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py +++ b/ResourceStatusSystem/PolicySystem/Actions/ActionBase.py @@ -1,13 +1,14 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" -Base class for Actions -""" +''' ActionBase + + Base class for Actions. + +''' -__RCSID__ = "$Id$" +__RCSID__ = '$Id: $' -class ActionBase(object): +class ActionBase( object ): + def __init__(self, granularity, name, status_type, pdp_decision, **kw): """Base class for actions. Arguments are: - granularity : string @@ -29,4 +30,4 @@ def run(self): pass ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py b/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py index 938a4dca589..4e1a3bce955 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/AlarmAction.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - AlarmPolType Actions -""" - -__RCSID__ = "$Id$" +''' AlarmAction + + AlarmPolType Actions. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import CS @@ -15,7 +13,10 @@ from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient -class AlarmAction(ActionBase): +__RCSID__ = '$Id: $' + +class AlarmAction( ActionBase ): + def __init__(self, granularity, name, status_type, pdp_decision, **kw): ActionBase.__init__( self, granularity, name, status_type, pdp_decision, **kw ) diff --git a/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py b/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py index c33961204b9..b7823e1a803 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/EmptyAction.py @@ -1,15 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - ResourcePolType Actions -""" -__RCSID__ = "$Id$" +''' EmptyAction -from DIRAC import gLogger + Action that does nothing. + +''' + +from DIRAC import gLogger from DIRAC.ResourceStatusSystem.PolicySystem.Actions.ActionBase import ActionBase -class EmptyAction(ActionBase): +__RCSID__ = '$Id: $' + +class EmptyAction( ActionBase ): + def run(self): """Do nothing, but log it :)""" gLogger.info( 'EmptyAction at %s with %s' % (self.name, str(self.pdp_decision))) diff --git a/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py b/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py index 72bf82434e5..44160194b67 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/RealBanAction.py @@ -1,9 +1,10 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - RealBan_PolType Actions -""" +''' RealBanAction + + RealBan_PolType Actions. + +''' + import time from DIRAC.ResourceStatusSystem.Utilities import CS @@ -11,6 +12,8 @@ from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI +__RCSID__ = '$Id: $' + da = DiracAdmin() csAPI = CSAPI() diff --git a/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py b/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py index 26221614bc0..131282dc0fa 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py +++ b/ResourceStatusSystem/PolicySystem/Actions/ResourceAction.py @@ -1,17 +1,20 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" - ResourcePolType Actions -""" +''' ResourceAction + + ResourcePolType Actions. + +''' -__RCSID__ = "$Id$" +from datetime import datetime from DIRAC.ResourceStatusSystem.PolicySystem.Actions.ActionBase import ActionBase -from datetime import datetime -class ResourceAction(ActionBase): - def run(self): +__RCSID__ = '$Id: $' + +class ResourceAction( ActionBase ): + + def run( self ): + token = 'RS_SVC' if self.new_status['Action']: @@ -45,4 +48,4 @@ def run(self): self.status_type, self.new_status['EndDate'] ) ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Actions/__init__.py b/ResourceStatusSystem/PolicySystem/Actions/__init__.py index ebd5ade4fc5..0acf784052e 100644 --- a/ResourceStatusSystem/PolicySystem/Actions/__init__.py +++ b/ResourceStatusSystem/PolicySystem/Actions/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.PolicySystem.Actions package + +''' -""" - Actions for PEP -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/PDP.py b/ResourceStatusSystem/PolicySystem/PDP.py index b926b276cb0..06520d6ecac 100644 --- a/ResourceStatusSystem/PolicySystem/PDP.py +++ b/ResourceStatusSystem/PolicySystem/PDP.py @@ -1,14 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' PDP + + PolicyDecissionPoint + +''' import datetime -from DIRAC.ResourceStatusSystem.PolicySystem import Status -from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter -from DIRAC.ResourceStatusSystem.PolicySystem.PolicyCaller import PolicyCaller -from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +from DIRAC.ResourceStatusSystem.PolicySystem import Status +from DIRAC.ResourceStatusSystem.Utilities.InfoGetter import InfoGetter +from DIRAC.ResourceStatusSystem.PolicySystem.PolicyCaller import PolicyCaller +from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller + +__RCSID__ = '$Id: $' class PDP: """ diff --git a/ResourceStatusSystem/PolicySystem/PEP.py b/ResourceStatusSystem/PolicySystem/PEP.py index dccd3049f10..4c202471d7b 100644 --- a/ResourceStatusSystem/PolicySystem/PEP.py +++ b/ResourceStatusSystem/PolicySystem/PEP.py @@ -1,24 +1,24 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" +''' PEP + Module used for enforcing policies. Its class is used for: 1. invoke a PDP and collects results 2. enforcing results by: a. saving result on a DB b. raising alarms c. other.... -""" -from DIRAC import S_OK, S_ERROR - -from DIRAC.ResourceStatusSystem import ValidRes, ValidStatus, ValidStatusTypes, \ - ValidSiteType, ValidServiceType, ValidResourceType - -from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient -from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient -from DIRAC.ResourceStatusSystem.PolicySystem.Actions.EmptyAction import EmptyAction -from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP -from DIRAC.ResourceStatusSystem.Utilities import Utils +''' + +from DIRAC import S_OK, S_ERROR +from DIRAC.ResourceStatusSystem import ValidRes, \ + ValidStatus, ValidStatusTypes, ValidSiteType, ValidServiceType, ValidResourceType +from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient +from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient +from DIRAC.ResourceStatusSystem.PolicySystem.Actions.EmptyAction import EmptyAction +from DIRAC.ResourceStatusSystem.PolicySystem.PDP import PDP +from DIRAC.ResourceStatusSystem.Utilities import Utils + +__RCSID__ = '$Id: $' class PEP: """ diff --git a/ResourceStatusSystem/PolicySystem/PolicyBase.py b/ResourceStatusSystem/PolicySystem/PolicyBase.py index e55947d25e6..57c16e6e0ab 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyBase.py +++ b/ResourceStatusSystem/PolicySystem/PolicyBase.py @@ -1,19 +1,18 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" - -""" - The Policy class is a simple base class for all the policies -""" +''' PolicyBase + + The Policy class is a simple base class for all the policies. + +''' from DIRAC import gLogger from DIRAC.ResourceStatusSystem import ValidRes - from DIRAC.ResourceStatusSystem.Command.ClientsInvoker import ClientsInvoker from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller -class PolicyBase(object): +__RCSID__ = '$Id: $' + +class PolicyBase( object ): """ Base class for all the policies. Do not instantiate directly. To use, you should call at least `setArgs` and, alternatively, diff --git a/ResourceStatusSystem/PolicySystem/PolicyCaller.py b/ResourceStatusSystem/PolicySystem/PolicyCaller.py index 66b52cdda38..9d0e7c9a868 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyCaller.py +++ b/ResourceStatusSystem/PolicySystem/PolicyCaller.py @@ -1,14 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -""" +''' PolicyCaller + Module used for calling policies. Its class is used for invoking - real policies, based on the policy name -""" -from DIRAC import gLogger + real policies, based on the policy name. + +''' + +from DIRAC import gLogger from DIRAC.ResourceStatusSystem.Utilities import Utils from DIRAC.ResourceStatusSystem.Command.CommandCaller import CommandCaller +__RCSID__ = '$Id: $' + class PolicyCaller: def __init__( self, commandCallerIn = None, **clients ): self.cc = commandCallerIn if commandCallerIn != None else CommandCaller() diff --git a/ResourceStatusSystem/PolicySystem/Status.py b/ResourceStatusSystem/PolicySystem/Status.py index 258b063a82d..29c692bd164 100644 --- a/ResourceStatusSystem/PolicySystem/Status.py +++ b/ResourceStatusSystem/PolicySystem/Status.py @@ -1,12 +1,15 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' Status + + Module that keeps the StateMachine. + +''' -from DIRAC import gLogger +from DIRAC import gLogger +from DIRAC.ResourceStatusSystem.Utilities.Utils import id_fun +from DIRAC.ResourceStatusSystem import ValidStatus -from DIRAC.ResourceStatusSystem.Utilities.Utils import id_fun -from DIRAC.ResourceStatusSystem import ValidStatus +__RCSID__ = '$Id: $' statesInfo = { 'Banned' : (0, set([0,1]), max), diff --git a/ResourceStatusSystem/PolicySystem/__init__.py b/ResourceStatusSystem/PolicySystem/__init__.py index 8f03a29fb48..32a163b41a0 100644 --- a/ResourceStatusSystem/PolicySystem/__init__.py +++ b/ResourceStatusSystem/PolicySystem/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.PolicySystem package + +''' -""" - DIRAC.ResourceStatusSystem.PolicySystem package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From 48214284edc363b6470e4833763632c0a59da953 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 13:24:24 +0100 Subject: [PATCH 10/33] pyLint changes ( cosmetic ) --- .../Service/ResourceManagementHandler.py | 11 +++++++---- .../Service/ResourceStatusHandler.py | 13 ++++++++----- ResourceStatusSystem/Service/__init__.py | 10 ++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ResourceStatusSystem/Service/ResourceManagementHandler.py b/ResourceStatusSystem/Service/ResourceManagementHandler.py index 12e01f98d41..c293969b06c 100644 --- a/ResourceStatusSystem/Service/ResourceManagementHandler.py +++ b/ResourceStatusSystem/Service/ResourceManagementHandler.py @@ -1,13 +1,16 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceManagementHandler + + Module that allows users to access the ResourceManagementDB remotely. + +''' from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RequestHandler import RequestHandler from DIRAC.ResourceStatusSystem.DB.ResourceManagementDB import ResourceManagementDB -db = False +__RCSID__ = '$Id: $' +db = False def initializeResourceManagementHandler( _serviceInfo ): diff --git a/ResourceStatusSystem/Service/ResourceStatusHandler.py b/ResourceStatusSystem/Service/ResourceStatusHandler.py index 4d2a7b94cc8..cc144f0f3f7 100644 --- a/ResourceStatusSystem/Service/ResourceStatusHandler.py +++ b/ResourceStatusSystem/Service/ResourceStatusHandler.py @@ -1,14 +1,17 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id: $" +''' ResourceStatusHandler + + Module that allows users to access the ResourceStatusDB remotely. + +''' from DIRAC import gConfig, S_OK, S_ERROR, gLogger from DIRAC.Core.DISET.RequestHandler import RequestHandler - from DIRAC.ResourceStatusSystem.DB.ResourceStatusDB import ResourceStatusDB from DIRAC.ResourceStatusSystem.Utilities import Utils -db = False + +__RCSID__ = '$Id: $' +db = False def initializeResourceStatusHandler( _serviceInfo ): diff --git a/ResourceStatusSystem/Service/__init__.py b/ResourceStatusSystem/Service/__init__.py index aa50271b353..e3c8e92d84d 100644 --- a/ResourceStatusSystem/Service/__init__.py +++ b/ResourceStatusSystem/Service/__init__.py @@ -1,11 +1,9 @@ -################################################################################ # $HeadURL $ -################################################################################ -__RCSID__ = "$Id$" +''' DIRAC.ResourceStatusSystem.Service package + +''' -""" - DIRAC.ResourceStatusSystem.Service package -""" +__RCSID__ = '$Id: $' ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From 245bbccc88a9ea4149cca282fe62ace8d613f7a4 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:06:30 +0100 Subject: [PATCH 11/33] pyLint changes ( docstring ) --- .../Service/ResourceManagementHandler.py | 5 +++- .../Service/ResourceStatusHandler.py | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ResourceStatusSystem/Service/ResourceManagementHandler.py b/ResourceStatusSystem/Service/ResourceManagementHandler.py index c293969b06c..e7048d96d9d 100644 --- a/ResourceStatusSystem/Service/ResourceManagementHandler.py +++ b/ResourceStatusSystem/Service/ResourceManagementHandler.py @@ -13,7 +13,10 @@ db = False def initializeResourceManagementHandler( _serviceInfo ): - + ''' + Handler initialization, where we set the ResourceManagementDB as global db. + ''' + global db db = ResourceManagementDB() diff --git a/ResourceStatusSystem/Service/ResourceStatusHandler.py b/ResourceStatusSystem/Service/ResourceStatusHandler.py index cc144f0f3f7..5bde5048a4c 100644 --- a/ResourceStatusSystem/Service/ResourceStatusHandler.py +++ b/ResourceStatusSystem/Service/ResourceStatusHandler.py @@ -14,7 +14,10 @@ db = False def initializeResourceStatusHandler( _serviceInfo ): - + ''' + Handler initialization, where we set the ResourceStatusDB as global db, and + we instantiate the synchronizer. + ''' global db db = ResourceStatusDB() @@ -30,9 +33,10 @@ def initializeResourceStatusHandler( _serviceInfo ): # publisher = Publisher( VOExtension, dbIn = db, commandCallerIn = cc, # infoGetterIn = ig, WMSAdminIn = WMSAdmin ) - SyncModule = Utils.voimport("DIRAC.ResourceStatusSystem.Utilities.Synchronizer") - sync_O = SyncModule.Synchronizer() - gConfig.addListenerToNewVersionEvent( sync_O.sync ) + syncModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Utilities.Synchronizer' ) + syncObject = syncModule.Synchronizer() + gConfig.addListenerToNewVersionEvent( syncObject.sync ) + return S_OK() ################################################################################ @@ -209,7 +213,8 @@ def export_delete( self, params, meta ): ## """ get periods of time when name was in status (for a total of hours hours) ## """ ## -## gLogger.info( "ResourceStatusHandler.getPeriods: Attempting to get %s periods when it was in %s" % ( name, status ) ) +## gLogger.info( "ResourceStatusHandler.getPeriods: Attempting to get %s periods \ +## when it was in %s" % ( name, status ) ) ## ## try: ## resQuery = rsDB.getPeriods( granularity, name, status, int( hours ) ) @@ -385,7 +390,8 @@ def export_delete( self, params, meta ): ## """ Enforce all the policies. If `useNewRes` is False, use cached results only (where available). ## """ ## try: -## gLogger.info("ResourceStatusHandler.enforcePolicies: Attempting to enforce policies for %s %s" % (granularity, name)) +## gLogger.info("ResourceStatusHandler.enforcePolicies: Attempting to \ +## enforce policies for %s %s" % (granularity, name)) ## try: ## reason = serviceType = resourceType = None ## @@ -515,7 +521,8 @@ def export_delete( self, params, meta ): ## else: ## rsDB.setToken( granularity, name, 'RS_SVC', datetime( 9999, 12, 31, 23, 59, 59 ) ) ## -## gLogger.info( "ResourceStatusHandler.reAssignToken: re-assigned token %s: %s: %s" % ( granularity, name, requester ) ) +## gLogger.info( "ResourceStatusHandler.reAssignToken: re-assigned token %s: %s: \ +## %s" % ( granularity, name, requester ) ) ## return S_OK() ## except Exception, x: ## errorStr = whoRaised( x ) @@ -549,7 +556,8 @@ def export_delete( self, params, meta ): ## except OverflowError: ## pass ## rsDB.setToken( granularity, name, tokenOwner, tokenNewExpiration ) -## gLogger.info( "ResourceStatusHandler.extendToken: extended token %s: %s for %i hours" % ( granularity, name, hrs ) ) +## gLogger.info( "ResourceStatusHandler.extendToken: extended token %s: \ +## %s for %i hours" % ( granularity, name, hrs ) ) ## return S_OK() ## except Exception, x: ## errorStr = whoRaised( x ) From bc5c3505e1135d0ecfa382e08036e844ea810438 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:09:25 +0100 Subject: [PATCH 12/33] pyLint changes ( cosmetic ) --- ResourceStatusSystem/DB/ResourceManagementDB.py | 14 +++++++------- ResourceStatusSystem/DB/ResourceStatusDB.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ResourceStatusSystem/DB/ResourceManagementDB.py b/ResourceStatusSystem/DB/ResourceManagementDB.py index 0b153f5fa99..f3bdbd3e29c 100644 --- a/ResourceStatusSystem/DB/ResourceManagementDB.py +++ b/ResourceStatusSystem/DB/ResourceManagementDB.py @@ -71,14 +71,14 @@ class ResourceManagementDB(object): def __init__( self, *args, **kwargs ): """Constructor.""" if len(args) == 1: - if isinstance(args[0], str): - maxQueueSize=10 - if isinstance(args[0], int): - maxQueueSize=args[0] + if isinstance( args[ 0 ], str ): + maxQueueSize = 10 + if isinstance( args[ 0 ], int ): + maxQueueSize = args[ 0 ] elif len(args) == 2: - maxQueueSize=args[1] + maxQueueSize = args[ 1 ] elif len(args) == 0: - maxQueueSize=10 + maxQueueSize = 10 if 'DBin' in kwargs.keys(): DBin = kwargs[ 'DBin' ] @@ -91,7 +91,7 @@ def __init__( self, *args, **kwargs ): from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceManagementDB', 'ResourceStatus/ResourceManagementDB', maxQueueSize ) - self.mm = MySQLMonkey( self ) + self.mm = MySQLMonkey( self ) @CheckDBExecution @ValidateDBTypes diff --git a/ResourceStatusSystem/DB/ResourceStatusDB.py b/ResourceStatusSystem/DB/ResourceStatusDB.py index 0606ac2a039..01b9650846b 100644 --- a/ResourceStatusSystem/DB/ResourceStatusDB.py +++ b/ResourceStatusSystem/DB/ResourceStatusDB.py @@ -92,7 +92,7 @@ def __init__( self, *args, **kwargs ): from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceStatusDB', 'ResourceStatus/ResourceStatusDB', maxQueueSize ) - self.mm = MySQLMonkey( self ) + self.mm = MySQLMonkey( self ) @CheckDBExecution @ValidateDBTypes From 4552ee657840f6538b4ae0ebb1e17eecd253307c Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:20:37 +0100 Subject: [PATCH 13/33] pyLint changes ( variable renaming ) --- .../Client/ResourceManagementClient.py | 16 ++++++++-------- .../Client/ResourceStatusClient.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index bdc07345280..503a1671b3d 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -763,25 +763,25 @@ def addOrModifyUserRegistryCache( self, login, name, email ): def _insertElement( self, element, kwargs ): fname = 'insert%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) def _updateElement( self, element, kwargs ): fname = 'update%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) def _getElement( self, element, kwargs ): fname = 'get%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) def _deleteElement( self, element, kwargs ): fname = 'delete%s' % element - f = getattr( self, fname ) - return f( **kwargs ) + fElem = getattr( self, fname ) + return fElem( **kwargs ) ''' ############################################################################## diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index be6f7006309..016ce5a3029 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -2547,29 +2547,29 @@ def __getStats( self, sqlQuery ): def _insertElement( self, elementTable, paramsDict ): fname = 'insert%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) # def _updateElement( self, elementTable, **kwargs ): def _updateElement( self, elementTable, paramsDict ): fname = 'update%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) # def _getElement( self, elementTable, **kwargs ): def _getElement( self, elementTable, paramsDict ): fname = 'get%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) # def _deleteElement( self, elementTable, **kwargs ): def _deleteElement( self, elementTable, paramsDict ): fname = 'delete%s' % elementTable - f = getattr( self, fname ) - return f( **paramsDict ) + fElem = getattr( self, fname ) + return fElem( **paramsDict ) ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file From 091dc8d77b3d27beb9f96378e4958b619ac11b5e Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:43:34 +0100 Subject: [PATCH 14/33] pyLint changes ( disable message ) --- ResourceStatusSystem/Client/ResourceStatusClient.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 016ce5a3029..2a0c6730f33 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -145,6 +145,7 @@ def __query( self, queryType, tableName, kwargs ): ############################################################################## ''' + # pylint: disable-msg=W0613 def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): ''' Inserts on Site a new row with the arguments given. From 80e6ae1ff2429f735b45650b9f3876dc460062cb Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:54:34 +0100 Subject: [PATCH 15/33] pyLint changes ( locally disabling ) --- .../Client/ResourceStatusClient.py | 60 ++++++++++++++++--- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 2a0c6730f33..70b3ccbb475 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -48,6 +48,8 @@ class ResourceStatusClient: the client considerably. """ + # pylint: disable-msg=I0011 + def __init__( self , serviceIn = None ): ''' The client tries to connect to :class:ResourceStatusDB by default. If it @@ -137,15 +139,13 @@ def __query( self, queryType, tableName, kwargs ): meta[ 'table' ] = tableName gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) - return gateFunction( params, meta ) - + return gateFunction( params, meta ) + ''' ############################################################################## # SITE FUNCTIONS ############################################################################## ''' - - # pylint: disable-msg=W0613 def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): ''' Inserts on Site a new row with the arguments given. @@ -164,6 +164,7 @@ def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Site', locals() ) def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): ''' @@ -184,6 +185,7 @@ def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'Site', locals() ) def getSite( self, siteName = None, siteType = None, gridSiteName = None, meta = {} ): @@ -204,6 +206,7 @@ def getSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'Site', locals() ) def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, meta = {} ): @@ -224,6 +227,7 @@ def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Site', locals() ) def getSitePresent( self, siteName = None, siteType = None, gridSiteName = None, gridTier = None, statusType = None, @@ -266,6 +270,7 @@ def getSitePresent( self, siteName = None, siteType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'SitePresent', locals() ) ''' @@ -291,6 +296,7 @@ def insertService( self, serviceName, serviceType, siteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Service', locals() ) def updateService( self, serviceName, serviceType, siteName, meta = {} ): ''' @@ -311,6 +317,7 @@ def updateService( self, serviceName, serviceType, siteName, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'Service', locals() ) def getService( self, serviceName = None, serviceType = None, siteName = None, meta = {} ): @@ -331,6 +338,7 @@ def getService( self, serviceName = None, serviceType = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'Service', locals() ) def deleteService( self, serviceName = None, serviceType = None, siteName = None, meta = {} ): @@ -351,6 +359,7 @@ def deleteService( self, serviceName = None, serviceType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Service', locals() ) def getServicePresent( self, serviceName = None, siteName = None, siteType = None, serviceType = None, statusType = None, @@ -395,6 +404,7 @@ def getServicePresent( self, serviceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ServicePresent', locals() ) ''' @@ -425,6 +435,7 @@ def insertResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'Resource', locals() ) def updateResource( self, resourceName, resourceType, serviceType, siteName, gridSiteName, meta = {} ): @@ -450,6 +461,7 @@ def updateResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'Resource', locals() ) def getResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, @@ -475,6 +487,7 @@ def getResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'Resource', locals() ) def deleteResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, @@ -500,6 +513,7 @@ def deleteResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'Resource', locals() ) def getResourcePresent( self, resourceName = None, siteName = None, serviceType = None, gridSiteName = None, @@ -551,6 +565,7 @@ def getResourcePresent( self, resourceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ResourcePresent', locals() ) ''' @@ -575,7 +590,8 @@ def insertStorageElement( self, storageElementName, resourceName, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'StorageElement', locals() ) def updateStorageElement( self, storageElementName, resourceName, gridSiteName, meta = {} ): @@ -596,6 +612,7 @@ def updateStorageElement( self, storageElementName, resourceName, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'StorageElement', locals() ) def getStorageElement( self, storageElementName = None, resourceName = None, gridSiteName = None, meta = {} ): @@ -614,7 +631,8 @@ def getStorageElement( self, storageElementName = None, resourceName = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElement', locals() ) def deleteStorageElement( self, storageElementName = None, resourceName = None, gridSiteName = None, @@ -635,6 +653,7 @@ def deleteStorageElement( self, storageElementName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'StorageElement', locals() ) def getStorageElementPresent( self, storageElementName = None, resourceName = None, gridSiteName = None, @@ -680,6 +699,7 @@ def getStorageElementPresent( self, storageElementName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElementPresent', locals() ) ''' @@ -702,6 +722,7 @@ def insertGridSite( self, gridSiteName, gridTier, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'GridSite', locals() ) def updateGridSite( self, gridSiteName, gridTier, meta = {} ): ''' @@ -719,6 +740,7 @@ def updateGridSite( self, gridSiteName, gridTier, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'GridSite', locals() ) def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): ''' @@ -735,6 +757,7 @@ def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'GridSite', locals() ) def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): ''' @@ -750,7 +773,8 @@ def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'GridSite', locals() ) ''' @@ -796,6 +820,7 @@ def insertElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementStatus', locals() ) def updateElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, @@ -836,6 +861,7 @@ def updateElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementStatus', locals() ) def getElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, @@ -876,6 +902,7 @@ def getElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementStatus', locals() ) def deleteElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, @@ -916,6 +943,7 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementStatus', locals() ) ''' @@ -961,6 +989,7 @@ def insertElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementScheduledStatus', locals() ) def updateElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, @@ -1002,6 +1031,7 @@ def updateElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementScheduledStatus', locals() ) def getElementScheduledStatus( self, element, elementName = None, statusType = None, status = None, @@ -1043,6 +1073,7 @@ def getElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementScheduledStatus', locals() ) def deleteElementScheduledStatus( self, element, elementName = None, statusType = None, status = None, @@ -1085,6 +1116,7 @@ def deleteElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementScheduledStatus', locals() ) ''' @@ -1130,6 +1162,7 @@ def insertElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementHistory', locals() ) def updateElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, @@ -1171,6 +1204,7 @@ def updateElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementHistory', locals() ) def getElementHistory( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, @@ -1211,6 +1245,7 @@ def getElementHistory( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementHistory', locals() ) def deleteElementHistory( self, element, elementName = None, statusType = None, status = None, reason = None, @@ -1252,9 +1287,10 @@ def deleteElementHistory( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementHistory', locals() ) - - ''' + + ''' ############################################################################## # CS VALID ELEMENTS ############################################################################## @@ -1338,6 +1374,7 @@ def addOrModifySite( self, siteName, siteType, gridSiteName ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Site', locals() ) def addOrModifyService( self, serviceName, serviceType, siteName ): @@ -1356,6 +1393,7 @@ def addOrModifyService( self, serviceName, serviceType, siteName ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Service', locals() ) def addOrModifyResource( self, resourceName, resourceType, serviceType, @@ -1379,6 +1417,7 @@ def addOrModifyResource( self, resourceName, resourceType, serviceType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Resource', locals() ) def addOrModifyStorageElement( self, storageElementName, resourceName, @@ -1397,6 +1436,7 @@ def addOrModifyStorageElement( self, storageElementName, resourceName, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'StorageElement', locals() ) def addOrModifyGridSite( self, gridSiteName, gridTier ): @@ -1462,6 +1502,7 @@ def modifyElementStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__modifyElementStatus( locals() ) def removeElement( self, element, elementName ): @@ -1478,6 +1519,7 @@ def removeElement( self, element, elementName ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__removeElement( element, elementName ) def getServiceStats( self, siteName, statusType = None ): From 49c94875f9bd7ffd43fcc07a734f8e7efd224e6a Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 14:57:43 +0100 Subject: [PATCH 16/33] Removed unused code --- .../Client/ResourceManagementClient.py | 38 ---------------- .../Client/ResourceStatusClient.py | 45 ------------------- 2 files changed, 83 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 503a1671b3d..84ba75a98e7 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -83,44 +83,6 @@ def __query( self, queryType, tableName, kwargs ): gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) -# def __query( self, kwargs ): -# ''' -# This method is a rather important one. It will format the input for the DB -# queries, instead of doing it on a decorator. Two dictionaries must be passed -# to the DB. First one contains 'columnName' : value pairs, being the key -# lower camel case. The second one must have, at lease, a key named 'table' -# with the right table name. -# ''' -# -# # Functions we can call, just a light safety measure. -# __INTERNAL_FUNCTIONS__ = [ 'insert', 'update', 'get', 'delete' ] -# gateFunction = None -# -# # I'm simply lazy, do not want to pass function name as argument. I get it here -# fname = sys._getframe( 1 ).f_code.co_name -# meta = kwargs.pop( 'meta' ) -# params = kwargs -# del params[ 'self' ] -# -# for _ifName in __INTERNAL_FUNCTIONS__: -# -# if fname.startswith( _ifName ): -# -# _table = fname.replace( _ifName, '' ) -# -# meta[ 'table' ] = _table -# -# gateFunction = getattr( self.gate, _ifName ) -# continue -# -# # Be careful, __eq__ method cannot be executed if we use server ! -# if gateFunction is not None: -# -# gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( _ifName, params, meta ) ) -# return gateFunction( params, meta ) -# -# return S_ERROR( 'Cannot find right call for %s' % fname ) - def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): ''' Inserts on EnvironmentCache a new row with the arguments given. diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 70b3ccbb475..b294883d644 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -65,51 +65,6 @@ def __init__( self , serviceIn = None ): self.gate = RPCClient( "ResourceStatus/ResourceStatus" ) else: self.gate = serviceIn - -# def __query( self, kwargs ): -# ''' -# This method is a rather important one. It will format the input for the DB -# queries, instead of doing it on a decorator. Two dictionaries must be passed -# to the DB. First one contains 'columnName' : value pairs, being the key -# lower camel case. The second one must have, at lease, a key named 'table' -# with the right table name. -# ''' -# -# # Functions we can call, just a light safety measure. -# __INTERNAL_FUNCTIONS__ = [ 'insert', 'update', 'get', 'delete' ] -# gateFunction = None -# -# # I'm simply lazy, do not want to pass function name as argument. I get it here -# fname = sys._getframe( 1 ).f_code.co_name -# meta = kwargs.pop( 'meta' ) -# params = kwargs -# del params[ 'self' ] -# -# for _ifName in __INTERNAL_FUNCTIONS__: -# -# if fname.startswith( _ifName ): -# -# _table = fname.replace( _ifName, '' ) -# -# # This is an special case with the Element tables. -# if _table.startswith( 'Element' ): -# _element = params.pop( 'element' ) -# _table = _table.replace( 'Element', _element ) -# params[ '%sName' % _element ] = params[ 'elementName' ] -# del params[ 'elementName' ] -# -# meta[ 'table' ] = _table -# -# gateFunction = getattr( self.gate, _ifName ) -# continue -# -# # Be careful, __eq__ method cannot be executed if we use server ! -# if gateFunction is not None: -# -# gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( _ifName, params, meta ) ) -# return gateFunction( params, meta ) -# -# return S_ERROR( 'Cannot find right call for %s' % fname ) def __query( self, queryType, tableName, kwargs ): ''' From 189a60c003c1d380d3cc87e44a59da2db802ff14 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:08:14 +0100 Subject: [PATCH 17/33] pyLint changes ( cosmetic ) --- .../Client/ResourceManagementClient.py | 40 +++--- .../Client/ResourceStatusClient.py | 124 ++++++------------ 2 files changed, 67 insertions(+), 97 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 84ba75a98e7..107c714dc67 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -83,6 +83,9 @@ def __query( self, queryType, tableName, kwargs ): gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) +################################################################################ +# ENVIRONMENT CACHE FUNCTIONS + def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): ''' Inserts on EnvironmentCache a new row with the arguments given. @@ -158,6 +161,10 @@ def deleteEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' return self.__query( 'delete', 'EnvironmentCache', locals() ) + +################################################################################ +# POLICY RESULT FUNCTIONS + def insertPolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, meta = {} ): @@ -288,6 +295,10 @@ def deletePolicyResult( self, granularity = None, name = None, :return: S_OK() || S_ERROR() ''' return self.__query( 'delete', 'PolicyResult', locals() ) + +################################################################################ +# CLIENT CACHE FUNCTIONS + def insertClientCache( self, name, commandName, opt_ID, value, result, dateEffective, lastCheckTime, meta = {} ): ''' @@ -399,6 +410,10 @@ def deleteClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' return self.__query( 'delete', 'ClientCache', locals() ) + +################################################################################ +# ACCOUNTING CACHE FUNCTIONS + def insertAccountingCache( self, name, plotType, plotName, result, dateEffective, lastCheckTime, meta = {} ): ''' @@ -503,6 +518,10 @@ def deleteAccountingCache( self, name = None, plotType = None, :return: S_OK() || S_ERROR() ''' return self.__query( 'delete', 'AccountingCache', locals() ) + +################################################################################ +# USER REGISTRY CACHE FUNCTIONS + def insertUserRegistryCache( self, login, name, email, meta = {} ): ''' Inserts on UserRegistryCache a new row with the arguments given. @@ -579,11 +598,8 @@ def deleteUserRegistryCache( self, login = None, name = None, email = None, ''' return self.__query( 'delete', 'UserRegistryCache', locals() ) - ''' - ############################################################################## - # EXTENDED BASE API METHODS - ############################################################################## - ''' +################################################################################ +# EXTENDED BASE API METHODS def addOrModifyEnvironmentCache( self, hashEnv, siteName, environment ): ''' @@ -715,12 +731,8 @@ def addOrModifyUserRegistryCache( self, login, name, email ): return self.__addOrModifyElement( 'UserRegistryCache', locals() ) ################################################################################ +# Getter functions - ''' - ############################################################################## - # Getter functions - ############################################################################## - ''' def _insertElement( self, element, kwargs ): @@ -745,11 +757,9 @@ def _deleteElement( self, element, kwargs ): fElem = getattr( self, fname ) return fElem( **kwargs ) - ''' - ############################################################################## - # addOrModify PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# addOrModify PRIVATE FUNCTIONS + def __addOrModifyElement( self, element, kwargs ): del kwargs[ 'self' ] diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index b294883d644..141d2569f37 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -20,7 +20,7 @@ __RCSID__ = '$Id: $' class ResourceStatusClient: - """ + ''' The :class:`ResourceStatusClient` class exposes the :mod:`DIRAC.ResourceStatus` API. All functions you need are on this client. @@ -46,9 +46,7 @@ class ResourceStatusClient: All functions calling methods exposed on the database or on the booster are making use of some syntactic sugar, in this case a decorator that simplifies the client considerably. - """ - - # pylint: disable-msg=I0011 + ''' def __init__( self , serviceIn = None ): ''' @@ -96,11 +94,9 @@ def __query( self, queryType, tableName, kwargs ): gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) - ''' - ############################################################################## - # SITE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# SITE FUNCTIONS + def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): ''' Inserts on Site a new row with the arguments given. @@ -228,11 +224,9 @@ def getSitePresent( self, siteName = None, siteType = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'SitePresent', locals() ) - ''' - ############################################################################## - # SERVICE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# SERVICE FUNCTIONS + def insertService( self, serviceName, serviceType, siteName, meta = {} ): ''' Inserts on Service a new row with the arguments given. @@ -362,11 +356,10 @@ def getServicePresent( self, serviceName = None, siteName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'ServicePresent', locals() ) - ''' - ############################################################################## - # RESOURCE FUNCTIONS - ############################################################################## - ''' + +################################################################################ +# RESOURCE FUNCTIONS + def insertResource( self, resourceName, resourceType, serviceType, siteName, gridSiteName, meta = {} ): ''' @@ -523,11 +516,9 @@ def getResourcePresent( self, resourceName = None, siteName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'ResourcePresent', locals() ) - ''' - ############################################################################## - # STORAGE ELEMENT FUNCTIONS - ############################################################################## - ''' +################################################################################ +# STORAGE ELEMENT FUNCTIONS + def insertStorageElement( self, storageElementName, resourceName, gridSiteName, meta = {} ): ''' @@ -657,11 +648,9 @@ def getStorageElementPresent( self, storageElementName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElementPresent', locals() ) - ''' - ############################################################################## - # GRID SITE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# GRID SITE FUNCTIONS + def insertGridSite( self, gridSiteName, gridTier, meta = {} ): ''' Inserts on GridSite a new row with the arguments given. @@ -732,11 +721,9 @@ def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): # pylint: disable-msg=W0613 return self.__query( 'delete', 'GridSite', locals() ) - ''' - ############################################################################## - # ELEMENT STATUS FUNCTIONS - ############################################################################## - ''' +################################################################################ +# ELEMENT STATUS FUNCTIONS + def insertElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, @@ -901,11 +888,9 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementStatus', locals() ) - ''' - ############################################################################## - # ELEMENT SCHEDULED STATUS FUNCTIONS - ############################################################################## - ''' +################################################################################ +# ELEMENT SCHEDULED STATUS FUNCTIONS + def insertElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, @@ -1073,12 +1058,10 @@ def deleteElementScheduledStatus( self, element, elementName = None, ''' # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementScheduledStatus', locals() ) - - ''' - ############################################################################## - # ELEMENT HISTORY FUNCTIONS - ############################################################################## - ''' + +################################################################################ +# ELEMENT HISTORY FUNCTIONS + def insertElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, @@ -1245,11 +1228,8 @@ def deleteElementHistory( self, element, elementName = None, # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementHistory', locals() ) - ''' - ############################################################################## - # CS VALID ELEMENTS - ############################################################################## - ''' +################################################################################ +# CS VALID ELEMENTS def getValidElements( self ): ''' @@ -1307,11 +1287,8 @@ def getValidResourceTypes( self ): ''' return S_OK( ValidResourceType ) - ''' - ############################################################################## - # EXTENDED FUNCTIONS - ############################################################################## - ''' +################################################################################ +# EXTENDED FUNCTIONS def addOrModifySite( self, siteName, siteType, gridSiteName ): ''' @@ -2312,11 +2289,9 @@ def getMonitoredsStatusWeb( self, granularity, selectDict, startItem, ################################################################################ - ''' - ############################################################################## - # addOrModify PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# addOrModify PRIVATE FUNCTIONS + def __addOrModifyElement( self, element, kwargs ): @@ -2425,11 +2400,8 @@ def __setStatusDefaults( self ): return iDict - ''' - ############################################################################## - # Modify PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# Modify PRIVATE FUNCTIONS def __modifyElementStatus( self,kwargs ): @@ -2488,11 +2460,8 @@ def __modifyElementStatus( self,kwargs ): return updateSQLQuery - ''' - ############################################################################## - # remove PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# remove PRIVATE FUNCTIONS def __removeElement( self, element, elementName ): @@ -2511,11 +2480,8 @@ def __removeElement( self, element, elementName ): return sqlQuery - ''' - ############################################################################## - # stats PRIVATE FUNCTIONS - ############################################################################## - ''' +################################################################################ +# stats PRIVATE FUNCTIONS def __getStats( self, sqlQuery ): @@ -2532,14 +2498,8 @@ def __getStats( self, sqlQuery ): count['Total'] = sum( count.values() ) return S_OK( count ) - ################################################################################ - - ''' - ############################################################################## - # Getter functions - ############################################################################## - ''' +# Getter functions # def _insertElement( self, elementTable, **kwargs ): def _insertElement( self, elementTable, paramsDict ): From c6c4a447abd5d3ec2384fb0eb955f2e4f7df9201 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:23:03 +0100 Subject: [PATCH 18/33] pyLint changes ( meta = None instead of {} ) --- .../Client/ResourceManagementClient.py | 44 +++++------ .../Client/ResourceStatusClient.py | 78 +++++++++---------- 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 107c714dc67..c64fb093689 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -74,7 +74,8 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) - meta = kwargs.pop( 'meta' ) + # If meta is None, we set it to {} + meta = ( kwargs.pop( 'meta' ) and True ) or {} params = kwargs del params[ 'self' ] @@ -86,7 +87,7 @@ def __query( self, queryType, tableName, kwargs ): ################################################################################ # ENVIRONMENT CACHE FUNCTIONS - def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): + def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): ''' Inserts on EnvironmentCache a new row with the arguments given. @@ -104,7 +105,7 @@ def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): :return: S_OK() || S_ERROR() ''' return self.__query( 'insert', 'EnvironmentCache', locals() ) - def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): + def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): ''' Updates EnvironmentCache with the parameters given. By default, `hashEnv` will be the parameter used to select the row. @@ -124,7 +125,7 @@ def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = {} ): ''' return self.__query( 'update', 'EnvironmentCache', locals() ) def getEnvironmentCache( self, hashEnv = None, siteName = None, - environment = None, meta = {} ): + environment = None, meta = None ): ''' Gets from EnvironmentCache all rows that match the parameters given. @@ -143,7 +144,7 @@ def getEnvironmentCache( self, hashEnv = None, siteName = None, ''' return self.__query( 'get', 'EnvironmentCache', locals() ) def deleteEnvironmentCache( self, hashEnv = None, siteName = None, - environment = None, meta = {} ): + environment = None, meta = None ): ''' Deletes from EnvironmentCache all rows that match the parameters given. @@ -167,7 +168,7 @@ def deleteEnvironmentCache( self, hashEnv = None, siteName = None, def insertPolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, - meta = {} ): + meta = None ): ''' Inserts on PolicyResult a new row with the arguments given. @@ -199,7 +200,7 @@ def insertPolicyResult( self, granularity, name, policyName, statusType, return self.__query( 'insert', 'PolicyResult', locals() ) def updatePolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, - meta = {} ): + meta = None ): ''' Updates PolicyResult with the parameters given. By default, `name`, `policyName` and `statusType` will be the parameters used to select the row. @@ -232,7 +233,7 @@ def updatePolicyResult( self, granularity, name, policyName, statusType, return self.__query( 'update', 'PolicyResult', locals() ) def getPolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, reason = None, - dateEffective = None, lastCheckTime = None, meta = {} ): + dateEffective = None, lastCheckTime = None, meta = None ): ''' Gets from PolicyResult all rows that match the parameters given. @@ -265,7 +266,7 @@ def getPolicyResult( self, granularity = None, name = None, policyName = None, def deletePolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, reason = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -300,7 +301,7 @@ def deletePolicyResult( self, granularity = None, name = None, # CLIENT CACHE FUNCTIONS def insertClientCache( self, name, commandName, opt_ID, value, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Inserts on ClientCache a new row with the arguments given. @@ -327,7 +328,7 @@ def insertClientCache( self, name, commandName, opt_ID, value, result, ''' return self.__query( 'insert', 'ClientCache', locals() ) def updateClientCache( self, name, commandName, opt_ID, value, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Updates ClientCache with the parameters given. By default, `name`, `commandName` and `value` will be the parameters used to select the row. @@ -356,7 +357,7 @@ def updateClientCache( self, name, commandName, opt_ID, value, result, return self.__query( 'update', 'ClientCache', locals() ) def getClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Gets from ClientCache all rows that match the parameters given. @@ -384,7 +385,7 @@ def getClientCache( self, name = None, commandName = None, opt_ID = None, return self.__query( 'get', 'ClientCache', locals() ) def deleteClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -415,7 +416,7 @@ def deleteClientCache( self, name = None, commandName = None, opt_ID = None, # ACCOUNTING CACHE FUNCTIONS def insertAccountingCache( self, name, plotType, plotName, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Inserts on AccountingCache a new row with the arguments given. @@ -440,7 +441,7 @@ def insertAccountingCache( self, name, plotType, plotName, result, ''' return self.__query( 'insert', 'AccountingCache', locals() ) def updateAccountingCache( self, name, plotType, plotName, result, - dateEffective, lastCheckTime, meta = {} ): + dateEffective, lastCheckTime, meta = None ): ''' Updates AccountingCache with the parameters given. By default, `name`, `plotType` and `plotName` will be the parameters used to select the row. @@ -467,7 +468,7 @@ def updateAccountingCache( self, name, plotType, plotName, result, return self.__query( 'update', 'AccountingCache', locals() ) def getAccountingCache( self, name = None, plotType = None, plotName = None, result = None, dateEffective = None, - lastCheckTime = None, meta = {} ): + lastCheckTime = None, meta = None ): ''' Gets from PolicyResult all rows that match the parameters given. @@ -494,7 +495,7 @@ def getAccountingCache( self, name = None, plotType = None, plotName = None, def deleteAccountingCache( self, name = None, plotType = None, plotName = None, result = None, dateEffective = None, lastCheckTime = None, - meta = {} ): + meta = None ): ''' Deletes from PolicyResult all rows that match the parameters given. @@ -522,7 +523,7 @@ def deleteAccountingCache( self, name = None, plotType = None, ################################################################################ # USER REGISTRY CACHE FUNCTIONS - def insertUserRegistryCache( self, login, name, email, meta = {} ): + def insertUserRegistryCache( self, login, name, email, meta = None ): ''' Inserts on UserRegistryCache a new row with the arguments given. @@ -540,7 +541,7 @@ def insertUserRegistryCache( self, login, name, email, meta = {} ): :return: S_OK() || S_ERROR() ''' return self.__query( 'insert', 'UserRegistryCache', locals() ) - def updateUserRegistryCache( self, login, name, email, meta = {} ): + def updateUserRegistryCache( self, login, name, email, meta = None ): ''' Updates UserRegistryCache with the parameters given. By default, `login` will be the parameter used to select the row. @@ -560,7 +561,7 @@ def updateUserRegistryCache( self, login, name, email, meta = {} ): ''' return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, - meta = {} ): + meta = None ): ''' Gets from UserRegistryCache all rows that match the parameters given. @@ -579,7 +580,7 @@ def getUserRegistryCache( self, login = None, name = None, email = None, ''' return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, - meta = {} ): + meta = None ): ''' Deletes from UserRegistryCache all rows that match the parameters given. @@ -733,7 +734,6 @@ def addOrModifyUserRegistryCache( self, login, name, email ): ################################################################################ # Getter functions - def _insertElement( self, element, kwargs ): fname = 'insert%s' % element diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 141d2569f37..2e310b258d7 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -5,8 +5,6 @@ ''' -import sys - from datetime import datetime, timedelta from DIRAC import S_OK, S_ERROR, gLogger @@ -79,7 +77,8 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) - meta = kwargs.pop( 'meta' ) + # If meta is None, we set it to {} + meta = ( kwargs.pop( 'meta' ) and True ) or {} params = kwargs del params[ 'self' ] @@ -97,7 +96,7 @@ def __query( self, queryType, tableName, kwargs ): ################################################################################ # SITE FUNCTIONS - def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): + def insertSite( self, siteName, siteType, gridSiteName, meta = None ): ''' Inserts on Site a new row with the arguments given. @@ -117,7 +116,7 @@ def insertSite( self, siteName, siteType, gridSiteName, meta = {} ): ''' # pylint: disable-msg=W0613 return self.__query( 'insert', 'Site', locals() ) - def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): + def updateSite( self, siteName, siteType, gridSiteName, meta = None ): ''' Updates Site with the parameters given. By default, `siteName` will be the \ parameter used to select the row. @@ -139,7 +138,7 @@ def updateSite( self, siteName, siteType, gridSiteName, meta = {} ): # pylint: disable-msg=W0613 return self.__query( 'update', 'Site', locals() ) def getSite( self, siteName = None, siteType = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Gets from Site all rows that match the parameters given. @@ -160,7 +159,7 @@ def getSite( self, siteName = None, siteType = None, gridSiteName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'Site', locals() ) def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from Site all rows that match the parameters given. @@ -184,7 +183,7 @@ def getSitePresent( self, siteName = None, siteType = None, gridSiteName = None, gridTier = None, statusType = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, formerStatus = None, meta = {} ): + tokenExpiration = None, formerStatus = None, meta = None ): ''' Gets from the view composed by Site, SiteStatus and SiteHistory all rows that match the parameters given ( not necessarily returns the same number @@ -227,7 +226,7 @@ def getSitePresent( self, siteName = None, siteType = None, ################################################################################ # SERVICE FUNCTIONS - def insertService( self, serviceName, serviceType, siteName, meta = {} ): + def insertService( self, serviceName, serviceType, siteName, meta = None ): ''' Inserts on Service a new row with the arguments given. @@ -247,7 +246,7 @@ def insertService( self, serviceName, serviceType, siteName, meta = {} ): ''' # pylint: disable-msg=W0613 return self.__query( 'insert', 'Service', locals() ) - def updateService( self, serviceName, serviceType, siteName, meta = {} ): + def updateService( self, serviceName, serviceType, siteName, meta = None ): ''' Updates Service with the parameters given. By default, `serviceName` will \ be the parameter used to select the row. @@ -269,7 +268,7 @@ def updateService( self, serviceName, serviceType, siteName, meta = {} ): # pylint: disable-msg=W0613 return self.__query( 'update', 'Service', locals() ) def getService( self, serviceName = None, serviceType = None, siteName = None, - meta = {} ): + meta = None ): ''' Gets from Service all rows that match the parameters given. @@ -290,7 +289,7 @@ def getService( self, serviceName = None, serviceType = None, siteName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'Service', locals() ) def deleteService( self, serviceName = None, serviceType = None, - siteName = None, meta = {} ): + siteName = None, meta = None ): ''' Deletes from Service all rows that match the parameters given. @@ -315,7 +314,7 @@ def getServicePresent( self, serviceName = None, siteName = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, formerStatus = None, - meta = {} ): + meta = None ): ''' Gets from the view composed by Service, ServiceStatus and ServiceHistory all rows that match the parameters given ( not necessarily returns the same @@ -356,12 +355,11 @@ def getServicePresent( self, serviceName = None, siteName = None, # pylint: disable-msg=W0613 return self.__query( 'get', 'ServicePresent', locals() ) - ################################################################################ # RESOURCE FUNCTIONS def insertResource( self, resourceName, resourceType, serviceType, siteName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Inserts on Resource a new row with the arguments given. @@ -386,7 +384,7 @@ def insertResource( self, resourceName, resourceType, serviceType, siteName, # pylint: disable-msg=W0613 return self.__query( 'insert', 'Resource', locals() ) def updateResource( self, resourceName, resourceType, serviceType, siteName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Updates Resource with the parameters given. By default, `resourceName` will be the parameter used to select the row. @@ -413,7 +411,7 @@ def updateResource( self, resourceName, resourceType, serviceType, siteName, return self.__query( 'update', 'Resource', locals() ) def getResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Gets from Resource all rows that match the parameters given. @@ -439,7 +437,7 @@ def getResource( self, resourceName = None, resourceType = None, return self.__query( 'get', 'Resource', locals() ) def deleteResource( self, resourceName = None, resourceType = None, serviceType = None, siteName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from Resource all rows that match the parameters given. @@ -470,7 +468,7 @@ def getResourcePresent( self, resourceName = None, siteName = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, formerStatus = None, - meta = {} ): + meta = None ): ''' Gets from the view composed by Resource, ResourceStatus and ResourceHistory all rows that match the parameters given ( not necessarily returns the same @@ -520,7 +518,7 @@ def getResourcePresent( self, resourceName = None, siteName = None, # STORAGE ELEMENT FUNCTIONS def insertStorageElement( self, storageElementName, resourceName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Inserts on StorageElement a new row with the arguments given. @@ -540,7 +538,7 @@ def insertStorageElement( self, storageElementName, resourceName, # pylint: disable-msg=W0613 return self.__query( 'insert', 'StorageElement', locals() ) def updateStorageElement( self, storageElementName, resourceName, - gridSiteName, meta = {} ): + gridSiteName, meta = None ): ''' Updates StorageElement with the parameters given. By default, `storageElementName` will be the parameter used to select the row. @@ -561,7 +559,7 @@ def updateStorageElement( self, storageElementName, resourceName, # pylint: disable-msg=W0613 return self.__query( 'update', 'StorageElement', locals() ) def getStorageElement( self, storageElementName = None, resourceName = None, - gridSiteName = None, meta = {} ): + gridSiteName = None, meta = None ): ''' Gets from StorageElement all rows that match the parameters given. @@ -582,7 +580,7 @@ def getStorageElement( self, storageElementName = None, resourceName = None, return self.__query( 'get', 'StorageElement', locals() ) def deleteStorageElement( self, storageElementName = None, resourceName = None, gridSiteName = None, - meta = {} ): + meta = None ): ''' Deletes from StorageElement all rows that match the parameters given. @@ -607,7 +605,7 @@ def getStorageElementPresent( self, storageElementName = None, status = None, dateEffective = None, reason = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, - formerStatus = None, meta = {} ): + formerStatus = None, meta = None ): ''' Gets from the view composed by StorageElement, StorageElementStatus and StorageElementHistory all rows that match the parameters given ( not @@ -651,7 +649,7 @@ def getStorageElementPresent( self, storageElementName = None, ################################################################################ # GRID SITE FUNCTIONS - def insertGridSite( self, gridSiteName, gridTier, meta = {} ): + def insertGridSite( self, gridSiteName, gridTier, meta = None ): ''' Inserts on GridSite a new row with the arguments given. @@ -668,7 +666,7 @@ def insertGridSite( self, gridSiteName, gridTier, meta = {} ): ''' # pylint: disable-msg=W0613 return self.__query( 'insert', 'GridSite', locals() ) - def updateGridSite( self, gridSiteName, gridTier, meta = {} ): + def updateGridSite( self, gridSiteName, gridTier, meta = None ): ''' Updates GridSite with the parameters given. By default, `gridSiteName` will be the parameter used to select the row. @@ -686,7 +684,7 @@ def updateGridSite( self, gridSiteName, gridTier, meta = {} ): ''' # pylint: disable-msg=W0613 return self.__query( 'update', 'GridSite', locals() ) - def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): + def getGridSite( self, gridSiteName = None, gridTier = None, meta = None ): ''' Gets from GridSite all rows that match the parameters given. @@ -703,7 +701,7 @@ def getGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): ''' # pylint: disable-msg=W0613 return self.__query( 'get', 'GridSite', locals() ) - def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): + def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = None ): ''' Deletes from GridSite all rows that match the parameters given. @@ -727,7 +725,7 @@ def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = {} ): def insertElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Inserts on Status a new row with the arguments given. @@ -767,7 +765,7 @@ def insertElementStatus( self, element, elementName, statusType, status, def updateElementStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Updates Status with the parameters given. By default, `elementName` and 'statusType' will be the parameters used to select the row. @@ -809,7 +807,7 @@ def getElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from Status all rows that match the parameters given. @@ -850,7 +848,7 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Deletes from Status all rows that match the parameters given. @@ -894,7 +892,7 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, def insertElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, - tokenExpiration, meta = {} ): + tokenExpiration, meta = None ): ''' Inserts on ScheduledStatus a new row with the arguments given. @@ -934,7 +932,7 @@ def insertElementScheduledStatus( self, element, elementName, statusType, def updateElementScheduledStatus( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, - tokenExpiration, meta = {} ): + tokenExpiration, meta = None ): ''' Updates ScheduledStatus with the parameters given. By default, `elementName`, 'statusType' and `dateEffective` will be the parameters used @@ -978,7 +976,7 @@ def getElementScheduledStatus( self, element, elementName = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from ScheduledStatus all rows that match the parameters given. @@ -1020,7 +1018,7 @@ def deleteElementScheduledStatus( self, element, elementName = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Deletes from ScheduledStatus all rows that match the parameters given. @@ -1065,7 +1063,7 @@ def deleteElementScheduledStatus( self, element, elementName = None, def insertElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Inserts on History a new row with the arguments given. @@ -1105,7 +1103,7 @@ def insertElementHistory( self, element, elementName, statusType, status, def updateElementHistory( self, element, elementName, statusType, status, reason, dateCreated, dateEffective, dateEnd, lastCheckTime, tokenOwner, tokenExpiration, - meta = {} ): + meta = None ): ''' Updates History with the parameters given. By default, `elementName`, 'statusType', `reason` and `dateEnd` will be the parameters @@ -1148,7 +1146,7 @@ def getElementHistory( self, element, elementName = None, statusType = None, status = None, reason = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, - tokenExpiration = None, meta = {} ): + tokenExpiration = None, meta = None ): ''' Gets from History all rows that match the parameters given. @@ -1190,7 +1188,7 @@ def deleteElementHistory( self, element, elementName = None, dateCreated = None, dateEffective = None, dateEnd = None, lastCheckTime = None, tokenOwner = None, tokenExpiration = None, - meta = {} ): + meta = None ): ''' Deletes from History all rows that match the parameters given. From b240650861f949639b560adcb30aff4e4e080825 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:25:13 +0100 Subject: [PATCH 19/33] pyLint changes ( disabled unused ) --- .../Client/ResourceManagementClient.py | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index c64fb093689..59957fa4a07 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -104,6 +104,7 @@ def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'EnvironmentCache', locals() ) def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): ''' @@ -123,6 +124,7 @@ def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'EnvironmentCache', locals() ) def getEnvironmentCache( self, hashEnv = None, siteName = None, environment = None, meta = None ): @@ -142,6 +144,7 @@ def getEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'EnvironmentCache', locals() ) def deleteEnvironmentCache( self, hashEnv = None, siteName = None, environment = None, meta = None ): @@ -161,6 +164,7 @@ def deleteEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'EnvironmentCache', locals() ) ################################################################################ @@ -197,6 +201,7 @@ def insertPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'PolicyResult', locals() ) def updatePolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime, @@ -230,6 +235,7 @@ def updatePolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'PolicyResult', locals() ) def getPolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, reason = None, @@ -262,6 +268,7 @@ def getPolicyResult( self, granularity = None, name = None, policyName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'PolicyResult', locals() ) def deletePolicyResult( self, granularity = None, name = None, policyName = None, statusType = None, status = None, @@ -295,6 +302,7 @@ def deletePolicyResult( self, granularity = None, name = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'PolicyResult', locals() ) ################################################################################ @@ -326,6 +334,7 @@ def insertClientCache( self, name, commandName, opt_ID, value, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'ClientCache', locals() ) def updateClientCache( self, name, commandName, opt_ID, value, result, dateEffective, lastCheckTime, meta = None ): @@ -354,6 +363,7 @@ def updateClientCache( self, name, commandName, opt_ID, value, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'ClientCache', locals() ) def getClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, @@ -382,6 +392,7 @@ def getClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'ClientCache', locals() ) def deleteClientCache( self, name = None, commandName = None, opt_ID = None, value = None, result = None, dateEffective = None, @@ -410,6 +421,7 @@ def deleteClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'ClientCache', locals() ) ################################################################################ @@ -439,6 +451,7 @@ def insertAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'AccountingCache', locals() ) def updateAccountingCache( self, name, plotType, plotName, result, dateEffective, lastCheckTime, meta = None ): @@ -465,6 +478,7 @@ def updateAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'AccountingCache', locals() ) def getAccountingCache( self, name = None, plotType = None, plotName = None, result = None, dateEffective = None, @@ -491,6 +505,7 @@ def getAccountingCache( self, name = None, plotType = None, plotName = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'AccountingCache', locals() ) def deleteAccountingCache( self, name = None, plotType = None, plotName = None, result = None, @@ -518,6 +533,7 @@ def deleteAccountingCache( self, name = None, plotType = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'AccountingCache', locals() ) ################################################################################ @@ -540,6 +556,7 @@ def insertUserRegistryCache( self, login, name, email, meta = None ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'insert', 'UserRegistryCache', locals() ) def updateUserRegistryCache( self, login, name, email, meta = None ): ''' @@ -559,6 +576,7 @@ def updateUserRegistryCache( self, login, name, email, meta = None ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, meta = None ): @@ -578,6 +596,7 @@ def getUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, meta = None ): @@ -597,6 +616,7 @@ def deleteUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'delete', 'UserRegistryCache', locals() ) ################################################################################ @@ -620,8 +640,8 @@ def addOrModifyEnvironmentCache( self, hashEnv, siteName, environment ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'EnvironmentCache', locals() ) - def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, status, reason, dateEffective, lastCheckTime ): ''' @@ -653,8 +673,8 @@ def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'PolicyResult', locals() ) - def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, dateEffective, lastCheckTime ): ''' @@ -682,8 +702,8 @@ def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'ClientCache', locals() ) - def addOrModifyAccountingCache( self, name, plotType, plotName, result, dateEffective, lastCheckTime ): ''' @@ -709,8 +729,8 @@ def addOrModifyAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'AccountingCache', locals() ) - def addOrModifyUserRegistryCache( self, login, name, email ): ''' Using `login` to query the database, decides whether to insert or update @@ -729,6 +749,7 @@ def addOrModifyUserRegistryCache( self, login, name, email ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'UserRegistryCache', locals() ) ################################################################################ From 48d633f77e8af868addc83b969ff87b783ed5e74 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:31:12 +0100 Subject: [PATCH 20/33] test --- ResourceStatusSystem/Client/ResourceManagementClient.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 59957fa4a07..7a2591f3336 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -576,7 +576,6 @@ def updateUserRegistryCache( self, login, name, email, meta = None ): :return: S_OK() || S_ERROR() ''' - # pylint: disable-msg=W0613 return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, meta = None ): From c30a45b303cbd5bafdfac57240d8ec8869a9c6ae Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:31:46 +0100 Subject: [PATCH 21/33] test --- ResourceStatusSystem/Client/ResourceManagementClient.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 7a2591f3336..9d081c7df84 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -595,7 +595,6 @@ def getUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' - # pylint: disable-msg=W0613 return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, meta = None ): From 286406c0a219dd4937046a811b1d684026de028a Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:46:32 +0100 Subject: [PATCH 22/33] pyLint changes ( variable rename ) --- ResourceStatusSystem/DB/ResourceManagementDB.py | 12 ++++-------- ResourceStatusSystem/DB/ResourceStatusDB.py | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ResourceStatusSystem/DB/ResourceManagementDB.py b/ResourceStatusSystem/DB/ResourceManagementDB.py index f3bdbd3e29c..ff28fca03e1 100644 --- a/ResourceStatusSystem/DB/ResourceManagementDB.py +++ b/ResourceStatusSystem/DB/ResourceManagementDB.py @@ -81,12 +81,12 @@ def __init__( self, *args, **kwargs ): maxQueueSize = 10 if 'DBin' in kwargs.keys(): - DBin = kwargs[ 'DBin' ] + dbIn = kwargs[ 'DBin' ] if isinstance(DBin, list): from DIRAC.Core.Utilities.MySQL import MySQL - self.db = MySQL( 'localhost', DBin[0], DBin[1], 'ResourceManagementDB' ) + self.db = MySQL( 'localhost', dbIn[0], dbIn[1], 'ResourceManagementDB' ) else: - self.db = DBin + self.db = dbIn else: from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceManagementDB', 'ResourceStatus/ResourceManagementDB', maxQueueSize ) @@ -223,9 +223,6 @@ def inspectSchema( self ): ################################################################################ #EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF -''' -This will go to the booster - ################################################################################ ## Web functions ################################################################################ @@ -290,5 +287,4 @@ def inspectSchema( self ): # # return finalDict # -################################################################################ -''' +################################################################################ \ No newline at end of file diff --git a/ResourceStatusSystem/DB/ResourceStatusDB.py b/ResourceStatusSystem/DB/ResourceStatusDB.py index 01b9650846b..b07d561746b 100644 --- a/ResourceStatusSystem/DB/ResourceStatusDB.py +++ b/ResourceStatusSystem/DB/ResourceStatusDB.py @@ -82,12 +82,12 @@ def __init__( self, *args, **kwargs ): maxQueueSize = 10 if 'DBin' in kwargs.keys(): - DBin = kwargs[ 'DBin' ] + dbIn = kwargs[ 'DBin' ] if isinstance( DBin, list ): from DIRAC.Core.Utilities.MySQL import MySQL - self.db = MySQL( 'localhost', DBin[ 0 ], DBin[ 1 ], 'ResourceStatusDB' ) + self.db = MySQL( 'localhost', dbIn[ 0 ], dbIn[ 1 ], 'ResourceStatusDB' ) else: - self.db = DBin + self.db = dbIn else: from DIRAC.Core.Base.DB import DB self.db = DB( 'ResourceStatusDB', 'ResourceStatus/ResourceStatusDB', maxQueueSize ) From 2e0ea98bb821fc288b324cdfc8c08356160a642a Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 15:46:54 +0100 Subject: [PATCH 23/33] pyLint changes ( added docstring ) --- .../Client/ResourceManagementClient.py | 24 +++++++++++++++---- .../Client/ResourceStatusClient.py | 20 +++++++++------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 9d081c7df84..c5b1ea3d9ca 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -576,6 +576,7 @@ def updateUserRegistryCache( self, login, name, email, meta = None ): :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, meta = None ): @@ -595,6 +596,7 @@ def getUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # pylint: disable-msg=W0613 return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, meta = None ): @@ -754,24 +756,33 @@ def addOrModifyUserRegistryCache( self, login, name, email ): # Getter functions def _insertElement( self, element, kwargs ): - + ''' + Method that executes the insert method of the given element. + ''' fname = 'insert%s' % element fElem = getattr( self, fname ) return fElem( **kwargs ) def _updateElement( self, element, kwargs ): - + ''' + Method that executes the update method of the given element. + ''' fname = 'update%s' % element fElem = getattr( self, fname ) return fElem( **kwargs ) def _getElement( self, element, kwargs ): - + ''' + Method that executes the get method of the given element. + ''' fname = 'get%s' % element fElem = getattr( self, fname ) return fElem( **kwargs ) - def _deleteElement( self, element, kwargs ): + def _deleteElement( self, element, kwargs ): + ''' + Method that executes the delete method of the given element. + ''' fname = 'delete%s' % element fElem = getattr( self, fname ) return fElem( **kwargs ) @@ -780,7 +791,10 @@ def _deleteElement( self, element, kwargs ): # addOrModify PRIVATE FUNCTIONS def __addOrModifyElement( self, element, kwargs ): - + ''' + Method that executes update if the item is not new, otherwise inserts it + on the element table. + ''' del kwargs[ 'self' ] kwargs[ 'meta' ] = { 'onlyUniqueKeys' : True } diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 2e310b258d7..514d544a65d 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -2499,30 +2499,34 @@ def __getStats( self, sqlQuery ): ################################################################################ # Getter functions -# def _insertElement( self, elementTable, **kwargs ): def _insertElement( self, elementTable, paramsDict ): - + ''' + Method that executes the insert method of the given element. + ''' fname = 'insert%s' % elementTable fElem = getattr( self, fname ) return fElem( **paramsDict ) -# def _updateElement( self, elementTable, **kwargs ): def _updateElement( self, elementTable, paramsDict ): - + ''' + Method that executes the update method of the given element. + ''' fname = 'update%s' % elementTable fElem = getattr( self, fname ) return fElem( **paramsDict ) -# def _getElement( self, elementTable, **kwargs ): def _getElement( self, elementTable, paramsDict ): - + ''' + Method that executes the get method of the given element. + ''' fname = 'get%s' % elementTable fElem = getattr( self, fname ) return fElem( **paramsDict ) -# def _deleteElement( self, elementTable, **kwargs ): def _deleteElement( self, elementTable, paramsDict ): - + ''' + Method that executes the delete method of the given element. + ''' fname = 'delete%s' % elementTable fElem = getattr( self, fname ) return fElem( **paramsDict ) From d1cf5ba9fd17419f70579ab04681fe2a4061f6b6 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 16:11:40 +0100 Subject: [PATCH 24/33] pyLint changes ( variable renaming, docstrings ) --- .../Agent/CacheCleanerAgent.py | 8 +-- .../Agent/CacheFeederAgent.py | 32 ++++++------ .../Agent/RSInspectorAgent.py | 48 ++++++++--------- .../Agent/SSInspectorAgent.py | 47 ++++++++--------- .../Agent/SeSInspectorAgent.py | 31 +++++------ .../Agent/StElInspectorAgent.py | 51 ++++++++++--------- ResourceStatusSystem/Agent/TokenAgent.py | 48 ++++++++--------- 7 files changed, 134 insertions(+), 131 deletions(-) diff --git a/ResourceStatusSystem/Agent/CacheCleanerAgent.py b/ResourceStatusSystem/Agent/CacheCleanerAgent.py index 7744dd505e8..22073551f32 100644 --- a/ResourceStatusSystem/Agent/CacheCleanerAgent.py +++ b/ResourceStatusSystem/Agent/CacheCleanerAgent.py @@ -6,7 +6,7 @@ ''' -from datetime import datetime,timedelta +from datetime import datetime, timedelta from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule @@ -61,12 +61,12 @@ def execute( self ): now = datetime.utcnow().replace( microsecond = 0, second = 0 ) sixMonthsAgo = now - timedelta( days = 180 ) - for g in ValidRes: + for granularity in ValidRes: #deleter = getattr( self.rsClient, 'delete%sHistory' % g ) kwargs = { 'meta' : { 'minor' : { 'DateEnd' : sixMonthsAgo } } } - self.log.info( 'Deleting %sHistory older than %s' % ( g, sixMonthsAgo ) ) - res = self.rsClient.deleteElementHistory( g, **kwargs ) + self.log.info( 'Deleting %sHistory older than %s' % ( granularity, sixMonthsAgo ) ) + res = self.rsClient.deleteElementHistory( granularity, **kwargs ) if not res[ 'OK' ]: self.log.error( res[ 'Message' ] ) diff --git a/ResourceStatusSystem/Agent/CacheFeederAgent.py b/ResourceStatusSystem/Agent/CacheFeederAgent.py index 706507cba51..f0440d1797e 100644 --- a/ResourceStatusSystem/Agent/CacheFeederAgent.py +++ b/ResourceStatusSystem/Agent/CacheFeederAgent.py @@ -31,14 +31,14 @@ def initialize( self ): self.rmClient = ResourceManagementClient() self.clientsInvoker = ClientsInvoker() - commandsList_ClientsCache = [ + commandsListClientsCache = [ ( 'ClientsCache_Command', 'JobsEffSimpleEveryOne_Command' ), ( 'ClientsCache_Command', 'PilotsEffSimpleEverySites_Command' ), ( 'ClientsCache_Command', 'DTEverySites_Command' ), ( 'ClientsCache_Command', 'DTEveryResources_Command' ) ] - commandsList_AccountingCache = [ + commandsListAccountingCache = [ ( 'AccountingCache_Command', 'TransferQualityByDestSplitted_Command', ( 2, ), 'Always' ), ( 'AccountingCache_Command', 'FailedTransfersBySourceSplitted_Command', ( 2, ), 'Always' ), ( 'AccountingCache_Command', 'TransferQualityByDestSplittedSite_Command', ( 24, ), 'Hourly' ), @@ -54,33 +54,33 @@ def initialize( self ): ( 'AccountingCache_Command', 'RunningJobsBySiteSplitted_Command', ( 8760, ), 'Daily' ), ] - self.commandObjectsList_ClientsCache = [] - self.commandObjectsList_AccountingCache = [] + self.commandObjectsListClientsCache = [] + self.commandObjectsListAccountingCache = [] cc = CommandCaller() # We know beforehand which APIs are we going to need, so we initialize them # first, making everything faster. - APIs = [ 'ResourceStatusClient', 'WMSAdministrator', 'ReportGenerator', - 'JobsClient', 'PilotsClient', 'GOCDBClient', 'ReportsClient' ] - APIs = initAPIs( APIs, {} ) + knownAPIs = [ 'ResourceStatusClient', 'WMSAdministrator', 'ReportGenerator', + 'JobsClient', 'PilotsClient', 'GOCDBClient', 'ReportsClient' ] + knownAPIs = initAPIs( knownAPIs, {} ) - for command in commandsList_ClientsCache: + for command in commandsListClientsCache: cObj = cc.setCommandObject( command ) - for apiName, apiInstance in APIs.items(): + for apiName, apiInstance in knownAPIs.items(): cc.setAPI( cObj, apiName, apiInstance ) - self.commandObjectsList_ClientsCache.append( ( command, cObj ) ) + self.commandObjectsListClientsCache.append( ( command, cObj ) ) - for command in commandsList_AccountingCache: + for command in commandsListAccountingCache: cObj = cc.setCommandObject( command ) - for apiName, apiInstance in APIs.items(): + for apiName, apiInstance in knownAPIs.items(): cc.setAPI( cObj, apiName, apiInstance ) cArgs = command[ 2 ] - self.commandObjectsList_AccountingCache.append( ( command, cObj, cArgs ) ) + self.commandObjectsListAccountingCache.append( ( command, cObj, cArgs ) ) return S_OK() @@ -95,10 +95,10 @@ def execute( self ): try: - for co in self.commandObjectsList_ClientsCache: + for co in self.commandObjectsListClientsCache: commandName = co[0][1].split( '_' )[0] - gLogger.info( 'Executed %s' % commandName ) + self.log.info( 'Executed %s' % commandName ) try: self.clientsInvoker.setCommand( co[1] ) res = self.clientsInvoker.doCommand()['Result'] @@ -143,7 +143,7 @@ def execute( self ): now = datetime.utcnow().replace( microsecond = 0 ) - for co in self.commandObjectsList_AccountingCache: + for co in self.commandObjectsListAccountingCache: if co[0][3] == 'Hourly': if now.minute >= 10: diff --git a/ResourceStatusSystem/Agent/RSInspectorAgent.py b/ResourceStatusSystem/Agent/RSInspectorAgent.py index 6258f24a150..adbf8c35b9d 100644 --- a/ResourceStatusSystem/Agent/RSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/RSInspectorAgent.py @@ -36,9 +36,9 @@ def initialize( self ): try: self.rsClient = ResourceStatusClient() - self.ResourcesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ResourcesFreqs' ) - self.ResourcesToBeChecked = Queue.Queue() - self.ResourceNamesInCheck = [] + self.resourcesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ResourcesFreqs' ) + self.resourcesToBeChecked = Queue.Queue() + self.resourceNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -57,9 +57,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -70,7 +67,7 @@ def execute( self ): 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Resource', self.ResourcesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Resource', self.resourcesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -80,40 +77,43 @@ def execute( self ): for resourceTuple in resQuery: - if ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) in self.ResourceNamesInCheck: + if ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) in self.resourceNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) continue resourceL = [ 'Resource' ] + resourceTuple - self.ResourceNamesInCheck.insert( 0, ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) - self.ResourcesToBeChecked.put( resourceL ) + self.resourceNamesInCheck.insert( 0, ( resourceTuple[ 0 ], resourceTuple[ 1 ] ) ) + self.resourcesToBeChecked.put( resourceL ) return S_OK() except Exception, x: errorStr = where( self, self.execute ) - self.log.exception( errorStr,lException=x ) + self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.ResourceNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.resourceNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.ResourceNamesInCheck ) + _msg = _msg % len( self.resourceNamesInCheck ) self.log.info( _msg ) - while self.ResourceNamesInCheck: + while self.resourceNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -122,7 +122,7 @@ def _executeCheck( self, _arg ): while True: - toBeChecked = self.ResourcesToBeChecked.get() + toBeChecked = self.resourcesToBeChecked.get() pepDict = { 'granularity' : toBeChecked[ 0 ], 'name' : toBeChecked[ 1 ], @@ -135,24 +135,24 @@ def _executeCheck( self, _arg ): try: - gLogger.info( "Checking Resource %s, with type/status: %s/%s" % \ + self.log.info( "Checking Resource %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) pepRes = pep.enforce( **pepDict ) if pepRes.has_key( 'PolicyCombinedResult' ) and pepRes[ 'PolicyCombinedResult' ].has_key( 'Status' ): pepStatus = pepRes[ 'PolicyCombinedResult' ][ 'Status' ] if pepStatus != pepDict[ 'status' ]: - gLogger.info( 'Updated Site %s (%s) from %s to %s' % + self.log.info( 'Updated Site %s (%s) from %s to %s' % ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.ResourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.resourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( "RSInspector._executeCheck Checking Resource %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) try: - self.ResourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.resourceNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/SSInspectorAgent.py b/ResourceStatusSystem/Agent/SSInspectorAgent.py index e97c1083512..2d9b59c698f 100644 --- a/ResourceStatusSystem/Agent/SSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SSInspectorAgent.py @@ -5,7 +5,8 @@ ''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule @@ -20,7 +21,7 @@ AGENT_NAME = 'ResourceStatus/SSInspectorAgent' class SSInspectorAgent( AgentModule ): - """ + ''' The SSInspector agent ( SiteInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -29,15 +30,15 @@ class SSInspectorAgent( AgentModule ): If you want to know more about the SSInspectorAgent, scroll down to the end of the file. - """ + ''' def initialize( self ): try: self.rsClient = ResourceStatusClient() - self.SitesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/SitesFreqs' ) - self.SitesToBeChecked = Queue.Queue() - self.SiteNamesInCheck = [] + self.sitesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/SitesFreqs' ) + self.sitesToBeChecked = Queue.Queue() + self.siteNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -56,9 +57,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -68,7 +66,7 @@ def execute( self ): 'FormerStatus', 'SiteType', 'TokenOwner'] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Site', self.SitesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Site', self.sitesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -78,14 +76,14 @@ def execute( self ): for siteTuple in resQuery: - if ( siteTuple[ 0 ],siteTuple[ 1 ] ) in self.SiteNamesInCheck: + if ( siteTuple[ 0 ], siteTuple[ 1 ] ) in self.siteNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( siteTuple[ 0 ],siteTuple[ 1 ] ) ) continue resourceL = [ 'Site' ] + siteTuple - self.SiteNamesInCheck.insert( 0, ( siteTuple[ 0 ], siteTuple[ 1 ] ) ) - self.SitesToBeChecked.put( resourceL ) + self.siteNamesInCheck.insert( 0, ( siteTuple[ 0 ], siteTuple[ 1 ] ) ) + self.sitesToBeChecked.put( resourceL ) return S_OK() @@ -94,24 +92,27 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.SiteNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.siteNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.SiteNamesInCheck ) + _msg = _msg % len( self.siteNamesInCheck ) self.log.info( _msg ) - while self.SiteNamesInCheck: + while self.siteNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient', 'GGUSTicketsClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -143,13 +144,13 @@ def _executeCheck( self, _arg ): ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.SiteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.siteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( "SSInspector._executeCheck Checking Site %s, with type/status: %s/%s" % \ ( pepDict['name'], pepDict['statusType'], pepDict['status'] ) ) try: - self.SiteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.siteNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/SeSInspectorAgent.py b/ResourceStatusSystem/Agent/SeSInspectorAgent.py index 8383d8f9b35..333b2a5fbb9 100644 --- a/ResourceStatusSystem/Agent/SeSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SeSInspectorAgent.py @@ -5,7 +5,8 @@ ''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule @@ -20,7 +21,7 @@ AGENT_NAME = 'ResourceStatus/SeSInspectorAgent' class SeSInspectorAgent( AgentModule ): - """ + ''' The SeSInspector agent ( ServiceInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -29,13 +30,13 @@ class SeSInspectorAgent( AgentModule ): If you want to know more about the SeSInspectorAgent, scroll down to the end of the file. - """ + ''' def initialize( self ): try: self.rsClient = ResourceStatusClient() - self.ServicesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ServicesFreqs' ) + self.servicesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ServicesFreqs' ) self.queue = Queue.Queue() self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) @@ -55,9 +56,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -68,7 +66,7 @@ def execute( self ): 'ServiceType', 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'Service', self.ServicesFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'Service', self.servicesFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -76,8 +74,8 @@ def execute( self ): resQuery = resQuery[ 'Value' ] self.log.info( 'Found %d candidates to be checked.' % len( resQuery ) ) - for r in resQuery: - resourceL = [ 'Service' ] + r + for service in resQuery: + resourceL = [ 'Service' ] + service # Here we peek INSIDE the Queue to know if the item is already # here. It's ok _here_ since (i.e. I know what I'm doing): # - It is a read only operation. @@ -92,10 +90,11 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' if not self.queue.empty(): self.log.info( "Wait for queue to get empty before terminating the agent" ) while not self.queue.empty(): @@ -103,11 +102,13 @@ def finalize( self ): self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck(self): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) diff --git a/ResourceStatusSystem/Agent/StElInspectorAgent.py b/ResourceStatusSystem/Agent/StElInspectorAgent.py index 9d1c7dbc390..18240625040 100644 --- a/ResourceStatusSystem/Agent/StElInspectorAgent.py +++ b/ResourceStatusSystem/Agent/StElInspectorAgent.py @@ -5,7 +5,8 @@ ''' -import Queue, time +import Queue +import time from DIRAC import S_OK, S_ERROR from DIRAC.Core.Base.AgentModule import AgentModule @@ -20,7 +21,7 @@ AGENT_NAME = 'ResourceStatus/StElInspectorAgent' class StElInspectorAgent( AgentModule ): - """ + ''' The StElInspector agent ( StorageElementInspectorAgent ) is one of the four InspectorAgents of the RSS. @@ -29,15 +30,15 @@ class StElInspectorAgent( AgentModule ): If you want to know more about the StElInspectorAgent, scroll down to the end of the file. - """ + ''' def initialize( self ): try: self.rsClient = ResourceStatusClient() - self.StorageElementsFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/StorageElementsFreqs' ) - self.StorageElementsToBeChecked = Queue.Queue() - self.StorageElementsNamesInCheck = [] + self.storageElementsFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/StorageElementsFreqs' ) + self.storageElementsToBeChecked = Queue.Queue() + self.storageElementsNamesInCheck = [] self.maxNumberOfThreads = self.am_getOption( 'maxThreadsInPool', 1 ) self.threadPool = ThreadPool( self.maxNumberOfThreads, @@ -56,9 +57,6 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def execute( self ): try: @@ -69,7 +67,7 @@ def execute( self ): 'TokenOwner' ] kwargs[ 'tokenOwner' ] = 'RS_SVC' - resQuery = self.rsClient.getStuffToCheck( 'StorageElement', self.StorageElementsFreqs, **kwargs ) + resQuery = self.rsClient.getStuffToCheck( 'StorageElement', self.storageElementsFreqs, **kwargs ) if not resQuery[ 'OK' ]: self.log.error( resQuery[ 'Message' ] ) return resQuery @@ -79,15 +77,15 @@ def execute( self ): for seTuple in resQuery: - if ( seTuple[ 0 ], seTuple[ 1 ] ) in self.StorageElementsNamesInCheck: + if ( seTuple[ 0 ], seTuple[ 1 ] ) in self.storageElementsNamesInCheck: self.log.info( '%s(%s) discarded, already on the queue' % ( seTuple[ 0 ], seTuple[ 1 ] ) ) continue resourceL = [ 'StorageElement' ] + seTuple # the tuple consists on ( SEName, SEStatusType ) - self.StorageElementsNamesInCheck.insert( 0, ( resourceL[ 1 ], resourceL[ 2 ] ) ) - self.StorageElementsToBeChecked.put( resourceL ) + self.storageElementsNamesInCheck.insert( 0, ( resourceL[ 1 ], resourceL[ 2 ] ) ) + self.storageElementsToBeChecked.put( resourceL ) return S_OK() @@ -96,24 +94,27 @@ def execute( self ): self.log.exception( errorStr, lException = x ) return S_ERROR( errorStr ) -################################################################################ -################################################################################ - def finalize( self ): - if self.StorageElementsNamesInCheck: + ''' + Method executed at the end of the last cycle. It waits until the queue + is empty. + ''' + if self.storageElementsNamesInCheck: _msg = "Wait for queue to get empty before terminating the agent (%d tasks)" - _msg = _msg % len( self.StorageElementsNamesInCheck ) + _msg = _msg % len( self.storageElementsNamesInCheck ) self.log.info( _msg ) - while self.StorageElementsNamesInCheck: + while self.storageElementsNamesInCheck: time.sleep( 2 ) self.log.info( "Queue is empty, terminating the agent..." ) return S_OK() -################################################################################ ################################################################################ def _executeCheck( self, _arg ): - + ''' + Method executed by the threads in the pool. Picks one element from the + common queue, and enforces policies on that element. + ''' # Init the APIs beforehand, and reuse them. __APIs__ = [ 'ResourceStatusClient', 'ResourceManagementClient' ] clients = knownAPIs.initAPIs( __APIs__, {} ) @@ -122,7 +123,7 @@ def _executeCheck( self, _arg ): while True: - toBeChecked = self.StorageElementsToBeChecked.get() + toBeChecked = self.storageElementsToBeChecked.get() pepDict = { 'granularity' : toBeChecked[ 0 ], 'name' : toBeChecked[ 1 ], @@ -141,16 +142,16 @@ def _executeCheck( self, _arg ): if pepRes.has_key( 'PolicyCombinedResult' ) and pepRes[ 'PolicyCombinedResult' ].has_key( 'Status' ): pepStatus = pepRes[ 'PolicyCombinedResult' ][ 'Status' ] if pepStatus != pepDict[ 'status' ]: - gLogger.info( 'Updated Site %s (%s) from %s to %s' % + self.log.info( 'Updated Site %s (%s) from %s to %s' % ( pepDict['name'], pepDict['statusType'], pepDict['status'], pepStatus )) # remove from InCheck list - self.StorageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.storageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except Exception: self.log.exception( 'StElInspector._executeCheck' ) try: - self.StorageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) + self.storageElementsNamesInCheck.remove( ( pepDict[ 'name' ], pepDict[ 'statusType' ] ) ) except IndexError: pass diff --git a/ResourceStatusSystem/Agent/TokenAgent.py b/ResourceStatusSystem/Agent/TokenAgent.py index 43a63c08b79..b330f5c294d 100644 --- a/ResourceStatusSystem/Agent/TokenAgent.py +++ b/ResourceStatusSystem/Agent/TokenAgent.py @@ -19,15 +19,15 @@ AGENT_NAME = 'ResourceStatus/TokenAgent' class TokenAgent( AgentModule ): - """ + ''' TokenAgent is in charge of checking tokens assigned on resources. Notifications are sent to those users owning expiring tokens. - """ + ''' def initialize( self ): - """ + ''' TokenAgent initialization - """ + ''' # Why only Site and StorageElement ?? # self.ELEMENTS = [ 'Site', 'StorageElement' ] @@ -36,7 +36,7 @@ def initialize( self ): try: self.rsClient = ResourceStatusClient() self.rmClient = ResourceManagementClient() - self.nc = NotificationClient() + self.noClient = NotificationClient() return S_OK() except Exception: @@ -44,14 +44,12 @@ def initialize( self ): self.log.exception( errorStr ) return S_ERROR( errorStr ) -################################################################################ - def execute( self ): - """ - The main TokenAgent execution method. - Checks for tokens owned by users that are expiring, and notifies those users. - Calls rsClient.setToken() to set 'RS_SVC' as owner for those tokens that expired. - """ + ''' + The main TokenAgent execution method. + Checks for tokens owned by users that are expiring, and notifies those users. + Calls rsClient.setToken() to set 'RS_SVC' as owner for those tokens that expired. + ''' adminMail = '' @@ -62,12 +60,13 @@ def execute( self ): #reAssign the token to RS_SVC #for g in self.ELEMENTS: - for g in ValidRes: - tokensExpired = self.rsClient.getTokens( g, tokenExpiration = datetime.datetime.utcnow() ) + for granularity in ValidRes: + tokensExpired = self.rsClient.getTokens( granularity, + tokenExpiration = datetime.datetime.utcnow() ) if tokensExpired[ 'Value' ]: - adminMail += '\nLIST OF EXPIRED %s TOKENS\n' % g - adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20),'name'.ljust(15),'status type') + adminMail += '\nLIST OF EXPIRED %s TOKENS\n' % granularity + adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20), 'name'.ljust(15), 'status type') for token in tokensExpired[ 'Value' ]: @@ -75,18 +74,19 @@ def execute( self ): stype = token[ 2 ] user = token[ 9 ] - self.rsClient.setToken( g, name, stype, reason, 'RS_SVC', datetime.datetime( 9999, 12, 31, 23, 59, 59 ) ) + self.rsClient.setToken( granularity, name, stype, reason, 'RS_SVC', + datetime.datetime( 9999, 12, 31, 23, 59, 59 ) ) adminMail += ' %s %s %s\n' %( user.ljust(20), name.ljust(15), stype ) #notify token owners inNHours = datetime.datetime.utcnow() + datetime.timedelta( hours = self.notifyHours ) #for g in self.ELEMENTS: - for g in ValidRes: + for granularity in ValidRes: - tokensExpiring = self.rsClient.getTokens( g, tokenExpiration = inNHours ) + tokensExpiring = self.rsClient.getTokens( granularity, tokenExpiration = inNHours ) if tokensExpiring[ 'Value' ]: - adminMail += '\nLIST OF EXPIRING %s TOKENS\n' % g + adminMail += '\nLIST OF EXPIRING %s TOKENS\n' % granularity adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20),'name'.ljust(15),'status type') for token in tokensExpiring[ 'Value' ]: @@ -102,7 +102,7 @@ def execute( self ): if user == 'RS_SVC': continue - pdp = PDP( granularity = g, name = name, statusType = stype ) + pdp = PDP( granularity = granularity, name = name, statusType = stype ) decision = pdp.takeDecision() pcresult = decision[ 'PolicyCombinedResult' ] @@ -110,7 +110,7 @@ def execute( self ): expiration = token[ 2 ] - mailMessage = "The token for %s %s %s" % ( g, name, stype ) + mailMessage = "The token for %s %s %s" % ( granularity, name, stype ) mailMessage = mailMessage + "will expire on %s\n\n" % expiration mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n" mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource.\n\n" @@ -127,11 +127,11 @@ def execute( self ): mailMessage += policyMessage adminMail += policyMessage - self.nc.sendMail( self.rmClient.getUserRegistryCache( user )[ 2 ], + self.noClient.sendMail( self.rmClient.getUserRegistryCache( user )[ 2 ], 'Token for %s is expiring' % name, mailMessage ) if adminMail != '': #FIXME: 'ubeda' is not generic ;p - self.nc.sendMail( self.rmClient.getUserRegistryCache( 'ubeda' )[ 2 ], + self.noClient.sendMail( self.rmClient.getUserRegistryCache( 'ubeda' )[ 2 ], "Token's summary", adminMail ) return S_OK() From 886b35a939811acaec3ec0a658332f0f45dc206e Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 16:59:49 +0100 Subject: [PATCH 25/33] pyLint changes ( disable initialized members in initialize ) --- ResourceStatusSystem/Agent/CacheCleanerAgent.py | 2 ++ ResourceStatusSystem/Agent/CacheFeederAgent.py | 2 ++ ResourceStatusSystem/Agent/RSInspectorAgent.py | 2 ++ ResourceStatusSystem/Agent/SSInspectorAgent.py | 2 ++ ResourceStatusSystem/Agent/SeSInspectorAgent.py | 2 ++ ResourceStatusSystem/Agent/StElInspectorAgent.py | 2 ++ ResourceStatusSystem/Agent/TokenAgent.py | 3 +-- 7 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ResourceStatusSystem/Agent/CacheCleanerAgent.py b/ResourceStatusSystem/Agent/CacheCleanerAgent.py index 22073551f32..c3d55fdbd9a 100644 --- a/ResourceStatusSystem/Agent/CacheCleanerAgent.py +++ b/ResourceStatusSystem/Agent/CacheCleanerAgent.py @@ -37,6 +37,8 @@ class CacheCleanerAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() diff --git a/ResourceStatusSystem/Agent/CacheFeederAgent.py b/ResourceStatusSystem/Agent/CacheFeederAgent.py index f0440d1797e..9d917fc5328 100644 --- a/ResourceStatusSystem/Agent/CacheFeederAgent.py +++ b/ResourceStatusSystem/Agent/CacheFeederAgent.py @@ -26,6 +26,8 @@ class CacheFeederAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rmClient = ResourceManagementClient() diff --git a/ResourceStatusSystem/Agent/RSInspectorAgent.py b/ResourceStatusSystem/Agent/RSInspectorAgent.py index adbf8c35b9d..d3508583f18 100644 --- a/ResourceStatusSystem/Agent/RSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/RSInspectorAgent.py @@ -34,6 +34,8 @@ class RSInspectorAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() self.resourcesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ResourcesFreqs' ) diff --git a/ResourceStatusSystem/Agent/SSInspectorAgent.py b/ResourceStatusSystem/Agent/SSInspectorAgent.py index 2d9b59c698f..cc2c91cc97d 100644 --- a/ResourceStatusSystem/Agent/SSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SSInspectorAgent.py @@ -34,6 +34,8 @@ class SSInspectorAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() self.sitesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/SitesFreqs' ) diff --git a/ResourceStatusSystem/Agent/SeSInspectorAgent.py b/ResourceStatusSystem/Agent/SeSInspectorAgent.py index 333b2a5fbb9..90bf2b66cd5 100644 --- a/ResourceStatusSystem/Agent/SeSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SeSInspectorAgent.py @@ -34,6 +34,8 @@ class SeSInspectorAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() self.servicesFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/ServicesFreqs' ) diff --git a/ResourceStatusSystem/Agent/StElInspectorAgent.py b/ResourceStatusSystem/Agent/StElInspectorAgent.py index 18240625040..4a8a424d7d5 100644 --- a/ResourceStatusSystem/Agent/StElInspectorAgent.py +++ b/ResourceStatusSystem/Agent/StElInspectorAgent.py @@ -34,6 +34,8 @@ class StElInspectorAgent( AgentModule ): def initialize( self ): + # pylint: disable-msg=W0201 + try: self.rsClient = ResourceStatusClient() self.storageElementsFreqs = CS.getTypedDictRootedAt( 'CheckingFreqs/StorageElementsFreqs' ) diff --git a/ResourceStatusSystem/Agent/TokenAgent.py b/ResourceStatusSystem/Agent/TokenAgent.py index b330f5c294d..3f6f4609d52 100644 --- a/ResourceStatusSystem/Agent/TokenAgent.py +++ b/ResourceStatusSystem/Agent/TokenAgent.py @@ -28,9 +28,8 @@ def initialize( self ): ''' TokenAgent initialization ''' + # pylint: disable-msg=W0201 - # Why only Site and StorageElement ?? - # self.ELEMENTS = [ 'Site', 'StorageElement' ] self.notifyHours = self.am_getOption( 'notifyHours', 10 ) try: From a7da486d529cd809d644a8872cec488eacdccc0c Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 17:08:34 +0100 Subject: [PATCH 26/33] pyLint changes ( disabled R0904 ) --- ResourceStatusSystem/Agent/CacheCleanerAgent.py | 4 ++++ ResourceStatusSystem/Agent/CacheFeederAgent.py | 4 ++++ ResourceStatusSystem/Agent/RSInspectorAgent.py | 4 ++++ ResourceStatusSystem/Agent/SSInspectorAgent.py | 4 ++++ ResourceStatusSystem/Agent/SeSInspectorAgent.py | 4 ++++ ResourceStatusSystem/Agent/StElInspectorAgent.py | 4 ++++ ResourceStatusSystem/Agent/TokenAgent.py | 5 +++++ 7 files changed, 29 insertions(+) diff --git a/ResourceStatusSystem/Agent/CacheCleanerAgent.py b/ResourceStatusSystem/Agent/CacheCleanerAgent.py index c3d55fdbd9a..1e252770981 100644 --- a/ResourceStatusSystem/Agent/CacheCleanerAgent.py +++ b/ResourceStatusSystem/Agent/CacheCleanerAgent.py @@ -34,9 +34,13 @@ class CacheCleanerAgent( AgentModule ): If you want to know more about the CacheCleanerAgent, scroll down to the end of the file. ''' + + # Too many public methods + # pylint: disable-msg=R0904 def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/CacheFeederAgent.py b/ResourceStatusSystem/Agent/CacheFeederAgent.py index 9d917fc5328..ee1731b701f 100644 --- a/ResourceStatusSystem/Agent/CacheFeederAgent.py +++ b/ResourceStatusSystem/Agent/CacheFeederAgent.py @@ -24,8 +24,12 @@ class CacheFeederAgent( AgentModule ): tables. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/RSInspectorAgent.py b/ResourceStatusSystem/Agent/RSInspectorAgent.py index d3508583f18..69263f05f5e 100644 --- a/ResourceStatusSystem/Agent/RSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/RSInspectorAgent.py @@ -32,8 +32,12 @@ class RSInspectorAgent( AgentModule ): end of the file. """ + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/SSInspectorAgent.py b/ResourceStatusSystem/Agent/SSInspectorAgent.py index cc2c91cc97d..53a627cc404 100644 --- a/ResourceStatusSystem/Agent/SSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SSInspectorAgent.py @@ -32,8 +32,12 @@ class SSInspectorAgent( AgentModule ): end of the file. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/SeSInspectorAgent.py b/ResourceStatusSystem/Agent/SeSInspectorAgent.py index 90bf2b66cd5..071d79f4f7e 100644 --- a/ResourceStatusSystem/Agent/SeSInspectorAgent.py +++ b/ResourceStatusSystem/Agent/SeSInspectorAgent.py @@ -32,8 +32,12 @@ class SeSInspectorAgent( AgentModule ): end of the file. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/StElInspectorAgent.py b/ResourceStatusSystem/Agent/StElInspectorAgent.py index 4a8a424d7d5..307984cee80 100644 --- a/ResourceStatusSystem/Agent/StElInspectorAgent.py +++ b/ResourceStatusSystem/Agent/StElInspectorAgent.py @@ -32,8 +32,12 @@ class StElInspectorAgent( AgentModule ): end of the file. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): + # Attribute defined outside __init__ # pylint: disable-msg=W0201 try: diff --git a/ResourceStatusSystem/Agent/TokenAgent.py b/ResourceStatusSystem/Agent/TokenAgent.py index 3f6f4609d52..3142dfe9789 100644 --- a/ResourceStatusSystem/Agent/TokenAgent.py +++ b/ResourceStatusSystem/Agent/TokenAgent.py @@ -24,10 +24,15 @@ class TokenAgent( AgentModule ): Notifications are sent to those users owning expiring tokens. ''' + # Too many public methods + # pylint: disable-msg=R0904 + def initialize( self ): ''' TokenAgent initialization ''' + + # Attribute defined outside __init__ # pylint: disable-msg=W0201 self.notifyHours = self.am_getOption( 'notifyHours', 10 ) From 37fcd2e103b394f96bb390286e753b84aac08cdf Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 17:14:00 +0100 Subject: [PATCH 27/33] pyLint changes ( add disable code explanation ) --- .../Client/ResourceManagementClient.py | 31 +++++++++- .../Client/ResourceStatusClient.py | 56 ++++++++++++++++--- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index c5b1ea3d9ca..220ef2f7537 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -104,6 +104,7 @@ def insertEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'EnvironmentCache', locals() ) def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): @@ -124,6 +125,7 @@ def updateEnvironmentCache( self, hashEnv, siteName, environment, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'EnvironmentCache', locals() ) def getEnvironmentCache( self, hashEnv = None, siteName = None, @@ -144,6 +146,7 @@ def getEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'EnvironmentCache', locals() ) def deleteEnvironmentCache( self, hashEnv = None, siteName = None, @@ -164,6 +167,7 @@ def deleteEnvironmentCache( self, hashEnv = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'EnvironmentCache', locals() ) @@ -201,6 +205,7 @@ def insertPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'PolicyResult', locals() ) def updatePolicyResult( self, granularity, name, policyName, statusType, @@ -235,6 +240,7 @@ def updatePolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'PolicyResult', locals() ) def getPolicyResult( self, granularity = None, name = None, policyName = None, @@ -268,6 +274,7 @@ def getPolicyResult( self, granularity = None, name = None, policyName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'PolicyResult', locals() ) def deletePolicyResult( self, granularity = None, name = None, @@ -302,6 +309,7 @@ def deletePolicyResult( self, granularity = None, name = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'PolicyResult', locals() ) @@ -333,7 +341,8 @@ def insertClientCache( self, name, commandName, opt_ID, value, result, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'ClientCache', locals() ) def updateClientCache( self, name, commandName, opt_ID, value, result, @@ -362,7 +371,8 @@ def updateClientCache( self, name, commandName, opt_ID, value, result, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'ClientCache', locals() ) def getClientCache( self, name = None, commandName = None, opt_ID = None, @@ -392,6 +402,7 @@ def getClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ClientCache', locals() ) def deleteClientCache( self, name = None, commandName = None, opt_ID = None, @@ -421,6 +432,7 @@ def deleteClientCache( self, name = None, commandName = None, opt_ID = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'ClientCache', locals() ) @@ -451,6 +463,7 @@ def insertAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'AccountingCache', locals() ) def updateAccountingCache( self, name, plotType, plotName, result, @@ -478,6 +491,7 @@ def updateAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'AccountingCache', locals() ) def getAccountingCache( self, name = None, plotType = None, plotName = None, @@ -505,6 +519,7 @@ def getAccountingCache( self, name = None, plotType = None, plotName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'AccountingCache', locals() ) def deleteAccountingCache( self, name = None, plotType = None, @@ -533,6 +548,7 @@ def deleteAccountingCache( self, name = None, plotType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'AccountingCache', locals() ) @@ -555,7 +571,8 @@ def insertUserRegistryCache( self, login, name, email, meta = None ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'UserRegistryCache', locals() ) def updateUserRegistryCache( self, login, name, email, meta = None ): @@ -576,6 +593,7 @@ def updateUserRegistryCache( self, login, name, email, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'UserRegistryCache', locals() ) def getUserRegistryCache( self, login = None, name = None, email = None, @@ -596,6 +614,7 @@ def getUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'UserRegistryCache', locals() ) def deleteUserRegistryCache( self, login = None, name = None, email = None, @@ -616,6 +635,7 @@ def deleteUserRegistryCache( self, login = None, name = None, email = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'UserRegistryCache', locals() ) @@ -640,6 +660,7 @@ def addOrModifyEnvironmentCache( self, hashEnv, siteName, environment ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'EnvironmentCache', locals() ) def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, @@ -673,6 +694,7 @@ def addOrModifyPolicyResult( self, granularity, name, policyName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'PolicyResult', locals() ) def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, @@ -702,6 +724,7 @@ def addOrModifyClientCache( self, name, commandName, opt_ID, value, result, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'ClientCache', locals() ) def addOrModifyAccountingCache( self, name, plotType, plotName, result, @@ -729,6 +752,7 @@ def addOrModifyAccountingCache( self, name, plotType, plotName, result, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'AccountingCache', locals() ) def addOrModifyUserRegistryCache( self, login, name, email ): @@ -749,6 +773,7 @@ def addOrModifyUserRegistryCache( self, login, name, email ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'UserRegistryCache', locals() ) diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 514d544a65d..fd8b7e3e0cd 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -114,6 +114,7 @@ def insertSite( self, siteName, siteType, gridSiteName, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'Site', locals() ) def updateSite( self, siteName, siteType, gridSiteName, meta = None ): @@ -134,7 +135,8 @@ def updateSite( self, siteName, siteType, gridSiteName, meta = None ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'Site', locals() ) def getSite( self, siteName = None, siteType = None, gridSiteName = None, @@ -156,6 +158,7 @@ def getSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'Site', locals() ) def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, @@ -177,6 +180,7 @@ def deleteSite( self, siteName = None, siteType = None, gridSiteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'Site', locals() ) def getSitePresent( self, siteName = None, siteType = None, @@ -219,7 +223,8 @@ def getSitePresent( self, siteName = None, siteType = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'SitePresent', locals() ) @@ -244,6 +249,7 @@ def insertService( self, serviceName, serviceType, siteName, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'Service', locals() ) def updateService( self, serviceName, serviceType, siteName, meta = None ): @@ -265,6 +271,7 @@ def updateService( self, serviceName, serviceType, siteName, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'Service', locals() ) def getService( self, serviceName = None, serviceType = None, siteName = None, @@ -286,6 +293,7 @@ def getService( self, serviceName = None, serviceType = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'Service', locals() ) def deleteService( self, serviceName = None, serviceType = None, @@ -307,6 +315,7 @@ def deleteService( self, serviceName = None, serviceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'Service', locals() ) def getServicePresent( self, serviceName = None, siteName = None, @@ -352,6 +361,7 @@ def getServicePresent( self, serviceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ServicePresent', locals() ) @@ -381,6 +391,7 @@ def insertResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'Resource', locals() ) def updateResource( self, resourceName, resourceType, serviceType, siteName, @@ -407,6 +418,7 @@ def updateResource( self, resourceName, resourceType, serviceType, siteName, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'Resource', locals() ) def getResource( self, resourceName = None, resourceType = None, @@ -433,6 +445,7 @@ def getResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'Resource', locals() ) def deleteResource( self, resourceName = None, resourceType = None, @@ -459,6 +472,7 @@ def deleteResource( self, resourceName = None, resourceType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'Resource', locals() ) def getResourcePresent( self, resourceName = None, siteName = None, @@ -511,6 +525,7 @@ def getResourcePresent( self, resourceName = None, siteName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ResourcePresent', locals() ) @@ -535,6 +550,7 @@ def insertStorageElement( self, storageElementName, resourceName, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'StorageElement', locals() ) def updateStorageElement( self, storageElementName, resourceName, @@ -556,6 +572,7 @@ def updateStorageElement( self, storageElementName, resourceName, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'StorageElement', locals() ) def getStorageElement( self, storageElementName = None, resourceName = None, @@ -576,6 +593,7 @@ def getStorageElement( self, storageElementName = None, resourceName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElement', locals() ) def deleteStorageElement( self, storageElementName = None, @@ -597,6 +615,7 @@ def deleteStorageElement( self, storageElementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'StorageElement', locals() ) def getStorageElementPresent( self, storageElementName = None, @@ -642,7 +661,8 @@ def getStorageElementPresent( self, storageElementName = None, `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'StorageElementPresent', locals() ) @@ -663,7 +683,8 @@ def insertGridSite( self, gridSiteName, gridTier, meta = None ): `table` key and the proper table name. :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'GridSite', locals() ) def updateGridSite( self, gridSiteName, gridTier, meta = None ): @@ -682,6 +703,7 @@ def updateGridSite( self, gridSiteName, gridTier, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'GridSite', locals() ) def getGridSite( self, gridSiteName = None, gridTier = None, meta = None ): @@ -699,6 +721,7 @@ def getGridSite( self, gridSiteName = None, gridTier = None, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'GridSite', locals() ) def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = None ): @@ -716,6 +739,7 @@ def deleteGridSite( self, gridSiteName = None, gridTier = None, meta = None ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'GridSite', locals() ) @@ -760,6 +784,7 @@ def insertElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementStatus', locals() ) def updateElementStatus( self, element, elementName, statusType, status, @@ -801,6 +826,7 @@ def updateElementStatus( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementStatus', locals() ) def getElementStatus( self, element, elementName = None, statusType = None, @@ -842,6 +868,7 @@ def getElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementStatus', locals() ) def deleteElementStatus( self, element, elementName = None, statusType = None, @@ -883,6 +910,7 @@ def deleteElementStatus( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementStatus', locals() ) @@ -927,6 +955,7 @@ def insertElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementScheduledStatus', locals() ) def updateElementScheduledStatus( self, element, elementName, statusType, @@ -969,6 +998,7 @@ def updateElementScheduledStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementScheduledStatus', locals() ) def getElementScheduledStatus( self, element, elementName = None, @@ -1011,6 +1041,7 @@ def getElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementScheduledStatus', locals() ) def deleteElementScheduledStatus( self, element, elementName = None, @@ -1054,6 +1085,7 @@ def deleteElementScheduledStatus( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementScheduledStatus', locals() ) @@ -1098,6 +1130,7 @@ def insertElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'insert', 'ElementHistory', locals() ) def updateElementHistory( self, element, elementName, statusType, status, @@ -1140,6 +1173,7 @@ def updateElementHistory( self, element, elementName, statusType, status, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'update', 'ElementHistory', locals() ) def getElementHistory( self, element, elementName = None, statusType = None, @@ -1181,6 +1215,7 @@ def getElementHistory( self, element, elementName = None, statusType = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'get', 'ElementHistory', locals() ) def deleteElementHistory( self, element, elementName = None, @@ -1223,6 +1258,7 @@ def deleteElementHistory( self, element, elementName = None, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__query( 'delete', 'ElementHistory', locals() ) @@ -1304,6 +1340,7 @@ def addOrModifySite( self, siteName, siteType, gridSiteName ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Site', locals() ) @@ -1323,6 +1360,7 @@ def addOrModifyService( self, serviceName, serviceType, siteName ): :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Service', locals() ) @@ -1346,7 +1384,8 @@ def addOrModifyResource( self, resourceName, resourceType, serviceType, name of the grid site the resource belongs ( if any ) :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'Resource', locals() ) @@ -1365,7 +1404,8 @@ def addOrModifyStorageElement( self, storageElementName, resourceName, name of the grid site the storage element belongs :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__addOrModifyElement( 'StorageElement', locals() ) @@ -1432,6 +1472,7 @@ def modifyElementStatus( self, element, elementName, statusType, :return: S_OK() || S_ERROR() ''' + # Unused argument # pylint: disable-msg=W0613 return self.__modifyElementStatus( locals() ) @@ -1448,7 +1489,8 @@ def removeElement( self, element, elementName ): name of the individual of class element :return: S_OK() || S_ERROR() - ''' + ''' + # Unused argument # pylint: disable-msg=W0613 return self.__removeElement( element, elementName ) From b22f91c394280e35bb13fd835fd3b5a13b505d28 Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 17:51:06 +0100 Subject: [PATCH 28/33] pyLint changes ( unused variables, docstring, renaming ) --- ResourceStatusSystem/PolicySystem/PDP.py | 210 ++++++++++-------- ResourceStatusSystem/PolicySystem/PEP.py | 47 ++-- .../PolicySystem/PolicyBase.py | 63 +++--- .../PolicySystem/PolicyCaller.py | 67 ++++-- ResourceStatusSystem/PolicySystem/Status.py | 35 +-- 5 files changed, 231 insertions(+), 191 deletions(-) diff --git a/ResourceStatusSystem/PolicySystem/PDP.py b/ResourceStatusSystem/PolicySystem/PDP.py index 06520d6ecac..5d3589d3f2b 100644 --- a/ResourceStatusSystem/PolicySystem/PDP.py +++ b/ResourceStatusSystem/PolicySystem/PDP.py @@ -22,10 +22,26 @@ class PDP: """ def __init__( self, **clients ): - - cc = CommandCaller() - self.clients = clients - self.pc = PolicyCaller( cc, **clients ) + ''' + Constructor. Defines members that will be used later on. + ''' + + cc = CommandCaller() + self.clients = clients + self.pCaller = PolicyCaller( cc, **clients ) + self.iGetter = InfoGetter() + + self.__granularity = None + self.__name = None + self.__statusType = None + self.__status = None + self.__formerStatus = None + self.__reason = None + self.__siteType = None + self.__serviceType = None + self.__resourceType = None + self.__useNewRes = None + def setup( self, granularity = None, name = None, statusType = None, status = None, formerStatus = None, reason = None, siteType = None, @@ -55,14 +71,11 @@ def setup( self, granularity = None, name = None, statusType = None, self.__resourceType = resourceType self.__useNewRes = useNewRes - self.args = None - self.policy = None - self.knownInfo = None - self.ig = None + ################################################################################ - def takeDecision(self, policyIn=None, argsIn=None, knownInfo=None): + def takeDecision( self, policyIn = None, argsIn = None, knownInfo = None ): """ PDP MAIN FUNCTION decides policies that have to be applied, based on @@ -91,96 +104,97 @@ def takeDecision(self, policyIn=None, argsIn=None, knownInfo=None): 'EndDate: datetime.datetime (in a string)} """ - self.args = argsIn - self.policy = policyIn - self.knownInfo = knownInfo - - self.ig = InfoGetter() - - EVAL = self.ig.getInfoToApply(('policy', 'policyType'), - granularity = self.__granularity, - statusType = self.__statusType, - status = self.__status, - formerStatus = self.__formerStatus, - siteType = self.__siteType, - serviceType = self.__serviceType, - resourceType = self.__resourceType, - useNewRes = self.__useNewRes) + polToEval = self.iGetter.getInfoToApply( ( 'policy', 'policyType' ), + granularity = self.__granularity, + statusType = self.__statusType, + status = self.__status, + formerStatus = self.__formerStatus, + siteType = self.__siteType, + serviceType = self.__serviceType, + resourceType = self.__resourceType, + useNewRes = self.__useNewRes ) - policyType = EVAL['PolicyType'] # type: generator + policyType = polToEval[ 'PolicyType' ] # type: generator - if self.policy: + if policyIn: # Only the policy provided will be evaluated # FIXME: Check that the policies are valid. - singlePolicyResults = self.policy.evaluate() + singlePolicyResults = policyIn.evaluate() else: - singlePolicyResults = self._invocation(self.__granularity, - self.__name, self.__status, self.policy, - self.args, EVAL['Policies']) + singlePolicyResults = self._invocation( elf.__granularity, + self.__name, self.__status, policyIn, + argsIn, polToEval['Policies'] ) - policyCombinedResults = self._policyCombination(singlePolicyResults) + policyCombinedResults = self._policyCombination( singlePolicyResults ) if policyCombinedResults == {}: - policyCombinedResults["Action"] = False - policyCombinedResults["Reason"] = 'No policy results' - policyCombinedResults["PolicyType"] = policyType + policyCombinedResults[ 'Action' ] = False + policyCombinedResults[ 'Reason' ] = 'No policy results' + policyCombinedResults[ 'PolicyType' ] = policyType - if policyCombinedResults.has_key("Status"): - newstatus = policyCombinedResults['Status'] + if policyCombinedResults.has_key( 'Status' ): + newstatus = policyCombinedResults[ 'Status' ] if newstatus != self.__status: # Policies satisfy - newPolicyType = self.ig.getNewPolicyType(self.__granularity, newstatus) - policyType = set(policyType) & set(newPolicyType) - policyCombinedResults["Action"] = True + newPolicyType = self.iGetter.getNewPolicyType( self.__granularity, newstatus ) + policyType = set( policyType ) & set( newPolicyType ) + + policyCombinedResults[ 'Action' ] = True else: # Policies does not satisfy - policyCombinedResults["Action"] = False + policyCombinedResults[ 'Action' ] = False - policyCombinedResults["PolicyType"] = policyType + policyCombinedResults[ 'PolicyType' ] = policyType return { 'SinglePolicyResults' : singlePolicyResults, 'PolicyCombinedResult' : policyCombinedResults } ################################################################################ - def _invocation(self, granularity, name, status, policy, args, policies): - """ One by one, use the PolicyCaller to invoke the policies, and putting - their results in `policyResults`. When the status is `Unknown`, invokes - `self.__useOldPolicyRes`. Always returns a list, possibly empty. - """ + def _invocation( self, granularity, name, status, policy, args, policies ): + ''' + One by one, use the PolicyCaller to invoke the policies, and putting + their results in `policyResults`. When the status is `Unknown`, invokes + `self.__useOldPolicyRes`. Always returns a list, possibly empty. + ''' policyResults = [] - for p in policies: - pName = p['Name'] - pModule = p['Module'] - extraArgs = p['args'] - commandIn = p['commandIn'] - res = self.pc.policyInvocation(granularity = granularity, name = name, - status = status, policy = policy, args = args, pName = pName, - pModule = pModule, extraArgs = extraArgs, commandIn = commandIn ) + for pol in policies: + + pName = pol[ 'Name' ] + pModule = pol[ 'Module' ] + extraArgs = pol[ 'args' ] + commandIn = pol[ 'commandIn' ] + + res = self.pCaller.policyInvocation( granularity = granularity, name = name, + status = status, policy = policy, + args = args, pName = pName, + pModule = pModule, extraArgs = extraArgs, + commandIn = commandIn ) # If res is empty, return immediately - if not res: return policyResults + if not res: + return policyResults - if not res.has_key('Status'): - print("\n\n Policy result " + str(res) + " does not return 'Status'\n\n") + if not res.has_key( 'Status' ): + print('\n\n Policy result ' + str(res) + ' does not return "Status"\n\n') raise TypeError # Else - if res['Status'] == 'Unknown': - res = self.__useOldPolicyRes(name = name, policyName = pName) + if res[ 'Status' ] == 'Unknown': + res = self.__useOldPolicyRes( name = name, policyName = pName ) - if res['Status'] not in ( 'Error', 'Unknown' ): - policyResults.append(res) + if res[ 'Status' ] not in ( 'Error', 'Unknown' ): + policyResults.append( res ) return policyResults ################################################################################ - def _policyCombination(self, pol_results): - """ + def _policyCombination( self, pol_results ): + ''' INPUT: list type OUTPUT: dict type * Compute a new status, and store it in variable newStatus, of type integer. @@ -188,79 +202,83 @@ def _policyCombination(self, pol_results): * Concatenate the Reason fields * Take the first EndDate field that exists (FIXME: Do something more clever) * Finally, return the result - """ - if pol_results == []: return {} + ''' + if pol_results == []: + return {} - pol_results.sort(key=Status.value_of_policy) + pol_results.sort( key=Status.value_of_policy ) newStatus = -1 # First, set an always invalid status try: # We are in a special status, maybe forbidden transitions - _prio, access_list, gofun = Status.statesInfo[self.__status] + _prio, access_list, gofun = Status.statesInfo[ self.__status ] if access_list != set(): # Restrictions on transitions, checking if one is suitable: for p in pol_results: - if Status.value_of_policy(p) in access_list: - newStatus = Status.value_of_policy(p) + if Status.value_of_policy( p ) in access_list: + newStatus = Status.value_of_policy( p ) break # No status from policies suitable, applying stategy and # returning result. if newStatus == -1: - newStatus = gofun(access_list) - return { 'Status': Status.status_of_value(newStatus), + newStatus = gofun( access_list ) + return { 'Status': Status.status_of_value( newStatus ), 'Reason': 'Status forced by PDP' } else: # Special Status, but no restriction on transitions - newStatus = Status.value_of_policy(pol_results[0]) + newStatus = Status.value_of_policy( pol_results[ 0 ] ) except KeyError: # We are in a "normal" status: All transitions are possible. - newStatus = Status.value_of_policy(pol_results[0]) + newStatus = Status.value_of_policy( pol_results[ 0 ] ) # At this point, a new status has been chosen. newStatus is an # integer. - worstResults = [p for p in pol_results - if Status.value_of_policy(p) == newStatus] + worstResults = [ p for p in pol_results + if Status.value_of_policy( p ) == newStatus ] # Concatenate reasons - def getReason(p): + def getReason( p ): try: - res = p['Reason'] + res = p[ 'Reason' ] except KeyError: res = '' return res - worstResultsReasons = [getReason(p) for p in worstResults] + worstResultsReasons = [ getReason( p ) for p in worstResults ] - def catRes(x, y): + def catRes( x, y ): if x and y : return x + ' |###| ' + y elif x or y: if x: return x else: return y else : return '' - concatenatedRes = reduce(catRes, worstResultsReasons, '') + concatenatedRes = reduce( catRes, worstResultsReasons, '' ) # Handle EndDate - endDatePolicies = [p for p in worstResults if p.has_key('EndDate')] + endDatePolicies = [ p for p in worstResults if p.has_key( 'EndDate' ) ] # Building and returning result res = {} - res['Status'] = Status.status_of_value(newStatus) - if concatenatedRes != '': res['Reason'] = concatenatedRes - if endDatePolicies != []: res['EndDate'] = endDatePolicies[0]['EndDate'] + res[ 'Status' ] = Status.status_of_value( newStatus ) + if concatenatedRes != '': + res[ 'Reason' ] = concatenatedRes + if endDatePolicies != []: + res[ 'EndDate' ] = endDatePolicies[ 0 ][ 'EndDate' ] return res ################################################################################ - def __useOldPolicyRes(self, name, policyName): - """ Use the RSS Service to get an old policy result. - If such result is older than 2 hours, it returns {'Status':'Unknown'} - """ - res = self.clients['ResourceManagementClient'].getPolicyResult( name = name, policyName = policyName ) + def __useOldPolicyRes( self, name, policyName ): + ''' + Use the RSS Service to get an old policy result. + If such result is older than 2 hours, it returns {'Status':'Unknown'} + ''' + res = self.clients[ 'ResourceManagementClient' ].getPolicyResult( name = name, policyName = policyName ) if not res[ 'OK' ]: return { 'Status' : 'Unknown' } @@ -268,22 +286,22 @@ def __useOldPolicyRes(self, name, policyName): res = res[ 'Value' ] if res == []: - return {'Status':'Unknown'} + return { 'Status' : 'Unknown' } res = res[ 0 ] - oldStatus = res[5] - oldReason = res[6] - lastCheckTime = res[8] + oldStatus = res[ 5 ] + oldReason = res[ 6 ] + lastCheckTime = res[ 8 ] if ( lastCheckTime + datetime.timedelta(hours = 2) ) < datetime.datetime.utcnow(): return { 'Status' : 'Unknown' } result = {} - result[ 'Status' ] = oldStatus - result[ 'Reason' ] = oldReason - result[ 'OLD' ] = True + result[ 'Status' ] = oldStatus + result[ 'Reason' ] = oldReason + result[ 'OLD' ] = True result[ 'PolicyName' ] = policyName return result diff --git a/ResourceStatusSystem/PolicySystem/PEP.py b/ResourceStatusSystem/PolicySystem/PEP.py index 4c202471d7b..31fc35338db 100644 --- a/ResourceStatusSystem/PolicySystem/PEP.py +++ b/ResourceStatusSystem/PolicySystem/PEP.py @@ -9,7 +9,7 @@ c. other.... ''' -from DIRAC import S_OK, S_ERROR +from DIRAC import S_ERROR from DIRAC.ResourceStatusSystem import ValidRes, \ ValidStatus, ValidStatusTypes, ValidSiteType, ValidServiceType, ValidResourceType from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient @@ -21,7 +21,7 @@ __RCSID__ = '$Id: $' class PEP: - """ + ''' PEP (Policy Enforcement Point) initialization :params: @@ -40,10 +40,10 @@ class PEP: 'Granularity': a ValidRes (optional) } ] - """ + ''' - def __init__( self, pdp = None, clients = {} ): - """ + def __init__( self, pdp = None, clients = None ): + ''' Enforce policies, using a PDP (Policy Decision Point), based on self.__granularity (optional) @@ -61,23 +61,32 @@ def __init__( self, pdp = None, clients = {} ): :params: :attr:`pdp` : a custom PDP object (optional) :attr:`clients` : a dictionary containing modules corresponding to clients. - """ - try: self.rsClient = clients[ 'ResourceStatusClient' ] - except KeyError: self.rsClient = ResourceStatusClient() - try: self.rmClient = clients[ 'ResourceManagementClient' ] - except KeyError: self.rmClient = ResourceManagementClient() + ''' + + if clients is None: + clients= {} + + try: + self.rsClient = clients[ 'ResourceStatusClient' ] + except KeyError: + self.rsClient = ResourceStatusClient() + try: + self.rmClient = clients[ 'ResourceManagementClient' ] + except KeyError: + self.rmClient = ResourceManagementClient() self.clients = clients if not pdp: self.pdp = PDP( **clients ) -################################################################################ - def enforce( self, granularity = None, name = None, statusType = None, status = None, formerStatus = None, reason = None, siteType = None, serviceType = None, resourceType = None, tokenOwner = None, useNewRes = False, knownInfo = None ): - + ''' + Enforce policies for given set of keyworkds. To be better explained. + ''' + ## real ban flag ######################################################### realBan = False @@ -132,14 +141,14 @@ def enforce( self, granularity = None, name = None, statusType = None, policyType = res[ 'PolicyType' ] if 'Resource_PolType' in policyType: - m = Utils.voimport(actionBaseMod + ".ResourceAction") - m.ResourceAction(granularity, name, statusType, resDecisions, + action = Utils.voimport( '%s.ResourceAction' % actionBaseMod ) + action.ResourceAction(granularity, name, statusType, resDecisions, rsClient=self.rsClient, rmClient=self.rmClient).run() if 'Alarm_PolType' in policyType: - m = Utils.voimport(actionBaseMod + ".AlarmAction") - m.AlarmAction(granularity, name, statusType, resDecisions, + action = Utils.voimport( '%s.AlarmAction' % actionBaseMod ) + action.AlarmAction(granularity, name, statusType, resDecisions, Clients=self.clients, Params={"Granularity" : granularity, "SiteType" : siteType, @@ -147,8 +156,8 @@ def enforce( self, granularity = None, name = None, statusType = None, "ResourceType" : resourceType}).run() if 'RealBan_PolType' in policyType and realBan: - m = Utils.voimport(actionBaseMod + ".RealBanAction") - m.RealBanAction(granularity, name, resDecisions).run() + action = Utils.voimport( '%s.RealBanAction' % actionBaseMod ) + action.RealBanAction(granularity, name, resDecisions).run() return resDecisions diff --git a/ResourceStatusSystem/PolicySystem/PolicyBase.py b/ResourceStatusSystem/PolicySystem/PolicyBase.py index 57c16e6e0ab..add2f15b3e5 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyBase.py +++ b/ResourceStatusSystem/PolicySystem/PolicyBase.py @@ -13,13 +13,16 @@ __RCSID__ = '$Id: $' class PolicyBase( object ): - """ + ''' Base class for all the policies. Do not instantiate directly. To use, you should call at least `setArgs` and, alternatively, `setCommand` or `setCommandName` on the real policy instance. - """ + ''' - def __init__(self): + def __init__( self ): + ''' + Constructor + ''' self.args = None self.command = None self.commandName = None @@ -27,10 +30,8 @@ def __init__(self): self.infoName = None self.result = {} -################################################################################ - - def setArgs(self, argsIn): - """ + def setArgs( self, argsIn ): + ''' Set `self.args`. :params: @@ -39,69 +40,59 @@ def setArgs(self, argsIn): - `args[0]` should be a ValidRes - `args[1]` should be the name of the ValidRes - """ + ''' self.args = argsIn if self.args[0] not in ValidRes: gLogger.error( 'PolicyBase.setArgs got wrong ValidRes' ) -################################################################################ - - def setCommand(self, commandIn = None): - """ + def setCommand( self, commandIn = None ): + ''' Set `self.command`. :params: :attr:`commandIn`: a command object - """ + ''' self.command = commandIn -################################################################################ - - def setCommandName(self, commandNameIn = None): - """ + def setCommandName( self, commandNameIn = None ): + ''' Set `self.commandName`, necessary when a command object is not provided with setCommand. :params: :attr:`commandNameIn`: a tuple containing the command module and class (as strings) - """ + ''' self.commandName = commandNameIn -################################################################################ - - def setKnownInfo(self, knownInfoIn = None): - """ + def setKnownInfo( self, knownInfoIn = None ): + ''' Set `self.knownInfo`. No command will be then invoked. :params: :attr:`knownInfoIn`: a dictionary - """ + ''' self.knownInfo = knownInfoIn -################################################################################ - - def setInfoName(self, infoNameIn = None): - """ + def setInfoName( self, infoNameIn = None ): + ''' Set `self.infoName`. :params: :attr:`infoNameIn`: a string - """ + ''' self.infoName = infoNameIn -################################################################################ - # method to be extended by sub(real) policies - def evaluate(self): - """ + def evaluate( self ): + ''' Before use, call at least `setArgs` and, alternatively, `setCommand` or `setCommandName`. Invoking `super(PolicyCLASS, self).evaluate` will invoke the command (if necessary) as it is provided and returns the results. - """ + ''' if self.knownInfo: result = self.knownInfo @@ -120,12 +111,12 @@ def evaluate(self): if not self.infoName: - result = result['Result'] + result = result[ 'Result' ] else: if self.infoName in result.keys(): - result = result[self.infoName] + result = result[ self.infoName ] else: - gLogger.error( "missing 'infoName' in result" ) + gLogger.error( 'missing "infoName" in result' ) return None return result diff --git a/ResourceStatusSystem/PolicySystem/PolicyCaller.py b/ResourceStatusSystem/PolicySystem/PolicyCaller.py index 9d0e7c9a868..16b94d8823c 100644 --- a/ResourceStatusSystem/PolicySystem/PolicyCaller.py +++ b/ResourceStatusSystem/PolicySystem/PolicyCaller.py @@ -13,8 +13,19 @@ __RCSID__ = '$Id: $' class PolicyCaller: + ''' + PolicyCaller loads policies, sets commands and runs them. + ''' + def __init__( self, commandCallerIn = None, **clients ): - self.cc = commandCallerIn if commandCallerIn != None else CommandCaller() + ''' + Constructor + ''' + + if commandCallerIn is None: + commandCallerIn = CommandCaller() + + self.cCaller = commandCallerIn self.clients = clients ################################################################################ @@ -22,7 +33,7 @@ def __init__( self, commandCallerIn = None, **clients ): def policyInvocation( self, granularity = None, name = None, status = None, policy = None, args = None, pName = None, pModule = None, extraArgs = None, commandIn = None ): - """ + ''' Invokes a policy: 1. If :attr:`policy` is None, import the policy module specified @@ -36,46 +47,54 @@ def policyInvocation( self, granularity = None, name = None, 3. If commandIn is specified (normally it is), use :meth:`DIRAC.ResourceStatusSystem.Command.CommandCaller.CommandCaller.setCommandObject` to get a command object - """ + ''' - p = policy - a = args + if not policy: - if not p: try: - policyModule = Utils.voimport("DIRAC.ResourceStatusSystem.Policy." + pModule) + + policyModule = Utils.voimport( 'DIRAC.ResourceStatusSystem.Policy.%s' % pModule ) + except ImportError: - gLogger.warn("Unable to import a policy module named %s, falling back on AlwaysFalse_Policy." % pModule) - policyModule = __import__("DIRAC.ResourceStatusSystem.Policy.AlwaysFalse_Policy", - globals(), locals(), ['*']) - pModule = "AlwaysFalse_Policy" + _msg = 'Unable to import a policy module named %s, falling back on AlwaysFalse_Policy.' % pModule + gLogger.warn( _msg ) + policyModule = __import__( 'DIRAC.ResourceStatusSystem.Policy.AlwaysFalse_Policy', + globals(), locals(), ['*'] ) + pModule = 'AlwaysFalse_Policy' + try: - p = getattr(policyModule, pModule)() + + policy = getattr( policyModule, pModule )() + except AttributeError as exc: print policyModule, pModule raise exc - if not a: - a = (granularity, name) + if not args: + args = ( granularity, name ) if extraArgs: - a = a + tuple(extraArgs) + args = args + tuple( extraArgs ) if commandIn: - commandIn = self.cc.setCommandObject( commandIn ) + commandIn = self.cCaller.setCommandObject( commandIn ) for clientName, clientInstance in self.clients.items(): - self.cc.setAPI( commandIn, clientName, clientInstance ) + + self.cCaller.setAPI( commandIn, clientName, clientInstance ) - res = self._innerEval(p, a, commandIn = commandIn) + res = self._innerEval( policy, args, commandIn = commandIn ) # Just adding the PolicyName to the result of the evaluation of the policy - res['PolicyName'] = pName + res[ 'PolicyName' ] = pName return res - def _innerEval(self, policy, arguments, commandIn = None): - """Policy evaluation""" - policy.setArgs(arguments) - policy.setCommand(commandIn) + def _innerEval( self, policy, arguments, commandIn = None ): + ''' + Policy evaluation + ''' + + policy.setArgs( arguments ) + policy.setCommand( commandIn ) return policy.evaluate() ################################################################################ -#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF +#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF \ No newline at end of file diff --git a/ResourceStatusSystem/PolicySystem/Status.py b/ResourceStatusSystem/PolicySystem/Status.py index 29c692bd164..467c3f77c9e 100644 --- a/ResourceStatusSystem/PolicySystem/Status.py +++ b/ResourceStatusSystem/PolicySystem/Status.py @@ -18,33 +18,36 @@ 'Active' : (3, set(), id_fun) } -################################################################################ - -def value_of_status(s): - try: - return int(s) +def value_of_status( status ): + ''' + Given an status, returns its index + ''' + try: + return int( status ) except ValueError: try: - return statesInfo[s][0] + return statesInfo[ status ][ 0 ] except KeyError: #Temporary fix, not anymore InvalidStatus exception raising - gLogger.error( 'value_of_status returning -1') + gLogger.error( 'value_of_status returning -1' ) return -1 -################################################################################ - -def value_of_policy(p): - return value_of_status(p['Status']) - -################################################################################ +def value_of_policy( policy ): + ''' + Given a policy, returns its status + ''' + return value_of_status( policy[ 'Status' ] ) -def status_of_value(v): +def status_of_value( value ): + ''' + To be refactored + ''' # Hack: rely on the order of values in ValidStatus try: - return ValidStatus[v] + return ValidStatus[ value ] except IndexError: #Temporary fix, not anymore InvalidStatus exception raising - gLogger.error( 'status_of_value returning -1') + gLogger.error( 'status_of_value returning -1' ) return -1 ################################################################################ From 92462aa7bd2833f9f9b024feaab65ca5d498d59b Mon Sep 17 00:00:00 2001 From: ubeda Date: Mon, 27 Feb 2012 18:02:36 +0100 Subject: [PATCH 29/33] pyLint changes ( variable renaming ) and typos fixes --- ResourceStatusSystem/PolicySystem/PDP.py | 31 +++++++++++++++--------- ResourceStatusSystem/PolicySystem/PEP.py | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ResourceStatusSystem/PolicySystem/PDP.py b/ResourceStatusSystem/PolicySystem/PDP.py index 5d3589d3f2b..cdf812c6396 100644 --- a/ResourceStatusSystem/PolicySystem/PDP.py +++ b/ResourceStatusSystem/PolicySystem/PDP.py @@ -122,7 +122,7 @@ def takeDecision( self, policyIn = None, argsIn = None, knownInfo = None ): singlePolicyResults = policyIn.evaluate() else: - singlePolicyResults = self._invocation( elf.__granularity, + singlePolicyResults = self._invocation( self.__granularity, self.__name, self.__status, policyIn, argsIn, polToEval['Policies'] ) @@ -214,9 +214,9 @@ def _policyCombination( self, pol_results ): _prio, access_list, gofun = Status.statesInfo[ self.__status ] if access_list != set(): # Restrictions on transitions, checking if one is suitable: - for p in pol_results: - if Status.value_of_policy( p ) in access_list: - newStatus = Status.value_of_policy( p ) + for polRes in pol_results: + if Status.value_of_policy( polRes ) in access_list: + newStatus = Status.value_of_policy( polRes ) break # No status from policies suitable, applying stategy and @@ -241,21 +241,28 @@ def _policyCombination( self, pol_results ): if Status.value_of_policy( p ) == newStatus ] # Concatenate reasons - def getReason( p ): + def getReason( pol ): try: - res = p[ 'Reason' ] + res = pol[ 'Reason' ] except KeyError: res = '' return res worstResultsReasons = [ getReason( p ) for p in worstResults ] - def catRes( x, y ): - if x and y : return x + ' |###| ' + y - elif x or y: - if x: return x - else: return y - else : return '' + def catRes( xVal, yVal ): + ''' + Concatenate xVal and yVal. + ''' + if xVal and yVal : + return xVal + ' |###| ' + yVal + elif xVal or yVal: + if xVal: + return xVal + else: + return yVal + else: + return '' concatenatedRes = reduce( catRes, worstResultsReasons, '' ) diff --git a/ResourceStatusSystem/PolicySystem/PEP.py b/ResourceStatusSystem/PolicySystem/PEP.py index 31fc35338db..98186a99acf 100644 --- a/ResourceStatusSystem/PolicySystem/PEP.py +++ b/ResourceStatusSystem/PolicySystem/PEP.py @@ -64,7 +64,7 @@ def __init__( self, pdp = None, clients = None ): ''' if clients is None: - clients= {} + clients = {} try: self.rsClient = clients[ 'ResourceStatusClient' ] From 1f3c0464a7c720c09eddbe295d6c926f8e9c987f Mon Sep 17 00:00:00 2001 From: ubeda Date: Tue, 6 Mar 2012 17:17:30 +0100 Subject: [PATCH 30/33] BUGIX: _checkFloat checks INTEGERS, not datetimes. --- ResourceStatusSystem/Utilities/MySQLMonkey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ResourceStatusSystem/Utilities/MySQLMonkey.py b/ResourceStatusSystem/Utilities/MySQLMonkey.py index 642cda2800e..5a1d98fea05 100644 --- a/ResourceStatusSystem/Utilities/MySQLMonkey.py +++ b/ResourceStatusSystem/Utilities/MySQLMonkey.py @@ -501,7 +501,7 @@ def _checkFLOAT(self, suspicious): if type(i) not in (int, float): raise RSSDBException( 'Non numeric value "%s"' % suspicious ) - return [ '"%s"' % s.replace( microsecond = 0 ) for s in suspicious ] + return suspicious _checkNUMERIC = _checkFLOAT _checkDECIMAL = _checkFLOAT From afb882021d5332755e50630e43ed6c97309d9970 Mon Sep 17 00:00:00 2001 From: ubeda Date: Wed, 7 Mar 2012 09:45:01 +0100 Subject: [PATCH 31/33] FIX: checked 'OK' key on addOrModify --- ResourceStatusSystem/Client/ResourceManagementClient.py | 2 ++ ResourceStatusSystem/Client/ResourceStatusClient.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 868436a26fa..d555c259bc6 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -791,6 +791,8 @@ def __addOrModifyElement( self, element, kwargs ): kwargs[ 'meta' ] = { 'onlyUniqueKeys' : True } sqlQuery = self._getElement( element, kwargs ) + if not sqlQuery[ 'OK' ]: + return sqlQuery del kwargs[ 'meta' ] diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 5147daac180..233e3a8d338 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -2322,7 +2322,9 @@ def __addOrModifyElement( self, element, kwargs ): kwargs[ 'meta' ] = { 'onlyUniqueKeys' : True } sqlQuery = self._getElement( element, kwargs ) - + if not sqlQuery[ 'OK' ]: + return sqlQuery + del kwargs[ 'meta' ] if sqlQuery[ 'Value' ]: @@ -2380,6 +2382,8 @@ def __addOrModifyElementStatus( self, element, rDict ): } sqlQuery = self._getElement( 'ElementStatus', kwargs ) + if not sqlQuery[ 'OK' ]: + return sqlQuery rDict[ 'element' ] = element From 543ccfda9aa3be28b55971d06ab451c9346069b9 Mon Sep 17 00:00:00 2001 From: ubeda Date: Thu, 8 Mar 2012 10:33:27 +0100 Subject: [PATCH 32/33] FIX: Wrong order of bool sentence --- ResourceStatusSystem/Client/ResourceManagementClient.py | 2 +- ResourceStatusSystem/Client/ResourceStatusClient.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 654c4cce6fd..3ed2445a2b1 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -75,7 +75,7 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) # If meta is None, we set it to {} - meta = ( kwargs.pop( 'meta' ) and True ) or {} + meta = ( True and kwargs.pop( 'meta' ) ) or {} params = kwargs del params[ 'self' ] diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index 3962f65f6f5..b73f5c9ae56 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -78,7 +78,7 @@ def __query( self, queryType, tableName, kwargs ): gateFunction = getattr( self.gate, queryType ) # If meta is None, we set it to {} - meta = ( kwargs.pop( 'meta' ) and True ) or {} + meta = ( True and kwargs.pop( 'meta' ) ) or {} params = kwargs del params[ 'self' ] From c6cb38c4c97494745075b56e0daf913707737a35 Mon Sep 17 00:00:00 2001 From: ubeda Date: Thu, 8 Mar 2012 10:37:22 +0100 Subject: [PATCH 33/33] FIX: Moved log level to debug --- ResourceStatusSystem/Client/ResourceManagementClient.py | 2 +- ResourceStatusSystem/Client/ResourceStatusClient.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ResourceStatusSystem/Client/ResourceManagementClient.py b/ResourceStatusSystem/Client/ResourceManagementClient.py index 3ed2445a2b1..5eccbf76849 100644 --- a/ResourceStatusSystem/Client/ResourceManagementClient.py +++ b/ResourceStatusSystem/Client/ResourceManagementClient.py @@ -81,7 +81,7 @@ def __query( self, queryType, tableName, kwargs ): meta[ 'table' ] = tableName - gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) + gLogger.debug( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) ################################################################################ diff --git a/ResourceStatusSystem/Client/ResourceStatusClient.py b/ResourceStatusSystem/Client/ResourceStatusClient.py index b73f5c9ae56..941382e5017 100644 --- a/ResourceStatusSystem/Client/ResourceStatusClient.py +++ b/ResourceStatusSystem/Client/ResourceStatusClient.py @@ -90,7 +90,7 @@ def __query( self, queryType, tableName, kwargs ): meta[ 'table' ] = tableName - gLogger.info( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) + gLogger.debug( 'Calling %s, with \n params %s \n meta %s' % ( queryType, params, meta ) ) return gateFunction( params, meta ) ################################################################################