testplan.testing.multitest.driver.tcp package

Submodules

testplan.testing.multitest.driver.tcp.client module

TCPClient driver classes.

class testplan.testing.multitest.driver.tcp.client.TCPClient(name: str, host: Union[str, testplan.common.utils.context.ContextValue], port: Union[int, str, testplan.common.utils.context.ContextValue], interface: Optional[Tuple[str, int]] = None, connect_at_start: bool = True, **options)[source]

Bases: testplan.testing.multitest.driver.base.Driver

TCP client driver.

This is built on top of the testplan.common.utils.sockets.client.Client class, which provides equivalent functionality and may be used outside of MultiTest.

{emphasized_members_docs}

Parameters:
  • name – Name of TCPClient.
  • host – Target host name. This can be a ContextValue and will be expanded on runtime.
  • port – Target port number. This can be a ContextValue and will be expanded on runtime.
  • interface – Interface to bind to.
  • connect_at_start – Connect to server on start. Default: True

Also inherits all Driver options.

CONFIG

alias of TCPClientConfig

STATUS

alias of testplan.common.entity.base.ResourceStatus

abort()

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

abort_dependencies()

Returns an empty generator.

aborted

Returns if entity was aborted.

aborting() → None[source]

Abort logic that stops the client.

active

Entity not aborting/aborted.

async_start

Overrides the default async_start value in config.

auto_start

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

cfg

Configuration object.

close() → None[source]

Close connection.

connect() → None[source]

Connect client.

context

Key/value pair information of a Resource.

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

All attr of self in a dict for context resolution

define_runpath()

Define runpath directory based on parent object and configuration.

errpath

Path for stderr file regexp matching.

extract_driver_metadata() → testplan.testing.multitest.driver.base.DriverMetadata

Extracts driver metadata as described in the extractor function.

Returns:driver metadata
extract_values() → Union[bool, testplan.common.entity.base.FailedAction]

Extract matching values from input regex configuration options.

failover() → 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)

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()

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

force_stopped()

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

host

Target host name.

install_files() → None

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

is_alive

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

logger

logger object

logpath

Path for log regexp matching.

make_runpath_dirs()

Creates runpath related directories.

name

Driver name.

outpath

Path for stdout file regexp matching.

parent

Returns parent Entity.

pause()

Pauses entity execution.

pausing()

Pause the resource.

pending_work()

Resource has pending work.

port

Client port number assigned.

post_start()

Steps to be executed right after resource is started.

post_stop()

Steps to be executed right after resource is stopped.

pre_start() → None

Steps to be executed right before resource starts.

pre_stop()

Steps to be executed right before resource stops.

receive(size: int = 1024, timeout: int = 30) → Optional[bytes][source]

Receive bytes from the given connection.

receive_text(standard: str = 'utf-8', **kwargs) → str[source]

Calls TCPClient.receive and decodes received bytes.

reconnect() → None[source]

Client reconnect.

