Subrack Simulator

A simple subrack simulator.

class SubrackSimulator(**kwargs)

A simple simulator of a subrack management board web server.

class AttributeMetadataType

Type for attribute metadata dictionary.

__init__(**kwargs)

Initialise a new instance.

Parameters:

kwargs (Any) – initial values, different from the defaults, that the simulator should take.

Raises:

AttributeError – if kwargs refer to an non-existent attribute.

execute_command(name, argument)

Execute a command on the subrack hardware/simulator.

It works by checking for a method named f”_{name}”; that is, if the command name is “turn_on_tpms”, then it checks for a method named “_turn_on_tpms”. If it finds such a method, it calls it with the provided argument, and returns the return value.

Otherwise, it checks for a method named f”_async_{name}; for example, “_async_turn_on_tpms”. If it finds such a method, it simulates a long running command by returning “STARTED”, then letting a little time pass, then invoking the method.

Parameters:
  • name (str) – name of the command to execute.

  • argument (Optional[Any]) – argument to the command.

Return type:

Any

Returns:

the return value. For synchronous commands, this is the returned value of the fully executed command. For asynchronous commands, this is the string “STARTED” or “FAILED”.

Raises:

AttributeError – if the command method does not exist in the simulator.

get_attribute(name)

Return the value of a simulator attribute.

Parameters:

name (str) – name of the simulator attribute to be returned.

Return type:

Any

Returns:

the value of the attribute

set_attribute(name, value)

Set the value of a simulator attribute.

Parameters:
  • name (str) – name of the simulator attribute to be set.

  • value (Any) – new values for the simulator attribute

Return type:

Any

Returns:

the new values for the attribute

simulate_attribute(name, values)

Simulate a change in attribute value.

Parameters:
  • name (str) – name of the simulator attribute to be set.

  • values (Any) – new values for the simulator attribute

Return type:

Any

Returns:

the new values for the attribute