testplan.testing.multitest.driver.zmq package

Submodules

testplan.testing.multitest.driver.zmq.client module

ZMQClient Driver.

class testplan.testing.multitest.driver.zmq.client.ZMQClient(name: str, hosts: List[str | ContextValue] | str | ContextValue, ports: List[int | ContextValue] | int | ContextValue, message_pattern: int = SocketType.PAIR, connect_at_start: bool = True, **options: Any)[source]

Bases: Driver

The ZMQClient can make multiple connections to different ZMQServers. The socket can be of type:

  • zmq.PAIR

  • zmq.REQ

  • zmq.SUB

  • zmq.PULL

{emphasized_members_docs}

Parameters:
  • name (str) – Name of ZMQClient.

  • hosts (list of str) – List of ZMQServer hostnames to connect to. These can be ContextValue objects and will be expanded on runtime.

  • ports (list of int) – List of ZMQServer ports to connect to. These can be ContextValue objects and will be expanded on runtime. The port correspond to the host at the same index.

  • message_pattern (int) – Type of socket to create connection with. It can be zmq.PAIR (0), zmq.REQ (3), zmq.SUB (2) or zmq.PULL (7).

  • connect_at_start – If True the socket connects immediately after starting the ZMQClient.

CONFIG

alias of ZMQClientConfig

EXTRACTORS: List[BaseConnectionExtractor] = []
STATUS

alias of ResourceStatus

abort() None

Default abort policy. First abort all dependencies and then itself.

abort_dependencies() Generator[Entity, None, None]

Returns an empty generator.

property aborted: bool

Returns if entity was aborted.

aborting() None[source]

Abort logic that stops the client.

property active: bool

Entity not aborting/aborted.

property async_start: bool

Overrides the default async_start value in config.

property auto_start: bool

If False, the resource will not be automatically started by its parent (generally, a Environment object) while the parent is starting.

property cfg: Config

Configuration object.

connect() None[source]

Connect the client socket to all configured connections.

property context: Environment | None

Key/value pair information of a Resource.

context_input(exclude: list | None = None) Dict[str, Any]

All attr of self in a dict for context resolution

define_runpath() None

Define runpath directory based on parent object and configuration.

disconnect() None[source]

Disconnect the client socket from all configured connections if still connected.

property errpath: str | None

Path for stderr file regexp matching.

extract_values() bool | FailedAction

Extract matching values from input regex configuration options.

extracts: Dict[str, str]
failover() Resource | None

API to create the failover resource, to be implemented in derived class

fetch_error_log() List[str]

Fetch error message from the log files of driver, at first we can try self.errpath, if it does not exist, try self.logpath. Typically, several lines from the tail of file will be selected.

Returns:

text from log file

classmethod filter_locals(local_vars: Dict[str, Any]) Dict[str, Any]

Filter out init params of None value, they will take default value defined in its ConfigOption object; also filter out special vars that are not init params from local_vars.

Parameters:

local_vars

flush() None[source]

Flush the clients queue of messages by reconnecting.

force_started() None

Change the status to STARTED (e.g. exception raised).

force_stop() None

Change the status to STOPPED (e.g. exception raised).

get_connections() List[BaseConnectionInfo][source]
property hosts: List[str]

Hosts client connects to.

install_files() None

Installs the files specified in the install_files parameter at the install target.

property is_alive: bool

Called to periodically poll the resource health. Default implementation assumes the resource is always healthy.

property logger: TestplanLogger

logger object

property logpath: str | None

Path for log regexp matching.

make_runpath_dirs() None

Creates runpath related directories.

property name: str

Driver name.

property outpath: str | None

Path for stdout file regexp matching.

property parent: Entity | None

Returns parent Entity.

pause() None

Pauses entity execution.

pausing() None

Pause the resource.

pending_work() bool

Resource has pending work.

property ports: List[str]

Ports of the associated hosts.

post_start() None

Steps to be executed right after resource is started.

post_stop() None

Steps to be executed right after resource is stopped.

pre_start() None

Steps to be executed right before resource starts.

pre_stop() None

Steps to be executed right before resource stops.

receive(timeout: int = 30) Any[source]

Try to receive the message until it has either been received or hits timeout.

Parameters:

timeout (int) – Timeout to retry receiving the message.

Returns:

The received message.

Return type:

bytes or zmq.sugar.frame.Frame or memoryview

reconnect() None[source]

Disconnect and reconnect the client.

register_failover(klass: Type[Entity], params: dict) None

Register a failover class to instantiate if resource start fails.

Parameters:
  • klass – failover class

  • params – parameters for failover class __init__ method

property report: ReportLink

A handle to access the report via recursive parent

restart() None

