Skip to content
Merged
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
12 changes: 9 additions & 3 deletions src/DIRAC/ResourceStatusSystem/Utilities/CSHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from DIRAC import S_OK, gConfig, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getCESiteMapping
from DIRAC.Core.Utilities.SiteSEMapping import getSEParameters
from DIRAC.DataManagementSystem.Utilities.DMSHelpers import DMSHelpers

Expand Down Expand Up @@ -75,12 +76,17 @@ def getFileCatalogs():

def getSiteElements(siteName):
"""
Gets all the storage elements for a given site
Gets all the storage and computing elements for a given site
"""

res = DMSHelpers().getSiteSEMapping()
if not res["OK"]:
return res
resources = res["Value"][1].get(siteName, [])
resources = list(res["Value"][1].get(siteName, []))

return S_OK(list(resources))
res = getCESiteMapping()
if not res["OK"]:
return res
resources.extend(ce for ce, site in res["Value"].items() if site == siteName)

return S_OK(resources)
65 changes: 65 additions & 0 deletions src/DIRAC/ResourceStatusSystem/Utilities/test/Test_CSHelpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Tests for CSHelpers module"""

from unittest.mock import patch, MagicMock

from DIRAC import S_OK, S_ERROR
from DIRAC.ResourceStatusSystem.Utilities.CSHelpers import getSiteElements


@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.getCESiteMapping")
@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.DMSHelpers")
def test_getSiteElements_returns_ses_and_ces(mock_dms_helpers, mock_get_ce_site_mapping):
"""Test that getSiteElements returns both StorageElements and ComputingElements"""
mock_dms_instance = MagicMock()
mock_dms_instance.getSiteSEMapping.return_value = S_OK(({}, {"LCG.CERN.cern": ["CERN-SE1", "CERN-SE2"]}, {}))
mock_dms_helpers.return_value = mock_dms_instance

mock_get_ce_site_mapping.return_value = S_OK(
{"ce1.cern.ch": "LCG.CERN.cern", "ce2.cern.ch": "LCG.CERN.cern", "ce3.other.ch": "LCG.Other.cern"}
)

result = getSiteElements("LCG.CERN.cern")
assert result["OK"]
assert sorted(result["Value"]) == sorted(["CERN-SE1", "CERN-SE2", "ce1.cern.ch", "ce2.cern.ch"])


@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.getCESiteMapping")
@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.DMSHelpers")
def test_getSiteElements_site_with_only_ces(mock_dms_helpers, mock_get_ce_site_mapping):
"""Test that a site with only CEs (no SEs) still returns elements"""
mock_dms_instance = MagicMock()
mock_dms_instance.getSiteSEMapping.return_value = S_OK(({}, {}, {}))
mock_dms_helpers.return_value = mock_dms_instance

mock_get_ce_site_mapping.return_value = S_OK({"ce1.krakow.pl": "LCG.Krakow.pl"})

result = getSiteElements("LCG.Krakow.pl")
assert result["OK"]
assert result["Value"] == ["ce1.krakow.pl"]


@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.getCESiteMapping")
@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.DMSHelpers")
def test_getSiteElements_ce_mapping_fails(mock_dms_helpers, mock_get_ce_site_mapping):
"""Test that if CE mapping fails, error is propagated"""
mock_dms_instance = MagicMock()
mock_dms_instance.getSiteSEMapping.return_value = S_OK(({}, {"LCG.CERN.cern": ["CERN-SE1"]}, {}))
mock_dms_helpers.return_value = mock_dms_instance

mock_get_ce_site_mapping.return_value = S_ERROR("Failed to get CE mapping")

result = getSiteElements("LCG.CERN.cern")
assert not result["OK"]


@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.getCESiteMapping")
@patch("DIRAC.ResourceStatusSystem.Utilities.CSHelpers.DMSHelpers")
def test_getSiteElements_se_mapping_fails(mock_dms_helpers, mock_get_ce_site_mapping):
"""Test that if SE mapping fails, error is propagated"""
mock_dms_instance = MagicMock()
mock_dms_instance.getSiteSEMapping.return_value = S_ERROR("Failed to get SE mapping")
mock_dms_helpers.return_value = mock_dms_instance

result = getSiteElements("LCG.CERN.cern")
assert not result["OK"]
mock_get_ce_site_mapping.assert_not_called()
Empty file.
Loading