Skip to content

Commit 72d23f3

Browse files
committed
refactor: commands read args directly from self.args without hardcoded defaults
FreeDiskSpaceCommand and DowntimeCommand no longer duplicate default values in .get() fallbacks — defaults live exclusively in POLICIESMETA and are guaranteed to be present in self.args by the time the command runs.
1 parent b6b0340 commit 72d23f3

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

src/DIRAC/ResourceStatusSystem/Command/DowntimeCommand.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
Downtimes found are stored in the DowntimeCache table via ResourceManagementClient.
55
Stale or deleted GOCDB downtimes are also removed from the cache.
66
7-
The look-ahead window is controlled by the ``hours`` argument (read from ``self.args``,
8-
populated from ``/Operations/Defaults/ResourceStatus/Policies/Downtime/hours``):
7+
The look-ahead window is controlled by the ``hours`` argument read from ``self.args``,
8+
populated by the policy engine from ``POLICIESMETA`` defaults and any CS overrides:
99
10-
* ``hours = 0`` (default) — only ongoing downtimes are considered.
11-
* ``hours > 0`` — downtimes starting within the next ``hours`` hours are also included.
10+
* ``hours = 0`` — only ongoing downtimes are considered.
11+
* ``hours > 0`` — downtimes starting within the next ``hours`` hours are also included.
1212
1313
"""
1414

@@ -144,7 +144,7 @@ def _prepareCommand(self):
144144
145145
Optional key:
146146
147-
* ``hours`` (int) — look-ahead window in hours (default: ``None`` = ongoing only).
147+
* ``hours`` (int) — look-ahead window in hours (populated from ``POLICIESMETA``).
148148
149149
Name resolution:
150150
@@ -172,9 +172,7 @@ def _prepareCommand(self):
172172
if element not in ["Site", "Resource"]:
173173
return S_ERROR("element is neither Site nor Resource")
174174

175-
hours = None
176-
if "hours" in self.args:
177-
hours = self.args["hours"]
175+
hours = self.args.get("hours")
178176

179177
gOCDBServiceType = None
180178

src/DIRAC/ResourceStatusSystem/Command/FreeDiskSpaceCommand.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
33
Command to retrieve and cache the free/total disk space of a Storage Element.
44
5-
The unit and decision thresholds are read from ``self.args`` (populated from the
6-
Operations CS ``/Operations/Defaults/ResourceStatus/Policies/FreeDiskSpace``):
5+
The unit and decision thresholds are read from ``self.args``, which are populated
6+
by the policy engine from ``POLICIESMETA`` defaults and any CS overrides:
77
8-
* ``unit`` — space unit for the occupancy query: ``TB`` (default), ``GB`` or ``MB``
9-
* ``Banned_threshold`` — free-space value below which the SE is Banned (default: 0.1)
10-
* ``Degraded_threshold`` — free-space value below which the SE is Degraded (default: 5)
8+
* ``unit`` — space unit for the occupancy query (``TB``, ``GB`` or ``MB``)
9+
* ``Banned_threshold`` — free-space value below which the SE is Banned
10+
* ``Degraded_threshold`` — free-space value below which the SE is Degraded
1111
1212
Note: there are still many references to "space tokens" (e.g.
1313
``ResourceManagementClient().selectSpaceTokenOccupancyCache(token=elementName)``).
@@ -52,11 +52,11 @@ def _prepareCommand(self):
5252
5353
* ``name`` (str) — Storage Element name.
5454
55-
Optional keys (all read from the FreeDiskSpace policy configuration):
55+
Optional keys (populated from ``POLICIESMETA`` defaults and CS overrides):
5656
57-
* ``unit`` (str) — space unit: ``TB`` (default), ``GB`` or ``MB``.
58-
* ``Banned_threshold`` (float) — free space below which the SE is Banned (default: 0.1).
59-
* ``Degraded_threshold`` (float) — free space below which the SE is Degraded (default: 5).
57+
* ``unit`` (str) — space unit: ``TB``, ``GB`` or ``MB``.
58+
* ``Banned_threshold`` (float) — free space below which the SE is Banned.
59+
* ``Degraded_threshold`` (float) — free space below which the SE is Degraded.
6060
6161
:returns: S_OK tuple ``(elementName, unit, banned_threshold, degraded_threshold)``
6262
or S_ERROR if ``name`` is missing.
@@ -66,10 +66,9 @@ def _prepareCommand(self):
6666
return S_ERROR('"name" not found in self.args')
6767
elementName = self.args["name"]
6868

69-
unit = self.args.get("unit", "TB")
70-
71-
banned_threshold = self.args.get("Banned_threshold", 0.1)
72-
degraded_threshold = self.args.get("Degraded_threshold", 5)
69+
unit = self.args["unit"]
70+
banned_threshold = self.args["Banned_threshold"]
71+
degraded_threshold = self.args["Degraded_threshold"]
7372

7473
return S_OK((elementName, unit, banned_threshold, degraded_threshold))
7574

@@ -91,8 +90,8 @@ def doNew(self, masterParams=None):
9190

9291
if masterParams is not None:
9392
elementName, unit = masterParams
94-
banned_threshold = self.args.get("Banned_threshold", 0.1)
95-
degraded_threshold = self.args.get("Degraded_threshold", 5)
93+
banned_threshold = self.args["Banned_threshold"]
94+
degraded_threshold = self.args["Degraded_threshold"]
9695
else:
9796
params = self._prepareCommand()
9897
if not params["OK"]:

0 commit comments

Comments
 (0)