diff --git a/src/DIRAC/ConfigurationSystem/Client/PathFinder.py b/src/DIRAC/ConfigurationSystem/Client/PathFinder.py index 941cf8dec41..95737405d09 100755 --- a/src/DIRAC/ConfigurationSystem/Client/PathFinder.py +++ b/src/DIRAC/ConfigurationSystem/Client/PathFinder.py @@ -33,14 +33,23 @@ def divideFullName(entityName, componentName=None): def getSystemInstance(system, setup=False): - """Find system instance name + """Find system instance name. :param str system: system name :param str setup: setup name - :return: str + :return: str: instance name. If the system option is present + in the /DIRAC/Setups/ section but is not given a value, + an empty string is returned """ - optionPath = Path.cfgPath("/DIRAC/Setups", setup or getDIRACSetup(), system) + + # If noSetupFlag is set to True, we do not have system instances in the configuration + noSetupFlag = gConfigurationData.extractOptionFromCFG("/DIRAC/NoSetup") + if noSetupFlag == "True": + return "" + + setupToUse = setup or getDIRACSetup() + optionPath = Path.cfgPath("/DIRAC/Setups", setupToUse, system) instance = gConfigurationData.extractOptionFromCFG(optionPath) if not instance: raise RuntimeError(f"Option {optionPath} is not defined") diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py index f95b74021b8..5d745e0e409 100755 --- a/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py @@ -16,7 +16,7 @@ from DIRAC import S_ERROR, S_OK, gConfig from DIRAC.AccountingSystem.Client.Types.Job import Job from DIRAC.ConfigurationSystem.Client.Helpers import cfgPath -from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemInstance +from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemSection from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Core.Utilities import DErrno from DIRAC.Core.Utilities.ClassAd.ClassAdLight import ClassAd @@ -55,9 +55,6 @@ def initialize(self): if not self.am_getOption("Enable", True): self.log.info("Stalled Job Agent running in disabled mode") - wms_instance = getSystemInstance("WorkloadManagement") - if not wms_instance: - return S_ERROR("Can not get the WorkloadManagement system instance") self.stalledJobsTolerantSites = self.am_getOption("StalledJobsTolerantSites", []) self.stalledJobsToleranceTime = self.am_getOption("StalledJobsToleranceTime", 0) @@ -67,7 +64,7 @@ def initialize(self): self.matchedTime = self.am_getOption("MatchedTime", self.matchedTime) self.rescheduledTime = self.am_getOption("RescheduledTime", self.rescheduledTime) - wrapperSection = cfgPath("Systems", "WorkloadManagement", wms_instance, "JobWrapper") + wrapperSection = f"{getSystemSection('WorkloadManagement')}/JobWrapper" failedTime = self.am_getOption("FailedTimeHours", 6) watchdogCycle = gConfig.getValue(cfgPath(wrapperSection, "CheckingTime"), 30 * 60) diff --git a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_StalledJobAgent.py b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_StalledJobAgent.py index 615c55065a7..dbf4ce2fbf7 100644 --- a/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_StalledJobAgent.py +++ b/src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_StalledJobAgent.py @@ -25,11 +25,11 @@ def sja(mocker): ) mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.JobDB") mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.JobLoggingDB") - mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.getSystemInstance", side_effect=mockNone) + mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.getSystemSection", side_effect=mockNone) mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.JobMonitoringClient", return_value=MagicMock()) mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.PilotManagerClient", return_value=MagicMock()) mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.WMSClient", return_value=MagicMock()) - mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.getSystemInstance", return_value="/bof/bih") + mocker.patch("DIRAC.WorkloadManagementSystem.Agent.StalledJobAgent.getSystemSection", return_value="/bof/bih") stalledJobAgent = StalledJobAgent() stalledJobAgent._AgentModule__configDefaults = mockAM diff --git a/src/DIRAC/WorkloadManagementSystem/JobWrapper/Watchdog.py b/src/DIRAC/WorkloadManagementSystem/JobWrapper/Watchdog.py index c2a0ef50ad6..7ff8a46d3b8 100755 --- a/src/DIRAC/WorkloadManagementSystem/JobWrapper/Watchdog.py +++ b/src/DIRAC/WorkloadManagementSystem/JobWrapper/Watchdog.py @@ -25,7 +25,7 @@ from DIRAC import S_ERROR, S_OK, gLogger from DIRAC.ConfigurationSystem.Client.Config import gConfig -from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemInstance +from DIRAC.ConfigurationSystem.Client.PathFinder import getSystemSection from DIRAC.Core.Utilities import MJF from DIRAC.Core.Utilities.Os import getDiskSpace from DIRAC.Core.Utilities.Profiler import Profiler @@ -104,13 +104,7 @@ def initialize(self): else: self.initialized = True - setup = gConfig.getValue("/DIRAC/Setup", "") - if not setup: - return S_ERROR("Can not get the DIRAC Setup value") - wms_instance = getSystemInstance("WorkloadManagement") - if not wms_instance: - return S_ERROR("Can not get the WorkloadManagement system instance") - self.section = f"/Systems/WorkloadManagement/{wms_instance}/JobWrapper" + self.section = f"{getSystemSection('WorkloadManagement')}/JobWrapper" self.log.verbose("Watchdog initialization") # Test control flags diff --git a/src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapper.py b/src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapper.py index b13d7c6ce2f..4fb1521f718 100644 --- a/src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapper.py +++ b/src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapper.py @@ -92,7 +92,7 @@ def test_execute(mocker, executable, args, src, expectedResult): "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.getSystemSection", side_effect=getSystemSectionMock ) mocker.patch( - "DIRAC.WorkloadManagementSystem.JobWrapper.Watchdog.getSystemInstance", side_effect=getSystemSectionMock + "DIRAC.WorkloadManagementSystem.JobWrapper.Watchdog.getSystemSection", side_effect=getSystemSectionMock ) if src: