pyats.easypy.plugins package¶
Submodules¶
- class pyats.easypy.plugins.bases.BasePlugin(runtime)¶
Bases:
pyats.easypy.base.Component
Base class for all plugin
initializes basic information about a plugin
- error_handler(stage, e)¶
each plugin has the built-in ability to handle its own exceptions. By default, this exception is caught and stored - in order to avoid system crashing. This is the default error handler that handles this behavior.
Warning
overwriting this function allows you to control how errors in your plugins are handled, but also may lead to errors being “hidden” when you truly want them. Make sure you… keep track of what you are doing.
- static fmt_stage_name(stage)¶
formats the current stage name and add pid to it if it’s a task-related stage. This allows task errors to be split from each other
- get_errors(stage=None)¶
returns a string of the traceback of the last of any errors encountered while running this plugin stage. Used for reporting if one of the plugins failed so we don’t show an empty passed job.
Otherwise returns None.
- has_errors(stage=None)¶
checks if errors occured during a particular execution stage of this plugin. This is the API to use to access the errors generated when this plugin’s various stages are run.
- property name¶
The name of a plugin defaults to its class name. This is also used to start the plugin’s command-line parser section when available.
- parse_args()¶
parse arguments if available, store results to self.args. This follows the easypy argument propagation scheme, where any unknown arguments to this plugin is then stored back into sys.argv and untouched.
Does nothing if a plugin doesn’t come with a built-in parser.
- run(obj, stage, reporter)¶
run plugin stage
plugin entry point called by plugin manager to run a particular stage.
any exceptions/errors during execution of a plugin stage would be stored within the plugin itself, accessible via .has_errors() api.
- Parameters
(Task/Job) (obj) –
(Stage) (stage) –
- class pyats.easypy.plugins.debug.ArchiveConfigPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Plugin that writes the global config to the RunTime Directory
__init__
initializes basic information about a plugin
- pre_job()¶
- class pyats.easypy.plugins.debug.ConfigDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)¶
Bases:
yaml.dumper.SafeDumper
- yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'tuple'>: <function SafeRepresenter.represent_list>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, None: <function SafeRepresenter.represent_undefined>, <class 'type'>: <function represent_class>, <class 'pyats.datastructures.factory.MetaClassFactory'>: <function represent_class>, <class 'pyats.datastructures.attrdict.AttrDict'>: <function represent_dict>}¶
- class pyats.easypy.plugins.debug.CopyJobfileToRunInfo(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
copies the current running jobfile to runtime directory for debugging purposes.
__init__
initializes basic information about a plugin
- pre_job(job)¶
- class pyats.easypy.plugins.debug.CopyManifestFileToRunInfo(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
copies the job manifest file to runtime directory for debugging purposes.
__init__
initializes basic information about a plugin
- pre_job(job)¶
- class pyats.easypy.plugins.debug.EnvironmentDebugPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
saves the current environment information to env.txt file under the runinfo directory.
__init__
initializes basic information about a plugin
- EXTERNAL_PYATS_PKGS = '^pyats($|\\..+$)'¶
- INTERNAL_PYATS_PKGS = '^ats($|\\..+$)'¶
- pre_job(job)¶
- pyats.easypy.plugins.debug.check_pyats_version()¶
- pyats.easypy.plugins.debug.represent_class(dumper, data)¶
- pyats.easypy.plugins.debug.represent_dict(dumper, data)¶
- pyats.easypy.plugins.debug.write_env_variables(fh)¶
- pyats.easypy.plugins.debug.write_pip_pkgs(fh)¶
- pyats.easypy.plugins.debug.write_runtime_values(fh, runtime_env)¶
- pyats.easypy.plugins.debug.write_tcl_pkgs(fh)¶
- class pyats.easypy.plugins.htmllogs.HTMLLogsPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- post_job(job)¶
Generate HTML logs.
- pyats.easypy.plugins.htmllogs.convert_seconds_to_hhmmss(seconds)¶
- pyats.easypy.plugins.htmllogs.get_overall_result(summary)¶
- class pyats.easypy.plugins.kleenex.KleenexPlugin(*args, **kwargs)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- create_topology_graph(taskid='')¶
Create a diagram representing the actual topology.
- do_bringup_clean_logic(task=None, reporter=None)¶
Do bringup and clean as required.
- do_bringup_if_required(task=None)¶
Launch a dynamic topology if required, and load testbed config.
- do_clean(task=None)¶
- load_actual_testbed_configuration()¶
Load actual testbed configuration. Pull the testbed configuration from bringup and load it into self.runtime.job.testbed (possibly replacing the content created by the testbed plugin, which is OK because bringup also merges in content from the original testbed_file, if specified).
- post_job(job)¶
- post_task(task)¶
- pre_job(job, reporter)¶
- pre_task(task, reporter)¶
- prepare_clean(job=None, task=None, reporter=None)¶
Prepare the clean execution. This can be done pre-job or pre-task.
Load clean files, identify which devices to clean.
If task is passed, check if arguments
clean_files
and/orlogical_testbed_file
are passed and use them for task-specific clean.Store processed data in runinfo directory, with taskid if applicable.
- undo_bringup_if_required()¶
Tear down a dynamic topology if it has been previously launched.
- class pyats.easypy.plugins.logs.JobLogPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
JobLogPLugin
Creates a separate easypy module logger and save all easypy internal log messages to that file.
Note
Redirects all log messages in the easypy main process to TaskLog.
initializes basic information about a plugin
- post_job(job)¶
- post_task(task)¶
Remove what pre-task did
- pre_job(job)¶
Everything goes into JobLog
- pre_task(task)¶
Move easypy logging into separate handler, ensure it still gets displayed on the screen
- class pyats.easypy.plugins.logs.LiveviewPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Plugin that starts the liveview server in another process and subscribes to the reporter socket.
__init__
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- hijack_main()¶
- post_job()¶
- pre_job()¶
- class pyats.easypy.plugins.logs.LogWarnings(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Plugin that redirects all python warnings (from warnings module) to both stderr and logging.
Also enables the filtration of all pyATS deprecated warning messages.
__init__
initializes basic information about a plugin
- pre_job()¶
- class pyats.easypy.plugins.logs.TaskLogPlugin(*args, **kwargs)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Creates the TaskLogHandler to each Task process, and attaches to the root logger to collect all messages into the TaskLog. Also sets the default log-level to INFO, and enables on-fork auto-create of new tasklogs.
This handler is removed at the end of Task process.
__init__
initializes basic information about a plugin
- post_task(task)¶
- pre_task(task)¶
- class pyats.easypy.plugins.manager.PluginManager(*args, **kwargs)¶
Bases:
pyats.easypy.base.Component
Plugin Manager class
Instanciates, configures, manages and runs all easypy plugins. This is the main driver behind the easypy plugin system. Do not mock: may blow up.
In any given process, there is only a single instance of PluginManager.
- errored_plugins(stage=None)¶
return list of plugins that errored out when they ran.
- has_errors(stage=None)¶
errors
True/False for if any plugin errored out
- load(data)¶
loads plugins from dictionary data
this api loads plugins defined in a specific dictionary format (same as that defined in load_from_yaml). It does the heavy-lifting of actual plugin module loading and instanciatation.
- Parameters
(dict) (data) –
Example
- PluginManater().load({‘SomePlugin’: {
‘enabled’: True, ‘module’: ‘pyats.easypy.plugins’, ‘order’: 60})
- Returns
- Return type
list of discovered and loaded plugins
- parse_plugin_args()¶
Parse plugin arguments
Iterates over all plugins and invoke their parsers, if any. Plugin’s argument parsing shall follow the argument propagation scheme: sys.argv is left with any arguments it doesn’t recognize.
- run(obj, stage)¶
run plugin stage
main function called by job/tasks to run all plugins in order, for any given stage.
The PluginManager.run() controls the execution order of plugins. When any errors are encountered during a plugin’s PRE-stage run, the corresponding POST-stage section of all plugin ran so far will be run, and the plugin engine will raise exception and error out.
This ensures proper clean-up behavior of plugins, and as well make sure nothing is run (job/task) in case a plugin is not running correctly.
If a plugin action method has “job” or “task” argument, the current executing job/task object will be automatically provided as function argument.
- Parameters
(Task/Job) (obj) –
(str) (stage) –
- class pyats.easypy.plugins.rerun.RerunPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Rerun is an important plugin of pyATS that enables the re-execution of testcases depending on their result types.
Before running the tests this plugin checks for rerun input file to determine which tests will be run
After the execution there will be rerun input file created in order to have the list of testcases that will be run again.
- Parameters
rerun_file (-) – tasks
rerun_condition (-) – If any of the testcases has a result matching one of the result types in the rerun_conditiion list, it will run again.
__init__
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- get_file_rerun_report(filename: str) → dict¶
- Read the rerun report from a rerun results file, or the archive of a
previous run
- get_http_rerun_report(url: str) → dict¶
- Download and read the rerun report from a rerun results file, or the
archive of a previous run
- post_job(job)¶
- pre_job(job)¶
- pre_task(task)¶
- class pyats.easypy.plugins.runinfo.RuninfoSymlinkPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Note
This is a legacy behavior carried over from Tcl-ATS that not many people knows or uses.
Example
basic_example -> basic_example.2015Aug31_10:47:31
__init__
initializes basic information about a plugin
- post_job()¶
- pre_job(job)¶
- class pyats.easypy.plugins.runinfo.TaskResultsPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
creates and delete runinfo/taskresults folder before and after each job run. This is used for debugging and visualizing task progresses.
__init__
initializes basic information about a plugin
- post_job(job)¶
- pre_job(job)¶
- class pyats.easypy.plugins.stages.PluginStage(value)¶
Bases:
enum.Enum
An enumeration.
- property counterpart¶
- property is_post¶
- property is_pre¶
- post_job = 'post_job'¶
- post_task = 'post_task'¶
- pre_job = 'pre_job'¶
- pre_task = 'pre_task'¶
- property scope¶
- class pyats.easypy.plugins.stages.Scope(value)¶
Bases:
enum.Enum
An enumeration.
- job = 'job'¶
- task = 'task'¶
- class pyats.easypy.plugins.testbed.TestbedPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
Loads the provided testbed yaml file into pyats.topology.Testbed objects, and makes them available as testscript parameters in task processes.
__init__
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- post_job(job)¶
- pre_job(job)¶
- class pyats.easypy.plugins.xunit.XunitPlugin(runtime)¶
Bases:
pyats.easypy.plugins.bases.BasePlugin
initializes basic information about a plugin
- classmethod configure_parser(parser, legacy_cli=True)¶
configures the main runtime parser with this component’s own parser group.
Note
to be implemented by the component owner/developer.
should be adding argument groups and args to the provided parser
- generate_xunit_report_data(ts, trade_url)¶
Generate xUnit xml report data.
- post_job(job)¶
Generate xUnit xml and report.
- pyats.easypy.plugins.xunit.pad_number(number)¶
Pads number with N zeroes so that lexicographical sort works properly Accepts numbers, returns a string