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:
testplan.common.utils.logger.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
-
aborted
¶ Returns if entity was aborted.
-
active
¶ Entity not aborting/aborted.
-
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 –
-
logger
¶ logger object
-
report
¶ A handle to access the report via recursive parent
-
runpath
¶ Path to be used for temp/output files by entity.
-
scratch
¶ Path to be used for temp files by entity.
-
status
¶ Status object.
-
timer
¶
- runpath (
-
class
testplan.common.entity.base.
EntityConfig
(**options)[source]¶ Bases:
testplan.common.config.base.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¶
-
parent
¶ Returns the parent configuration.
-
set_local
(name, value)¶ set without any check
-
classmethod
-
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'¶
-
metadata
¶ TODO
-
tag
¶ Current status value.
-
-
class
testplan.common.entity.base.
Environment
(parent: Optional[Entity] = None)[source]¶ Bases:
object
A collection of resources that can be started/stopped.
Parameters: parent ( Entity
) – Reference to parent object.-
add
(item: testplan.common.entity.base.Resource, uid: Optional[str] = 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
- item (
-
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
-
-
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:
testplan.common.entity.base.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.
-
aborted
¶ Returns if entity was aborted.
-
aborting
()¶ Aborting logic for self.
-
active
¶ Entity not aborting/aborted.
-
async_start
¶ If True, the resource’s parent will take the responsibility to check that the resource has already STARTED or STOPPED.
-
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.
-
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 –
-
is_alive
¶ Called to periodically poll the resource health. Default implementation assumes the resource is always healthy.
-
logger
¶ logger object
-
make_runpath_dirs
()¶ Creates runpath related directories.
-
pause
()¶ Pauses entity execution.
-
register_failover
(klass: testplan.common.entity.base.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
-
report
¶ A handle to access the report via recursive parent
-
resume
()¶ Resumes entity execution.
-
runpath
¶ Path to be used for temp/output files by entity.
-
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.
-
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.
-
timer
¶
-
uid
()¶ Unique identifier of self.
-
wait
(target_status, timeout=None)¶ Wait until objects status becomes target status.
Parameters: - target_status (
str
) – expected status - timeout (
int
orNoneType
) – timeout in seconds
- target_status (
- async_start (
-
class
testplan.common.entity.base.
ResourceConfig
(**options)[source]¶ Bases:
testplan.common.entity.base.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¶
-
parent
¶ Returns the parent configuration.
-
set_local
(name, value)¶ set without any check
-
classmethod
-
class
testplan.common.entity.base.
ResourceStatus
[source]¶ Bases:
testplan.common.entity.base.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.
-
metadata
¶ TODO
-
reset
()¶ Reset status as None.
-
tag
¶ Current status value.
-
update_metadata
(**metadata)¶ Updates metadata.
Parameters: metadata ( OrderedDict
) – additional metadata
-
-
class
testplan.common.entity.base.
Runnable
(**options)[source]¶ Bases:
testplan.common.entity.base.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.
-
aborted
¶ Returns if entity was aborted.
-
aborting
()¶ Aborting logic for self.
-
active
¶ Entity not aborting/aborted.
-
add_resource
(resource: testplan.common.entity.base.Resource, uid: Optional[str] = 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
- resource (Subclass of
-
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 –
-
i
¶
-
interactive
¶
-
logger
¶ logger object
-
make_runpath_dirs
()¶ Creates runpath related directories.
-
pause
()¶ Pauses entity execution.
-
report
¶ A handle to access the report via recursive parent
-
resources
¶ Returns the
Environment
ofResources
.
-
resume
()¶ Resumes entity execution.
-
runpath
¶ Path to be used for temp/output files by entity.
-
scratch
¶ Path to be used for temp files by entity.
-
status
¶ Status object.
-
timer
¶
-
uid
()¶ Unique identifier of self.
-
wait
(target_status, timeout=None)¶ Wait until objects status becomes target status.
Parameters: - target_status (
str
) – expected status - timeout (
int
orNoneType
) – timeout in seconds
- target_status (
- interactive_port (
-
class
testplan.common.entity.base.
RunnableConfig
(**options)[source]¶ Bases:
testplan.common.entity.base.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¶
-
parent
¶ Returns the parent configuration.
-
set_local
(name, value)¶ set without any check
-
classmethod
-
class
testplan.common.entity.base.
RunnableManager
(**options)[source]¶ Bases:
testplan.common.entity.base.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.
-
aborted
¶ Returns if entity was aborted.
-
active
¶ Expose the runnable active attribute.
-
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 –
-
logger
¶ logger object
-
make_runpath_dirs
()¶ Creates runpath related directories.
-
pause
()¶ Pauses entity execution.
-
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>
-
runnable
¶ Runnable instance.
-
runpath
¶ Expose the runnable runpath.
-
scratch
¶ Path to be used for temp files by entity.
-
status
¶ Expose the runnable status.
-
timer
¶
-
uid
()¶ Unique identifier of self.
-
wait
(target_status, timeout=None)¶ Wait until objects status becomes target status.
Parameters: - target_status (
str
) – expected status - timeout (
int
orNoneType
) – timeout in seconds
- target_status (
- parse_cmdline (
-
class
testplan.common.entity.base.
RunnableManagerConfig
(**options)[source]¶ Bases:
testplan.common.entity.base.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¶
-
parent
¶ Returns the parent configuration.
-
set_local
(name, value)¶ set without any check
-
classmethod
-
class
testplan.common.entity.base.
RunnableResult
[source]¶ Bases:
object
Result object of a
Runnable
entity.
-
class
testplan.common.entity.base.
RunnableStatus
[source]¶ Bases:
testplan.common.entity.base.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.
-
metadata
¶ TODO
-
reset
()¶ Reset status as None.
-
tag
¶ Current status value.
-
update_metadata
(**metadata)¶ Updates metadata.
Parameters: metadata ( OrderedDict
) – additional metadata
-
Module contents¶
Common entity implementations.