Skip to content

Commit

Permalink
refactor (SE): for the same protocol, favor the local plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed May 31, 2022
1 parent 21d6076 commit 898a174
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/DIRAC/Resources/Storage/StorageElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,6 @@ def __filterPlugins(self, methodName, protocols=None, inputProtocol=None):
"""

log = self.log.getSubLogger("__filterPlugins")

log.debug(
"Filtering plugins for %s (protocol = %s ; inputProtocol = %s)" % (methodName, protocols, inputProtocol)
)
Expand Down Expand Up @@ -1090,10 +1089,16 @@ def __filterPlugins(self, methodName, protocols=None, inputProtocol=None):
pluginsToUse = list(self.storages.values())

# The closest list for "OK" methods is the AccessProtocol preference, so we sort based on that
pluginsToUse.sort(
key=lambda x: getIndexInList(x.protocolParameters["Protocol"], self.localAccessProtocolList)

pluginsToUse = sorted(
pluginsToUse,
key=lambda x: (
getIndexInList(x.protocolParameters["Protocol"], self.localAccessProtocolList),
x.protocolSectionName in self.remoteProtocolSections,
),
)
log.debug("Plugins to be used for %s: %s" % (methodName, [p.pluginName for p in pluginsToUse]))

log.debug("Plugins to be used for %s: %s" % (methodName, [p.protocolSectionName for p in pluginsToUse]))
return pluginsToUse

log.debug("Allowed protocol: %s" % allowedProtocols)
Expand Down Expand Up @@ -1135,7 +1140,16 @@ def __filterPlugins(self, methodName, protocols=None, inputProtocol=None):
pluginsToUse.append(plugin)

# sort the plugins according to the lists in the CS
pluginsToUse.sort(key=lambda x: getIndexInList(x.protocolParameters["Protocol"], allowedProtocols))
# and then favor local plugins over remote ones
# note: False < True, so to have local plugin first,
# we test if the plugin is in the remote list
pluginsToUse = sorted(
pluginsToUse,
key=lambda x: (
getIndexInList(x.protocolParameters["Protocol"], allowedProtocols),
x.protocolSectionName in self.remoteProtocolSections,
),
)

log.debug("Plugins to be used for %s: %s" % (methodName, [p.protocolSectionName for p in pluginsToUse]))

Expand Down
8 changes: 7 additions & 1 deletion src/DIRAC/Resources/Storage/test/Test_StorageFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,13 @@ def generateConfig():

def mock_StorageFactory__generateStorageObject(*args, **kwargs):
"""Don't really load the plugin, just create an object"""
return S_OK(object())
# We create this FakeStorage object because if we just
# return a plain object, we get a lot of AttributeErrors
# later in the test
class FakeStorage:
pass

return S_OK(FakeStorage())


def mock_resourceStatus_getElementStatus(self, seName, elementType="StorageElement"):
Expand Down

0 comments on commit 898a174

Please sign in to comment.