register_failover(klass: testplan.common.entity.base.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
report

A handle to access the report via recursive parent

restart()

Stop and start the resource.

resume()

Resumes entity execution.

resuming()

Resume the resource.

runpath

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

scratch

Path to be used for temp files by entity.

send(msg: bytes) → int[source]

Sends bytes.

Parameters:msg – Message to be sent
Returns:Number of bytes sent
send_text(msg: str, standard: str = 'utf-8') → int[source]

Encodes to bytes and calls TCPClient.send.

send_tsp(msg: bytes) → Tuple[float, int][source]

Sends bytes and returns also timestamp sent.

Parameters:msg – Message to be sent
Returns:Timestamp when msg sent (in microseconds from epoch) and number of bytes sent
server_port
start()

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

started_check() → Union[bool, testplan.common.entity.base.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.

started_check_interval

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

starting() → None[source]

Start the TCP client and optionally connect to host/post.

status

Status object.

stop()

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

stopped_check() → Union[bool, testplan.common.entity.base.FailedAction]

Predicate indicating whether driver has fully stopped.

Default implementation immediately returns True.

stopped_check_interval

Driver stopped check interval.

stopping() → None[source]

Close the client connection.

timer
uid() → str

Driver uid.

wait(target_status, timeout=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.tcp.client.TCPClientConfig(**options)[source]

Bases: testplan.testing.multitest.driver.base.DriverConfig

Configuration object for TCPClient driver.

classmethod build_schema()

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

static default_metadata_extractor(driver) → testplan.testing.multitest.driver.base.DriverMetadata
denormalize()

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

get_local(name, default=None)

Returns a local config setting (not from container)

classmethod get_options()[source]

Schema for options validation and assignment of default values.

ignore_extra_keys = False
parent

Returns the parent configuration.

set_local(name, value)

set without any check

testplan.testing.multitest.driver.tcp.server module

TCPServer driver classes.

class testplan.testing.multitest.driver.tcp.server.TCPServer(name: str, host: Union[str, testplan.common.utils.context.ContextValue, None] = 'localhost', port: Union[int, str, testplan.common.utils.context.ContextValue, None] = 0, **options)[source]

Bases: testplan.testing.multitest.driver.base.Driver

Driver for a server that can send and receive messages over TCP. Supports multiple connections.

This is built on top of the testplan.common.utils.sockets.server.Server class, which provides equivalent functionality and may be used outside of MultiTest.

{emphasized_members_docs}

Parameters:
  • name (str) – Name of TCPServer.
  • host (str) – Host name to bind to. Default: ‘localhost’
  • port (int) – Port number to bind to. Default: 0 (Random port)

Also inherits all Driver options.

CONFIG

alias of TCPServerConfig

STATUS

alias of testplan.common.entity.base.ResourceStatus

abort()

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

abort_dependencies()

Returns an empty generator.

aborted

Returns if entity was aborted.

aborting()[source]

Abort logic that stops the server.

accept_connection(timeout=10)[source]

Accepts a connection in the order in which they were received. Return the index of the connection, which can be used to send and receive messages using that connection. If no connection is already available or becomes available in the given timeout, then the method returns -1.

Parameters:
  • timeout (int) – Timeout to wait for receiving connection.
  • accept_connection_sleep (float) – Sleep time to retry accept connection.
Returns:

Index of connection

Return type:

int

active

Entity not aborting/aborted.

async_start

Overrides the default async_start value in config.

auto_start

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

cfg

Configuration object.

close_connection(conn_idx)[source]

Unregister, close and remove connection with given connection index

Parameters:conn_idx (int) – Connection index of connection to be removed
Returns:None
Return type:NoneType
context

Key/value pair information of a Resource.

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

All attr of self in a dict for context resolution

define_runpath()

Define runpath directory based on parent object and configuration.

errpath

Path for stderr file regexp matching.

extract_driver_metadata() → testplan.testing.multitest.driver.base.DriverMetadata

Extracts driver metadata as described in the extractor function.

Returns:driver metadata
extract_values() → Union[bool, testplan.common.entity.base.FailedAction]

Extract matching values from input regex configuration options.

failover() → 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)

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()

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

force_stopped()

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

host

Target host name.

install_files() → None

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

is_alive

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

logger

logger object

logpath

Path for log regexp matching.

make_runpath_dirs()

Creates runpath related directories.

name

Driver name.

outpath

Path for stdout file regexp matching.

parent

Returns parent Entity.

pause()

Pauses entity execution.

pausing()

Pause the resource.

pending_work()

Resource has pending work.

port

Port number assigned.

post_start()

Steps to be executed right after resource is started.

post_stop()

Steps to be executed right after resource is stopped.

pre_start() → None

Steps to be executed right before resource starts.

pre_stop()

Steps to be executed right before resource stops.

receive(size=None, conn_idx=None, timeout=30)[source]

Receive bytes from the given connection.

receive_text(standard='utf-8', **kwargs)[source]

Calls TCPServer.receive and decodes received bytes.

register_failover(klass: testplan.common.entity.base.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
report

A handle to access the report via recursive parent

restart()

Stop and start the resource.

resume()

Resumes entity execution.

resuming()

Resume the resource.

runpath

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

scratch

Path to be used for temp files by entity.

send(msg, conn_idx=None, timeout=30)[source]

Send the given message through the given connection.

Parameters:
  • msg (bytes) – message to be sent
  • conn_idx (int) – Index of connection to send to
  • timeout (int) – Timeout in seconds for sending all bytes
Returns:

Number of bytes sent

Return type:

int

send_text(msg, standard='utf-8', **kwargs)[source]

Encodes to bytes and calls TCPServer.send.

socket

Returns the underlying socket object

start()

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

started_check() → Union[bool, testplan.common.entity.base.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.

started_check_interval

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

starting()[source]

Starts the TCP server.

status

Status object.

stop()

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

stopped_check() → Union[bool, testplan.common.entity.base.FailedAction]

Predicate indicating whether driver has fully stopped.

Default implementation immediately returns True.

stopped_check_interval

Driver stopped check interval.

stopping()[source]

Stops the TCP server.

timer
uid() → str

Driver uid.

wait(target_status, timeout=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.tcp.server.TCPServerConfig(**options)[source]

Bases: testplan.testing.multitest.driver.base.DriverConfig

Configuration object for TCPServer driver.

classmethod build_schema()

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

static default_metadata_extractor(driver) → testplan.testing.multitest.driver.base.DriverMetadata
denormalize()

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

get_local(name, default=None)

Returns a local config setting (not from container)

classmethod get_options()[source]

Schema for options validation and assignment of default values.

ignore_extra_keys = False
parent

Returns the parent configuration.

set_local(name, value)

set without any check

Module contents

TCP communication protocol drivers.