Skip to content

Commit

Permalink
Merge pull request #185 from lsst-ts/tickets/DM-47619
Browse files Browse the repository at this point in the history
Tickets/DM-47619: Add support to `RemoteGroup` for disabling checks for a list of components
  • Loading branch information
MarcoRocchietti authored Dec 13, 2024
2 parents 850670f + a2f005c commit 21b8305
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/news/DM-47619.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support to ``RemoteGroup`` for disabling checks for a list of components.
50 changes: 49 additions & 1 deletion python/lsst/ts/observatory/control/remote_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(

self._components = dict(
[
(component, component.lower().replace(":", "_"))
(component, self._remote_name_to_attr_format(component))
for component in components
]
)
Expand Down Expand Up @@ -317,6 +317,26 @@ def __init__(
asyncio.gather(*start_task_list) if len(start_task_list) > 0 else None
)

@staticmethod
def _remote_name_to_attr_format(component_name: str) -> str:
"""Returns the remote name in a format compatible with Python object
attribute names.
Parameters
----------
component_name: `str`
Name of the CSC with the same format as that used to initialize the
`salobj.Remotes`, e.g.; "MTMount" or "Hexapod:1".
Returns
-------
`str`
The name of the CSC in lowercase, replacing the colon by an
underscore, e.g. "Hexapod:1" -> "hexapod_1" or "ATHexapod" ->
"athexapod".
"""
return component_name.lower().replace(":", "_")

def components_to_check(self) -> typing.List[str]:
"""Return components for which check is enabled.
Expand All @@ -331,6 +351,34 @@ def components_to_check(self) -> typing.List[str]:
if getattr(self.check, component)
]

def disable_checks_for_components(self, components: typing.List[str]) -> None:
"""Disables checks for a list of components.
The elements of `components` that are not part of the CSC group will be
ignored.
Parameters
----------
components: `list` of `str`
A list of strings that indentifies the components to disable the
check. The names can be eather in attribute format (e.g. "mtmount"
or "hexapod_1") or in salobj remote name format (e.g. "MTMount" or
"Hexapod:1").
"""
for comp in components:
attr_comp = self._remote_name_to_attr_format(comp)
if attr_comp not in self._components.values():
self.log.warning(
f"Component {attr_comp} (referred to as {comp!r}) not in CSC Group. "
f"Must be one of {self.components} or {self.components_attr}. Ignoring."
)
else:
self.log.debug(
f"Disabling check for the component {attr_comp} (referred to as {comp!r})."
)
setattr(self.check, attr_comp, False)

def get_required_resources(
self, component: str, intended_usage: typing.Union[None, int]
) -> typing.Any:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_base_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,30 @@ async def test_get_work_components(self) -> None:

with pytest.raises(RuntimeError):
self.basegroup.get_work_components(["bad_1"])

async def test_disable_components_checks(self) -> None:
async with self.make_group(usage=Usages.DryTest):
# For this test, it is necessary to have at least three components.
assert self.ntest >= 3, "Three components are needed to perform the test"
# Enable all checks and get the components of the remote
self.basegroup.reset_checks()
remote_components = self.basegroup.components_to_check()
# Components to disable checks
components_to_disable = [
"test_1", # Component name in attribute-format
"Test:2", # Component name in Salobj format
"Notcomp:1", # Component name not part of the remote
]

self.basegroup.disable_checks_for_components(
components=components_to_disable
)

# Retrieve the components with checks enabled
remote_enabled_checks = self.basegroup.components_to_check()

assert "test_1" not in remote_enabled_checks
assert "test_2" not in remote_enabled_checks
assert not hasattr(self.basegroup.check, "notcomp_1")
# The remaining components must have their checks enabled
assert all(comp in remote_enabled_checks for comp in remote_components[2:])

0 comments on commit 21b8305

Please sign in to comment.