Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/DIRAC/Resources/Catalog/RucioFileCatalogClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@
RUCIO_COLLECTION_TYPES = {"DATASET", "CONTAINER"}


def get_scope(lfn, scopes=None, diracAlgorithm="dirac"):
def get_scope(lfn, scopes=None, default_extract="def"):
"""
Helper function that extracts the scope from the LFN.

:param str lfn: Logical file name
:param list scopes: list of scopes
:param str diracAlgorithm: only used by extract_scope if there is no config file with an algorithm listed.
Otherwise use the algorithm listed in the config file.
:param str default_extract: fallback algorithm used by Rucio if no config file defines one.
:return: scope name
"""

if scopes is None:
scopes = []
scope, _ = extract_scope(did=lfn, scopes=scopes, default_extract=diracAlgorithm)
scope, _ = extract_scope(did=lfn, scopes=scopes, default_extract=default_extract)
return scope


Expand Down Expand Up @@ -106,7 +105,7 @@ def __init__(self, **options):

:param options: options dict
"""
self.diracScopeAlg = options.get("DiracScopeAlg", "dirac")
self.scopeExtractAlg = options.get("DiracScopeAlg", "def")
self.useDiracCS = False # use a Rucio config file
self.convertUnicode = True
proxyInfo = {"OK": False}
Expand Down Expand Up @@ -206,7 +205,7 @@ def __getDidsFromLfn(self, lfn):
if lfn.find(":") > -1:
scope, name = lfn.split(":")
else:
scope = get_scope(lfn, scopes=self.scopes, diracAlgorithm=self.diracScopeAlg)
scope = get_scope(lfn, scopes=self.scopes, default_extract=self.scopeExtractAlg)
name = lfn
return {"scope": scope, "name": name}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from unittest.mock import MagicMock, patch
from DIRAC.Resources.Catalog.RucioFileCatalogClient import RucioFileCatalogClient
from DIRAC.Resources.Catalog.RucioFileCatalogClient import RucioFileCatalogClient, get_scope


class TestRucioFileCatalogClient(unittest.TestCase):
Expand All @@ -13,6 +13,35 @@ def setUp(self):
def tearDown(self):
self.patcher.stop()

@patch("DIRAC.Resources.Catalog.RucioFileCatalogClient.extract_scope")
def test_get_scope_defaults_to_rucio_default_algorithm(self, mock_extract_scope):
mock_extract_scope.return_value = ("atlas", "atlas:file")

scope = get_scope("atlas:file", scopes=["atlas"])

self.assertEqual(scope, "atlas")
mock_extract_scope.assert_called_once_with(did="atlas:file", scopes=["atlas"], default_extract="def")

@patch("DIRAC.Resources.Catalog.RucioFileCatalogClient.extract_scope")
def test_get_scope_can_still_take_an_explicit_algorithm(self, mock_extract_scope):
mock_extract_scope.return_value = ("atlas", "atlas:file")

scope = get_scope("atlas:file", scopes=["atlas"], default_extract="dirac")

self.assertEqual(scope, "atlas")
mock_extract_scope.assert_called_once_with(did="atlas:file", scopes=["atlas"], default_extract="dirac")

@patch("DIRAC.Resources.Catalog.RucioFileCatalogClient.get_scope")
def test_get_dids_from_lfn_uses_updated_scope_keyword(self, mock_get_scope):
mock_get_scope.return_value = "atlas"

result = self.client._RucioFileCatalogClient__getDidsFromLfn("atlas.file")

self.assertEqual(result, {"scope": "atlas", "name": "atlas.file"})
mock_get_scope.assert_called_once_with(
"atlas.file", scopes=["test_scope"], default_extract=self.client.scopeExtractAlg
)

def test_transform_DIRAC_operator_to_Rucio(self):
DIRAC_dict = {"key1": "value1", "key2": {">": 10}, "key3": {"=": 10}}
expected_output = {"key1": "value1", "key2.gt": 10, "key3": 10}
Expand Down
Loading