diff --git a/src/DIRAC/Resources/Catalog/RucioFileCatalogClient.py b/src/DIRAC/Resources/Catalog/RucioFileCatalogClient.py index 8700a8eb237..638dd967e30 100644 --- a/src/DIRAC/Resources/Catalog/RucioFileCatalogClient.py +++ b/src/DIRAC/Resources/Catalog/RucioFileCatalogClient.py @@ -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 @@ -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} @@ -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} diff --git a/src/DIRAC/Resources/Catalog/test/Test_RucioFileCatalogClient.py b/src/DIRAC/Resources/Catalog/test/Test_RucioFileCatalogClient.py index d3afd07f6cf..3e0ead8ddd8 100644 --- a/src/DIRAC/Resources/Catalog/test/Test_RucioFileCatalogClient.py +++ b/src/DIRAC/Resources/Catalog/test/Test_RucioFileCatalogClient.py @@ -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): @@ -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}