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: Any)[source]
Bases:
LoggableBase class for
EntityandResourceobjects providing common functionality like runpath creation, abort policy and common attributes.- Parameters:
runpath (
strorNoneTypecallable 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: bool
Returns if entity was aborted.
- property active: bool
Entity not aborting/aborted.
- context_input(exclude: list | None = None) Dict[str, Any][source]
All attr of self in a dict for context resolution
- classmethod filter_locals(local_vars: Dict[str, Any]) Dict[str, Any][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: ReportLink
A handle to access the report via recursive parent
- 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.
- property status: EntityStatus
Status object.
- class testplan.common.entity.base.EntityConfig(**options: Any)[source]
Bases:
ConfigConfiguration object for
Entityobject.All classes that inherit
Entitycan define a configuration that inherits this one’s schema.- 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)
- ignore_extra_keys = False
- set_local(name: str, value: Any) None
set without any check
- class testplan.common.entity.base.EntityStatus[source]
Bases:
objectRepresents current status of an
Entityobject.TODO: Utilise metadata to store information.
- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- change(new: str | None) None[source]
Transition to new status.
- Parameters:
new (
NoneTypeorstr) – status to be set
- property metadata: OrderedDict[str, Any]
TODO
- property tag: str | None
Current status value.
- class testplan.common.entity.base.Environment(parent: Entity | None = None)[source]
Bases:
objectA 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
Resourceto the Environment.- Parameters:
item (
Resource) – Resource to be added.uid (
strorNoneType) – Unique identifier.
- Returns:
Unique identifier assigned to item added.
- Return type:
str
- all_status(target: str | None) 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: ThreadPool, timeout: float | None = None) None[source]
Start all resources concurrently in thread pool and log exceptions.
- Parameters:
pool – thread pool
- stop(is_reversed: bool = False) None[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: str)[source]
Bases:
objectSimple 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:
objectA recursive linkage that will be available to all Entity object.
- children: List[ReportLink]
- class testplan.common.entity.base.Resource(**options: Any)[source]
Bases:
EntityAn object that can be started/stopped and expose its context object of key/value pair information.
A Resource is usually part of an
Environmentobject of aRunnableobject.- Parameters:
async_start (
bool) – Resource can start asynchronously.auto_start (
bool) – Enables the Environment to start the Resource automatically.
Also inherits all
Entityoptions.- CONFIG
alias of
ResourceConfig
- STATUS
alias of
ResourceStatus
- abort() None
Default abort policy. First abort all dependencies and then itself.
- property aborted: bool
Returns if entity was aborted.
- aborting() None
Aborting logic for self.
- property active: bool
Entity not aborting/aborted.
- property async_start: bool
If True, the resource’s parent will take the responsibility to check that the resource has already STARTED or STOPPED.
- 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 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.
- failover() Resource | None[source]
API to create the failover resource, to be implemented in derived class
- 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: 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
- property is_alive: bool
Called to periodically poll the resource health. Default implementation assumes the resource is always healthy.
- property logger: TestplanLogger
logger object
- make_runpath_dirs() None
Creates runpath related directories.
- pause() None
Pauses entity execution.
- register_failover(klass: Type[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: ReportLink
A handle to access the report via recursive parent
- resume() None
Resumes entity execution.
- 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.
- start() None[source]
Triggers the start logic of a Resource by executing :py:meth: Resource.starting <testplan.common.entity.base.Resource.starting> method.
- property status: EntityStatus
Status object.
- stop() None[source]
Triggers the stop logic of a Resource by executing :py:meth: Resource.stopping <testplan.common.entity.base.Resource.stopping> method.
- uid() str
Unique identifier of self.
- wait(target_status: str | None, timeout: int | None = None) None
Wait until objects status becomes target status.
- Parameters:
target_status (
str) – expected statustimeout (
intorNoneType) – timeout in seconds
- class testplan.common.entity.base.ResourceConfig(**options: Any)[source]
Bases:
EntityConfigConfiguration object for
Resourceentity.- 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)
- ignore_extra_keys = False
- set_local(name: str, value: Any) None
set without any check
- class testplan.common.entity.base.ResourceStatus[source]
Bases:
EntityStatusStatus of a
Resourceentity.- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- STARTED = 'STARTED'
- STARTING = 'STARTING'
- STOPPED = 'STOPPED'
- STOPPING = 'STOPPING'
- change(new: str | None) None
Transition to new status.
- Parameters:
new (
NoneTypeorstr) – status to be set
- clear_metadata() None
Re-initializes metadata as empty.
- property metadata: OrderedDict[str, Any]
TODO
- reset() None
Reset status as None.
- property tag: str | None
Current status value.
- update_metadata(**metadata: Any) None
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: Any)[source]
Bases:
EntityAn object that defines steps, a run method to execute the steps and provides results with the
RunnableResultobject.It contains an
Environmentobject ofResourceobjects that can be started/stopped and utilized by the steps defined.- Parameters:
interactive_port (
intorNoneType) – Enable interactive execution mode on a port.interactive_block (
bool) – Block on run() on interactive mode.
Also inherits all
Entityoptions.- CONFIG
alias of
RunnableConfig
- ENVIRONMENT
alias of
Environment
- RESULT
alias of
RunnableResult
- STATUS
alias of
RunnableStatus
- abort() None
Default abort policy. First abort all dependencies and then itself.
- abort_dependencies() Generator[Resource, None, None][source]
Yield all dependencies to be aborted before self abort.
- property aborted: bool
Returns if entity was aborted.
- aborting() None
Aborting logic for self.
- property active: bool
Entity not aborting/aborted.
- add_resource(resource: Resource, uid: str | None = None) str[source]
Adds a
resourcein the runnable environment.- Parameters:
resource (Subclass of
Resource) – Resource to be added.uid (
strorNoneType) – Optional input resource uid.
- Returns:
Resource uid assigned.
- Return type:
str
- 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.
- 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
- property i: TestRunnerIHandler | None
- property interactive: TestRunnerIHandler | None
- property logger: TestplanLogger
logger object
- make_runpath_dirs() None
Creates runpath related directories.
- pause() None
Pauses entity execution.
- property report: ReportLink
A handle to access the report via recursive parent
- property resources: Environment
Returns the
EnvironmentofResources.
- result: RunnableResult
- resume() None
Resumes entity execution.
- run() RunnableResult | None[source]
Executes the defined steps and populates the result object.
- 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.
- property status: EntityStatus
Status object.
- uid() str
Unique identifier of self.
- wait(target_status: str | None, timeout: int | None = None) None
Wait until objects status becomes target status.
- Parameters:
target_status (
str) – expected statustimeout (
intorNoneType) – timeout in seconds
- class testplan.common.entity.base.RunnableConfig(**options: Any)[source]
Bases:
EntityConfigConfiguration object for
Runnableentity.- 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)
- ignore_extra_keys = False
- set_local(name: str, value: Any) None
set without any check
- class testplan.common.entity.base.RunnableManager(**options: Any)[source]
Bases:
EntityExecutes a
Runnableentity in a separate thread and handles the abort signals.- Parameters:
parse_cmdline (
bool) – Parse command line arguments.runnable (
TestRunner) – Test runner.resources (
listofResources) – Initial resources.abort_signals (
listof signals) – Signals to catch and trigger abort.
Also inherits all
Entityoptions.- CONFIG
alias of
RunnableManagerConfig
- STATUS
alias of
EntityStatus
- abort() None
Default abort policy. First abort all dependencies and then itself.
- property aborted: bool
Returns if entity was aborted.
- property active: bool
Expose the runnable active attribute.
- 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.
- enrich_options(options: Dict[str, Any]) Dict[str, Any][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: 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
- property logger: TestplanLogger
logger object
- make_runpath_dirs() None
Creates runpath related directories.
- pause() None
Pauses entity execution.
- property report: ReportLink
A handle to access the report via recursive parent
- resume() None
Resumes entity execution.
- run() RunnableResult | Any[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 runpath: str
Expose the runnable runpath.
- property scratch: str
Path to be used for temp files by entity.
- property status: EntityStatus
Expose the runnable status.
- uid() str
Unique identifier of self.
- wait(target_status: str | None, timeout: int | None = None) None
Wait until objects status becomes target status.
- Parameters:
target_status (
str) – expected statustimeout (
intorNoneType) – timeout in seconds
- class testplan.common.entity.base.RunnableManagerConfig(**options: Any)[source]
Bases:
EntityConfigConfiguration object for
RunnableManagerentity.- 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)
- ignore_extra_keys = False
- set_local(name: str, value: Any) None
set without any check
- class testplan.common.entity.base.RunnableResult[source]
Bases:
objectResult object of a
Runnableentity.- run: bool | Exception
- step_results: OrderedDict[str, Any]
- class testplan.common.entity.base.RunnableStatus[source]
Bases:
EntityStatusStatus of a
Runnableentity.- EXECUTING = 'EXECUTING'
- FINISHED = 'FINISHED'
- NONE = None
- PAUSED = 'PAUSED'
- PAUSING = 'PAUSING'
- RESUMING = 'RESUMING'
- RUNNING = 'RUNNING'
- change(new: str | None) None
Transition to new status.
- Parameters:
new (
NoneTypeorstr) – status to be set
- clear_metadata() None
Re-initializes metadata as empty.
- property metadata: OrderedDict[str, Any]
TODO
- reset() None
Reset status as None.
- property tag: str | None
Current status value.
- update_metadata(**metadata: Any) None
Updates metadata.
- Parameters:
metadata (
OrderedDict) – additional metadata
Module contents
Common entity implementations.