Skip to content

Commit

Permalink
Merge pull request #112 from lsst-ts/tickets/DM-42694
Browse files Browse the repository at this point in the history
Tickets/dm42694: Proper handling of indexd-CSCs in csc_state_transition script
  • Loading branch information
rbovill authored Feb 28, 2024
2 parents 343e5ce + 574fc4c commit 8491c5e
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 120 deletions.
7 changes: 7 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Version History
.. No new work should be required in order to complete this section.
.. Below is an example of a version history format.
v0.22.0
-------
* Switched M1M3 to individual state transitions.
* Made the csc_state_transition.py script correctly handle indexed-CSCs.
* Moved the various lists in base_script.py to utils.py.
* Various formatting improvements.

v0.21.0
-------
* Added the 'and' into all instances of auxtel_telescope_and_dome_checkout.
Expand Down
113 changes: 3 additions & 110 deletions python/lsst/ts/IntegrationTests/base_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from lsst.ts import salobj
from lsst.ts.idl.enums.Script import ScriptState
from lsst.ts.idl.enums.ScriptQueue import Location, ScriptProcessState
from lsst.ts.IntegrationTests import utils


class BaseScript:
Expand Down Expand Up @@ -60,16 +61,6 @@ class BaseScript:
A list of tuples. The tuple is the script name and a boolean.
The boolean specifies the script as Standard (True)
or External (False).
cscs : `frozenset`
An immutable set of CSCs. This is used to validate CSC state
transition commands.
csc_states : `frozenset`
An immutable set of CSC states. This is used to validate CSC state
transition commands.
processing_states : `frozenset`
An immutable set of the ScriptQueue processing states.
terminal_states : `frozenset`
An immutable set of the ScriptQueue terminal states.
"""

# See Attributes for the definition.
Expand All @@ -79,104 +70,6 @@ class BaseScript:
configs: tuple = ()
scripts: list = []

# Define the list of CSCs.
# This is needed to validate the csc_state_transition configuration.
cscs = frozenset(
[
"ATAOS",
"MTAirCompressor",
"ATBuilding",
"ATCamera",
"ATDome",
"ATDomeTrajectory",
"ATHeaderService",
"ATHexapod",
"ATMCS",
"ATMonochromator",
"ATOODS",
"ATPneumatics",
"ATPtg",
"ATSpectrograph",
"ATWhiteLight",
"Authorize",
"GCHeaderService",
"CCCamera",
"CCHeaderService",
"CCOODS",
"CBP",
"DIMM",
"DREAM",
"DSM",
"EAS",
"Electrometer",
"ESS",
"FiberSpectrograph",
"GenericCamera",
"GIS",
"Guider",
"HVAC",
"LaserTracker",
"LEDProjector",
"LinearStage",
"LOVE",
"MTAOS",
"MTCamera",
"MTDome",
"MTDomeTrajectory",
"MTEEC",
"MTHeaderService",
"MTHexapod",
"MTM1M3",
"MTM1M3TS",
"MTM2",
"MTMount",
"MTOODS",
"MTPtg",
"MTRotator",
"MTVMS",
"OCPS:2",
"OCPS:3",
"PMD",
"Scheduler",
"Script",
"ScriptQueue",
"SummitFacility",
"Test",
"TunableLaser",
"Watcher",
"WeatherForecast",
]
)

# Define the list of CSC States.
csc_states = frozenset(
[
"Offline",
"Standby",
"Disabled",
"Enabled",
]
)
# Define the set of script states that indicate the script is processing.
processing_states = frozenset(
(
ScriptProcessState.UNKNOWN,
ScriptProcessState.LOADING,
ScriptProcessState.CONFIGURED,
ScriptProcessState.RUNNING,
)
)

# Define the set of script states that indicate the script is complete.
terminal_states = frozenset(
(
ScriptProcessState.DONE,
ScriptProcessState.LOADFAILED,
ScriptProcessState.CONFIGURE_FAILED,
ScriptProcessState.TERMINATED,
)
)

def __init__(self, queue_placement: str = "LAST") -> None:
"""Initialize the given Standard or External
script, with the given Yaml configuration, placed in the
Expand Down Expand Up @@ -244,15 +137,15 @@ async def wait_for_done(self, data: salobj.BaseMsgType) -> None:
data : ``lsst.ts.salobj.BaseMsgType``
The object returned by the ScriptQueue Script Event (evt_script).
"""
if data.processState in self.processing_states:
if data.processState in utils.processing_states:
# Script initial, configuration and running states.
print(
f"Script processing state: "
f"{ScriptProcessState(data.processState).name}"
)
return
print(f"Waiting for script ID {self.temp_script_indexes[0]} to finish...")
if data.processState in self.terminal_states and data.timestampProcessEnd > 0:
if data.processState in utils.terminal_states and data.timestampProcessEnd > 0:
print(
f"Script {data.scriptSalIndex} terminal processing state: "
f"{ScriptProcessState(data.processState).name}\n"
Expand Down
31 changes: 24 additions & 7 deletions python/lsst/ts/IntegrationTests/csc_state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import asyncio

import yaml
from lsst.ts.IntegrationTests import BaseScript
from lsst.ts.IntegrationTests import BaseScript, utils


class CSCStateTransition(BaseScript):
Expand All @@ -38,6 +38,8 @@ class CSCStateTransition(BaseScript):
----------
csc : `str`
The name of the CSC to transition. Case-sensitive.
csc_index : `int`
The index value for the indexed-CSC.
state : `str`
The state to transition.
additional_configuration : `str`
Expand All @@ -53,10 +55,12 @@ def __init__(
self,
csc: str,
state: str,
additional_configuration: str = None,
csc_index: int = 0,
additional_configuration: str = "",
) -> None:
super().__init__()
self.csc = csc
self.csc_index = csc_index
self.state = state
self.added_config = additional_configuration
# Set the ScriptQueue index based on which telescope.
Expand All @@ -66,7 +70,11 @@ def __init__(
self.index = 1
# Construct the intermediate configuration list.
# Convert the list to a string.
temp_config = [self.csc, self.state]
if self.csc_index:
full_csc_name = f"{self.csc}:{self.csc_index}"
else:
full_csc_name = self.csc
temp_config = [full_csc_name, self.state]
if self.added_config:
temp_config.append(self.added_config)
config = ", ".join(str(i) for i in temp_config)
Expand All @@ -86,9 +94,9 @@ def __init__(

def csc_state_transition() -> None:
# Define the lists of CSC and State options.
csc_list = list(BaseScript.cscs)
csc_list = list(utils.cscs)
csc_list.sort()
state_list = list(BaseScript.csc_states)
state_list = list(utils.csc_states)
state_list.sort()
# Define the script arguments.
parser = argparse.ArgumentParser()
Expand All @@ -109,7 +117,16 @@ def csc_state_transition() -> None:
help="Specify to which state to transition.",
)
parser.add_argument(
"additional_configuration",
"-x",
"--csc_index",
metavar="index",
nargs="?",
type=int,
help="Define the index of the CSC, if applicable.",
)
parser.add_argument(
"-a",
"--additional_configuration",
nargs="?",
type=str,
help="Specify any additional configurations.",
Expand All @@ -133,7 +150,7 @@ def csc_state_transition() -> None:
f" state:\t{state_list}\n"
)
exit()
if args.csc not in BaseScript.cscs:
if args.csc not in utils.cscs:
print(
f"Invalid CSC: {args.csc}. "
f"Perhaps it is misspelled or not properly capitalized."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ComCamImageTaking(BaseScript):
("maintel/take_image_comcam.py", BaseScript.is_standard),
]

def __init__(self, test_env: str) -> None:
def __init__(self) -> None:
super().__init__()


Expand Down
105 changes: 104 additions & 1 deletion python/lsst/ts/IntegrationTests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,111 @@

import argparse

from lsst.ts.idl.enums.ScriptQueue import ScriptProcessState

def get_test_env_arg() -> None:
# Define the various lists used by the modules in this package.

# Define the list of CSCs.
# This is needed to validate the csc_state_transition configuration.
cscs = frozenset(
[
"ATAOS",
"MTAirCompressor",
"ATBuilding",
"ATCamera",
"ATDome",
"ATDomeTrajectory",
"ATHeaderService",
"ATHexapod",
"ATMCS",
"ATMonochromator",
"ATOODS",
"ATPneumatics",
"ATPtg",
"ATSpectrograph",
"ATWhiteLight",
"Authorize",
"GCHeaderService",
"CCCamera",
"CCHeaderService",
"CCOODS",
"CBP",
"DIMM",
"DREAM",
"DSM",
"EAS",
"Electrometer",
"ESS",
"FiberSpectrograph",
"GenericCamera",
"GIS",
"Guider",
"HVAC",
"LaserTracker",
"LEDProjector",
"LinearStage",
"LOVE",
"MTAOS",
"MTCamera",
"MTDome",
"MTDomeTrajectory",
"MTEEC",
"MTHeaderService",
"MTHexapod",
"MTM1M3",
"MTM1M3TS",
"MTM2",
"MTMount",
"MTOODS",
"MTPtg",
"MTRotator",
"MTVMS",
"OCPS:2",
"OCPS:3",
"PMD",
"Scheduler",
"Script",
"ScriptQueue",
"SummitFacility",
"Test",
"TunableLaser",
"Watcher",
"WeatherForecast",
]
)

# Define the list of CSC States.
csc_states = frozenset(
[
"Offline",
"Standby",
"Disabled",
"Enabled",
]
)

# Define the set of script states that indicate the script is processing.
processing_states = frozenset(
(
ScriptProcessState.UNKNOWN,
ScriptProcessState.LOADING,
ScriptProcessState.CONFIGURED,
ScriptProcessState.RUNNING,
)
)

# Define the set of script states that indicate the script is complete.
terminal_states = frozenset(
(
ScriptProcessState.DONE,
ScriptProcessState.LOADFAILED,
ScriptProcessState.CONFIGURE_FAILED,
ScriptProcessState.TERMINATED,
)
)


def get_test_env_arg() -> argparse.Namespace:
# Define the script arguments.
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_comcam_image_taking_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test_comcam_image_taking(self) -> None:
Use the configuration stored in the image_taking_configs.py module.
"""
# Instantiate the ComCamImageTaking integration tests.
script_class = ComCamImageTaking(test_env="tts")
script_class = ComCamImageTaking()
# Get number of scripts
num_scripts = len(script_class.scripts)
print(
Expand Down

0 comments on commit 8491c5e

Please sign in to comment.