testplan.common.entity package
Submodules
testplan.common.entity.base module
Module containing base classes that represent object entities that can accept configuration, start/stop/run/abort, create results and have some state.
- class testplan.common.entity.base.Entity(**options)[source]
Bases:
Loggable
Base class for
Entity
andResource
objects providing common functionality like runpath creation, abort policy and common attributes.- Parameters:
runpath (
str
orNoneType
callable that returnsstr
) – Path to be used for temp/output files by entity.path_cleanup (
bool
) – Remove previous runpath created dirs/files.status_wait_timeout (
int
) – Timeout for wait status events.abort_wait_timeout (
int
) – Timeout for entity abort.active_loop_sleep (
float
) – Sleep time on busy waiting loops.
- CONFIG
alias of
EntityConfig
- STATUS
alias of
EntityStatus
- property aborted
Returns if entity was aborted.
- property active
Entity not aborting/aborted.
- property cfg
Configuration object.
- context_input(exclude: list = None) Dict[str, Any] [source]
All attr of self in a dict for context resolution
- classmethod filter_locals(local_vars)[source]
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
- property logger: TestplanLogger
logger object
- property report
A handle to access the report via recursive parent
- property runpath
Path to be used for temp/output files by entity.
- property scratch
Path to be used for temp files by entity.
- property status
Status object.
- property timer
- class testplan.common.entity.base.EntityConfig(**options)[source]
Bases:
Config
Configuration object for
Entity
object.All classes that inherit
Entity
can define a configuration that inherits this one’s schema.- classmethod build_schema()
Build a validation schema using the config options defined in this class and its parent classes.
- 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)
- ignore_extra_keys = False
- property parent
Returns the parent configuration.
- set_local(name, value)
set without any check
- class testplan.common.entity.base.EntityStatus[source]
Bases:
object
Represents current status of an
Entity
object.TODO: Utilise metadata to store information.
- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- property metadata
TODO
- property tag
Current status value.
- class testplan.common.entity.base.Environment(parent: Entity | None = None)[source]
Bases:
object
A collection of resources that can be started/stopped.
- Parameters:
parent (
Entity
) – Reference to parent object.
- add(item: Resource, uid: str | None = None) str [source]
Adds a
Resource
to the Environment.- Parameters:
item (
Resource
) – Resource to be added.uid (
str
orNoneType
) – Unique identifier.
- Returns:
Unique identifier assigned to item added.
- Return type:
str
- all_status(target) bool [source]
Checks whether all resources have target status.
- Parameters:
target (
str
) – expected status
- remove(uid: str) None [source]
Removes resource with the given uid from the environment.
- Parameters:
uid – Unique identifier.
- start_in_pool(pool)[source]
Start all resources concurrently in thread pool.
- Parameters:
pool (
ThreadPool
) – thread pool
- stop(is_reversed: bool = False)[source]
Stop all resources, optionally in reverse order, and log exceptions.
- Parameters:
is_reversed – flag whether to stop resources in reverse order
- class testplan.common.entity.base.FailedAction(error_msg)[source]
Bases:
object
Simple falsy container that can be used for returning results of certain failed async actions.
The error_msg can later on be used for enriching the error messages.
- class testplan.common.entity.base.ReportLink(name: str)[source]
Bases:
object
A recursive linkage that will be available to all Entity object.
- class testplan.common.entity.base.Resource(**options)[source]
Bases:
Entity
An object that can be started/stopped and expose its context object of key/value pair information.
A Resource is usually part of an
Environment
object of aRunnable
object.- Parameters:
async_start (
bool
) – Resource can start asynchronously.auto_start (
bool
) – Enables the Environment to start the Resource automatically.
Also inherits all
Entity
options.- CONFIG
alias of
ResourceConfig
- STATUS
alias of
ResourceStatus
- abort()
Default abort policy. First abort all dependencies and then itself.
- abort_dependencies()
Returns an empty generator.
- property aborted
Returns if entity was aborted.
- aborting()
Aborting logic for self.
- property active
Entity not aborting/aborted.
- property async_start
If True, the resource’s parent will take the responsibility to check that the resource has already STARTED or STOPPED.
- property auto_start
If False, the resource will not be automatically started by its parent (generally, a Environment object) while the parent is starting.
- property cfg
Configuration object.
- property 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.
- fetch_error_log() List[str] [source]
Override this method in Resource subclasses to automatically add any useful logs into the report, in case of startup/shutdown exception.
- Returns:
text from log files
- 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
- property is_alive
Called to periodically poll the resource health. Default implementation assumes the resource is always healthy.
- property logger: TestplanLogger
logger object
- make_runpath_dirs()
Creates runpath related directories.
- pause()
Pauses entity execution.
- register_failover(klass: Entity, params: dict) None [source]
Register a failover class to instantiate if resource start fails.
- Parameters:
klass – failover class
params – parameters for failover class __init__ method
- property report
A handle to access the report via recursive parent
- resume()
Resumes entity execution.
- property runpath
Path to be used for temp/output files by entity.
- property scratch
Path to be used for temp files by entity.
- start()[source]
Triggers the start logic of a Resource by executing :py:meth: Resource.starting <testplan.common.entity.base.Resource.starting> method.
- property status
Status object.
- stop()[source]
Triggers the stop logic of a Resource by executing :py:meth: Resource.stopping <testplan.common.entity.base.Resource.stopping> method.
- property timer
- uid()
Unique identifier of self.
- wait(target_status, timeout=None)
Wait until objects status becomes target status.
- Parameters:
target_status (
str
) – expected statustimeout (
int
orNoneType
) – timeout in seconds
- class testplan.common.entity.base.ResourceConfig(**options)[source]
Bases:
EntityConfig
Configuration object for
Resource
entity.- classmethod build_schema()
Build a validation schema using the config options defined in this class and its parent classes.
- 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)
- ignore_extra_keys = False
- property parent
Returns the parent configuration.
- set_local(name, value)
set without any check
- class testplan.common.entity.base.ResourceStatus[source]
Bases:
EntityStatus
Status of a
Resource
entity.- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- STARTED = 'STARTED'
- STARTING = 'STARTING'
- STOPPED = 'STOPPED'
- STOPPING = 'STOPPING'
- change(new)
Transition to new status.
- Parameters:
new (
NoneType
orstr
) – status to be set
- clear_metadata()
Re-initializes metadata as empty.
- property metadata
TODO
- reset()
Reset status as None.
- property tag
Current status value.
- update_metadata(**metadata)
Updates metadata.
- Parameters:
metadata (
OrderedDict
) – additional metadata
- class testplan.common.entity.base.ResourceTimings[source]
Bases:
object
- RESOURCE_SETUP = 'setup'
- RESOURCE_TEARDOWN = 'teardown'
- class testplan.common.entity.base.Runnable(**options)[source]
Bases:
Entity
An object that defines steps, a run method to execute the steps and provides results with the
RunnableResult
object.It contains an
Environment
object ofResource
objects that can be started/stopped and utilized by the steps defined.- Parameters:
interactive_port (
int
orNoneType
) – Enable interactive execution mode on a port.interactive_block (
bool
) – Block on run() on interactive mode.
Also inherits all
Entity
options.- CONFIG
alias of
RunnableConfig
- ENVIRONMENT
alias of
Environment
- RESULT
alias of
RunnableResult
- STATUS
alias of
RunnableStatus
- abort()
Default abort policy. First abort all dependencies and then itself.
- property aborted
Returns if entity was aborted.
- aborting()
Aborting logic for self.
- property active
Entity not aborting/aborted.
- add_resource(resource: Resource, uid: str | None = None)[source]
Adds a
resource
in the runnable environment.- Parameters:
resource (Subclass of
Resource
) – Resource to be added.uid (
str
orNoneType
) – Optional input resource uid.
- Returns:
Resource uid assigned.
- Return type:
str
- property cfg
Configuration object.
- 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.
- 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
- property i
- property interactive
- property logger: TestplanLogger
logger object
- make_runpath_dirs()
Creates runpath related directories.
- pause()
Pauses entity execution.
- property report
A handle to access the report via recursive parent
- property resources: Environment
Returns the
Environment
ofResources
.
- resume()
Resumes entity execution.
- property runpath
Path to be used for temp/output files by entity.
- property scratch
Path to be used for temp files by entity.
- property status
Status object.
- property timer
- uid()
Unique identifier of self.
- wait(target_status, timeout=None)
Wait until objects status becomes target status.
- Parameters:
target_status (
str
) – expected statustimeout (
int
orNoneType
) – timeout in seconds
- class testplan.common.entity.base.RunnableConfig(**options)[source]
Bases:
EntityConfig
Configuration object for
Runnable
entity.- classmethod build_schema()
Build a validation schema using the config options defined in this class and its parent classes.
- 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)
- ignore_extra_keys = False
- property parent
Returns the parent configuration.
- set_local(name, value)
set without any check
- class testplan.common.entity.base.RunnableManager(**options)[source]
Bases:
Entity
Executes a
Runnable
entity in a separate thread and handles the abort signals.- Parameters:
parse_cmdline (
bool
) – Parse command line arguments.runnable (
TestRunner
) – Test runner.resources (
list
ofResources
) – Initial resources.abort_signals (
list
of signals) – Signals to catch and trigger abort.
Also inherits all
Entity
options.- CONFIG
alias of
RunnableManagerConfig
- STATUS
alias of
EntityStatus
- abort()
Default abort policy. First abort all dependencies and then itself.
- property aborted
Returns if entity was aborted.
- property active
Expose the runnable active attribute.
- property cfg
Expose the runnable configuration object.
- 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.
- enrich_options(options)[source]
Enrich the options using parsed command line arguments. Override this method to add extra argument processing logic. The result dictionary is used to initialize the configuration.
- Parameters:
options
- 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
- property logger: TestplanLogger
logger object
- make_runpath_dirs()
Creates runpath related directories.
- pause()
Pauses entity execution.
- property report
A handle to access the report via recursive parent
- resume()
Resumes entity execution.
- run()[source]
Executes target runnable defined in configuration in a separate thread.
- Returns:
Runnable result object.
- Return type:
- py:class:
RunnableResult <testplan.common.entity.base.RunnableResult>
- property runnable
Runnable instance.
- property runpath
Expose the runnable runpath.
- property scratch
Path to be used for temp files by entity.
- property status
Expose the runnable status.
- property timer
- uid()
Unique identifier of self.
- wait(target_status, timeout=None)
Wait until objects status becomes target status.
- Parameters:
target_status (
str
) – expected statustimeout (
int
orNoneType
) – timeout in seconds
- class testplan.common.entity.base.RunnableManagerConfig(**options)[source]
Bases:
EntityConfig
Configuration object for
RunnableManager
entity.- classmethod build_schema()
Build a validation schema using the config options defined in this class and its parent classes.
- 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)
- ignore_extra_keys = False
- property parent
Returns the parent configuration.
- set_local(name, value)
set without any check
- class testplan.common.entity.base.RunnableResult[source]
Bases:
object
Result object of a
Runnable
entity.
- class testplan.common.entity.base.RunnableStatus[source]
Bases:
EntityStatus
Status of a
Runnable
entity.- EXECUTING = 'EXECUTING'
- FINISHED = 'FINISHED'
- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- RUNNING = 'RUNNING'
- change(new)
Transition to new status.
- Parameters:
new (
NoneType
orstr
) – status to be set
- clear_metadata()
Re-initializes metadata as empty.
- property metadata
TODO
- reset()
Reset status as None.
- property tag
Current status value.
- update_metadata(**metadata)
Updates metadata.
- Parameters:
metadata (
OrderedDict
) – additional metadata
- exception testplan.common.entity.base.StatusTransitionException[source]
Bases:
Exception
To be raised on illegal state transition attempt.
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- args
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
Module contents
Common entity implementations.