Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickets/DM-47619: Add support to RemoteGroup for disabling checks for a list of components #185

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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(salobj_remote_name: str) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming salobj_remote_name -> component_name.

"""Returns the remote name in a format compatible with Python object
attribute names.

Parameters
----------
salobj_remote_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 salobj_remote_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:])
Loading