Stop and start the resource.

resume() None

Resumes entity execution.

resuming() None

Resume the resource.

property runpath: str

Path to be used for temp/output files by entity.

property scratch: str

Path to be used for temp files by entity.

send(data: Any, timeout: int = 30) Any[source]

Try to send the message until it either sends or hits timeout.

Parameters:
  • data (bytes or zmq.sugar.frame.Frame or memoryview) – The content of the message.

  • timeout (int) – Timeout to retry sending the message.

Returns:

None

Return type:

NoneType

start() None

Triggers the start logic of a Resource by executing :py:meth: Resource.starting <testplan.common.entity.base.Resource.starting> method.

property start_timeout: float
started_check() bool | FailedAction

Predicate indicating whether driver has fully started.

Default implementation tests whether certain pattern exists in driver loggings, always returns True if no pattern is required.

property started_check_interval: float | Tuple[float, float]

Driver started check interval. In practice this value is lower-bounded by 0.1 seconds.

starting() None[source]

Start the ZMQ client.

property status: EntityStatus

Status object.

stop() None

Triggers the stop logic of a Resource by executing :py:meth: Resource.stopping <testplan.common.entity.base.Resource.stopping> method.

property stop_timeout: float
stopped_check() bool | FailedAction

Predicate indicating whether driver has fully stopped.

Default implementation immediately returns True.

property stopped_check_interval: float | Tuple[float, float]

Driver stopped check interval.

stopped_check_with_watch(watch: Any) bool | FailedAction
stopping() None[source]

Stop the ZMQ client.

subscribe(topic_filter: Any) None[source]

Subscribe the client to receive messages where the prefix of the message matches the topic filter. Only for SUBSCRIBE clients.

Parameters:

topic_filter (str) – String to filter received messages by.

property timer: Timer
uid() str

Driver uid.

unsubscribe(topic_filter: Any) None[source]

Unsubscribe the client from a particular filter. Only for SUBSCRIBE clients.

Parameters:

topic_filter (str) – Filter to be removed.

wait(target_status: str | None, timeout: int | None = None) None

Wait until objects status becomes target status.

Parameters:
  • target_status (str) – expected status

  • timeout (int or NoneType) – timeout in seconds

class testplan.testing.multitest.driver.zmq.client.ZMQClientConfig(**options: Any)[source]

Bases: DriverConfig

Configuration object for ZMQClient driver.

classmethod build_schema() Schema

Build a validation schema using the config options defined in this class and its parent classes.

denormalize() Config

Create new config object that inherits all explicit attributes from its parents as well.

get_local(name: str, default: Any = None) Any

Returns a local config setting (not from container)

classmethod get_options() Dict[Any, Any][source]

Schema for options validation and assignment of default values.

ignore_extra_keys = False
property parent: Config | None

Returns the parent configuration.

set_local(name: str, value: Any) None

set without any check

testplan.testing.multitest.driver.zmq.server module

ZMQServer Driver.

class testplan.testing.multitest.driver.zmq.server.ZMQServer(name: str, host: str = 'localhost', port: int = 0, message_pattern: int = SocketType.PAIR, **options: Any)[source]

Bases: Driver

The ZMQServer can receive multiple connections from different ZMQClients. The socket can be of type:

  • zmq.PAIR

  • zmq.REP

  • zmq.PUB

  • zmq.PUSH

{emphasized_members_docs}

Parameters:
  • name (str) – Name of ZMQServer.

  • host (str) – Host name to bind to. Default: ‘localhost’

  • port (int) – Port number to bind to. Default: 0 (Random port)

  • message_pattern (int) – Message pattern. Default: zmq.PAIR

CONFIG

alias of ZMQServerConfig

EXTRACTORS: List[BaseConnectionExtractor] = [<testplan.testing.multitest.driver.connection.connection_extractor.ConnectionExtractor object>]
STATUS

alias of ResourceStatus

abort() None

Default abort policy. First abort all dependencies and then itself.

abort_dependencies() Generator[Entity, None, None]

Returns an empty generator.

property aborted: bool

Returns if entity was aborted.

aborting() None[source]

Abort logic that stops the server.

property active: bool

Entity not aborting/aborted.

property async_start: bool

Overrides the default async_start value in config.

property auto_start: bool

If False, the resource will not be automatically started by its parent (generally, a Environment object) while the parent is starting.

property cfg: Config

Configuration object.

property connection_identifier: int | None
property context: Environment | None

Key/value pair information of a Resource.

context_input(exclude: list | None = None) Dict[str, Any]

All attr of self in a dict for context resolution

define_runpath() None

Define runpath directory based on parent object and configuration.

property errpath: str | None

