ConfigurableCsc#

class lsst.ts.salobj.ConfigurableCsc(name, index, config_schema, config_dir=None, check_if_duplicate=False, initial_state=None, override='', simulation_mode=0, extra_commands={})#

Bases: BaseCsc, ABC

Base class for a configurable Commandable SAL Component (CSC)

Parameters:
  • name (str) – Name of SAL component.

  • index (int or None) – SAL component index, or 0 or None if the component is not indexed.

  • config_schema (dict) – Configuration schema, as a dict in jsonschema format.

  • config_dir (str, optional) – Directory of configuration files, or None for the standard configuration directory (obtained from _get_default_config_dir). This is provided for unit testing.

  • check_if_duplicate (bool, optional) – Check for heartbeat events from the same SAL name and index at startup (before starting the heartbeat loop)? Defaults to False in order to speed up unit tests, but amain sets it true.

  • initial_state (State, int or None, optional) – Initial state for this CSC. If None use the class attribute default_initial_state. Typically State.STANDBY (or State.OFFLINE for an externally commandable CSC) but can also be State.DISABLED, or State.ENABLED, in which case you may also want to specify override for a configurable CSC.

  • override (str, optional) – Configuration override file to apply if initial_state is State.DISABLED or State.ENABLED.

  • simulation_mode (int, optional) – Simulation mode. The default is 0: do not simulate.

  • extra_commands (set`[`str]) – List of commands that can be defined in the CSC but be missing from the interface.

Raises:
  • ValueError – If config_dir is not a directory or initial_state is invalid.

  • salobj.ExpectedError – If simulation_mode is invalid. Note: you will only see this error if you await start_task.

  • RuntimeError – If the environment variable LSST_SITE is not set.

config_dir#

Directory containing configuration files.

Type:

pathlib.Path

config_validator#

Validator for configuration files.

Type:

StandardValidator

schema_version#

Configuration schema version, as specified in the schema as the final word of the title. Used to find the config_dir.

Type:

str

site#

The value of the LSST_SITE environment variable, e.g. “summit”. Used to select the correct configuration files.

Type:

str

Notes

Configuration

Configuration is handled by the start command, as follows:

  • The override field specifies a path to a configuration file found in the package specified by config_pkg in a subdirectory with the name of this SAL component (e.g. Test or ATDomeTrajectory).

  • The configuration file is validated against the schema specified by specified config_schema. This includes setting default values from the schema and validating the result again (in case the default values are invalid).

  • The validated configuration is converted to a struct-like object using types.SimpleNamespace.

  • The configuration is passed to the configure method, which subclasses must override. Note that configure is called just before summary state changes from State.STANDBY to State.DISABLED.

Constructor

The constructor does the following, beyond the parent class constructor:

Attributes Summary

config_dir

Get or set the configuration directory.

Methods Summary

add_arguments(parser)

Add arguments to the parser created by make_from_cmd_line.

add_kwargs_from_args(args, kwargs)

Add constructor keyword arguments based on parsed arguments.

begin_start(data)

Begin do_start; configure the CSC before changing state.

close_tasks()

Shut down pending tasks.

configure(config)

Configure the CSC.

get_config_pkg()

Get the name of the configuration package, e.g. "ts_config_ocs".

read_config_dir()

Read the config dir and put configurationsAvailable if changed.

read_config_dir_loop()

read_config_files(config_validator, ...[, ...])

Read a set of configuration files and return the validated config.

Attributes Documentation

config_dir#

Get or set the configuration directory.

Parameters:

config_dir (str, pathlib.Path) – New configuration directory.

Returns:

config_dir – Absolute path to the configuration directory.

Return type:

pathlib.Path

Raises:

ValueError – If the new configuration dir is not a directory.

Methods Documentation

classmethod add_arguments(parser)#

Add arguments to the parser created by make_from_cmd_line.

Parameters:

parser (argparse.ArgumentParser) – The argument parser.

Return type:

None

Notes

If you override this method then you should almost certainly override add_kwargs_from_args as well.

classmethod add_kwargs_from_args(args, kwargs)#

Add constructor keyword arguments based on parsed arguments.

Parameters:
  • args (argparse.Namespace) – Parsed command.

  • kwargs (dict) – Keyword argument dict for the constructor. Update this based on args. The index argument will already be present if relevant.

Return type:

None

Notes

If you override this method then you should almost certainly override add_arguments as well.

async begin_start(data)#

Begin do_start; configure the CSC before changing state.

Parameters:

data (cmd_start.DataType) – Command data

Return type:

None

Notes

The override field must be one of:

  • The name of a config label or config file

  • The name and version of a config file, formatted as <file_name>:<version>, where the version is a git reference, such as a git tag or commit hash. This form does not support labels.

async close_tasks()#

Shut down pending tasks. Called by close.

Return type:

None

abstract async configure(config)#

Configure the CSC.

Parameters:

config (object) – The configuration, as described by the config schema, as a struct-like object.

Return type:

None

Notes

Called when running the start command, just before changing summary state from State.STANDBY to State.DISABLED.

abstract static get_config_pkg()#

Get the name of the configuration package, e.g. “ts_config_ocs”.

Return type:

str

async read_config_dir()#

Read the config dir and put configurationsAvailable if changed.

Output the configurationsAvailable event (if changed), after updating the overrides and version fields. Also update the version field of evt_configurationApplied, in preparation for the next time the event is output.

Return type:

None

async read_config_dir_loop()#
Return type:

None

classmethod read_config_files(config_validator, config_dir, files_to_read, git_hash='')#

Read a set of configuration files and return the validated config.

Parameters:
  • config_validator (jsonschema validator) – Schema validator for configuration.

  • config_dir (pathlib.Path) – Path to config files.

  • files_to_read (List [str]) – Names of files to read, with .yaml suffix. Empty names are ignored (a useful feature for BaseConfigTestCase). The files are read in order, with each later file overriding values that have been accumulated so far.

  • git_hash (str, optional) – Git hash to use for the files. “” if current.

Returns:

The validated config as a simple namespace.

Return type:

types.SimpleNamespace

Raises:

ExpectedError – If the specified configuration files cannot be found, cannot be parsed as yaml dicts, or produce an invalid configuration (one that does not match the schema).