Path for stderr file regexp matching.

extract_values() bool | FailedAction

Extract matching values from input regex configuration options.

extracts: Dict[str, str]
failover() Resource | None

API to create the failover resource, to be implemented in derived class

fetch_error_log() List[str]

Fetch error message from the log files of driver, at first we can try self.errpath, if it does not exist, try self.logpath. Typically, several lines from the tail of file will be selected.

Returns:

text from log file

classmethod filter_locals(local_vars: Dict[str, Any]) Dict[str, Any]

Filter out init params of None value, they will take default value defined in its ConfigOption object; also filter out special vars that are not init params from local_vars.

Parameters:

local_vars

force_started() None

Change the status to STARTED (e.g. exception raised).

force_stop() None

Change the status to STOPPED (e.g. exception raised).

get_connections() List[BaseConnectionInfo]
property host: str | None

Target host name.

install_files() None

Installs the files specified in the install_files parameter at the install target.

property is_alive: bool

Called to periodically poll the resource health. Default implementation assumes the resource is always healthy.

property local_host: str | None
property local_port: int | None
property logger: TestplanLogger

logger object

property logpath: str | None

Path for log regexp matching.

make_runpath_dirs() None

Creates runpath related directories.

property name: str

Driver name.

property outpath: str | None

Path for stdout file regexp matching.

property parent: Entity | None

Returns parent Entity.

pause() None

Pauses entity execution.

pausing() None

Pause the resource.

pending_work() bool

Resource has pending work.

property port: int | None

Port number assigned.

post_start() None

Steps to be executed right after resource is started.

post_stop() None

Steps to be executed right after resource is stopped.

pre_start() None

Steps to be executed right before resource starts.

pre_stop() None

Steps to be executed right before resource stops.

receive(timeout: int = 30) Any[source]

Try to send the message until it either has been received or hits timeout.

Parameters:

timeout (int) – Timeout to retry receiving the message

Returns:

The received message

Return type:

object or str or zmq.sugar.frame.Frame

register_failover(klass: Type[Entity], params: dict) None

Register a failover class to instantiate if resource start fails.

Parameters:
  • klass – failover class

  • params – parameters for failover class __init__ method

property report: ReportLink

A handle to access the report via recursive parent

restart() None

Stop and start the resource.

resume() None

Resumes entity execution.

resuming() None

Resume the resource.

property runpath: str

Path to be used for temp/output files by entity.

property scratch: str

Path to be used for temp files by entity.

send(data: Any, timeout: int = 30) Any[source]

Try to send the message until it either sends or hits timeout.

Parameters:

timeout (int) – Timeout to retry sending the message

property socket: Socket[Any] | None

Returns the underlying zmq.sugar.socket.Socket object.

start() None

Triggers the start logic of a Resource by executing :py:meth: Resource.starting <testplan.common.entity.base.Resource.starting> method.

property start_timeout: float
started_check() bool | FailedAction

Predicate indicating whether driver has fully started.

Default implementation tests whether certain pattern exists in driver loggings, always returns True if no pattern is required.

property started_check_interval: float | Tuple[float, float]

Driver started check interval. In practice this value is lower-bounded by 0.1 seconds.

starting() None[source]

Start the ZMQServer.

property status: EntityStatus

Status object.

stop() None

Triggers the stop logic of a Resource by executing :py:meth: Resource.stopping <testplan.common.entity.base.Resource.stopping> method.

property stop_timeout: float
stopped_check() bool | FailedAction

Predicate indicating whether driver has fully stopped.

Default implementation immediately returns True.

property stopped_check_interval: float | Tuple[float, float]

Driver stopped check interval.

stopped_check_with_watch(watch: Any) bool | FailedAction
stopping() None[source]

Stop the ZMQServer.

property timer: Timer
uid() str

Driver uid.

wait(target_status: str | None, timeout: int | None = None) None

Wait until objects status becomes target status.

Parameters:
  • target_status (str) – expected status

  • timeout (int or NoneType) – timeout in seconds

class testplan.testing.multitest.driver.zmq.server.ZMQServerConfig(**options: Any)[source]

Bases: DriverConfig

Configuration object for ZMQServer driver.

classmethod build_schema() Schema

Build a validation schema using the config options defined in this class and its parent classes.

denormalize() Config

Create new config object that inherits all explicit attributes from its parents as well.

get_local(name: str, default: Any = None) Any

Returns a local config setting (not from container)

classmethod get_options() Dict[Any, Any][source]

Schema for options validation and assignment of default values.

ignore_extra_keys = False
property parent: Config | None

Returns the parent configuration.

set_local(name: str, value: Any) None

set without any check

Module contents

ZMQDrivers.