taf.plugins.loggers¶
loggers.py
logging functionality for TAF
-
class
taf.plugins.loggers.ClassLogger(log_level='INFO', log_file=None, log_stream=True, for_exception=False, introspection=True)[source]¶ Bases:
objectClass logger descriptor.
-
__get__(instance, owner)[source]¶ This method is called from class.
Parameters: owner (owner) – class instance. Returns: logger adaptor. Return type: logging.LoggerAdapter Note
In case using logger for module level use get() method. __get__() won’t be called from module level.
-
__init__(log_level='INFO', log_file=None, log_stream=True, for_exception=False, introspection=True)[source]¶ Initialize instance of ClassLogger.
Parameters:
-
_get_logger(modulename, classname='', caller_func='')[source]¶ Configure and return loggerAdapter instance.
Parameters: Returns: logger adaptor.
Return type:
-
-
class
taf.plugins.loggers.LoggerWrapper(logger, level)[source]¶ Bases:
threading.ThreadRead text message from a pipe and redirect them to a logger.
Note
The object itself is able to supply a file descriptor to be used for writing. fdWrite ==> fdRead ==> pipeReader.
-
__init__(logger, level)[source]¶ Setup the object with a logger and a loglevel and start the thread.
-
-
class
taf.plugins.loggers.NoErrArgumentParser(*args, **kwargs)[source]¶ Bases:
argparse.ArgumentParserArgumentParser class that handle only predefined for an instance options.
Note
The original ArgumentParser class raises an error if handle unknown option. But py.test have it’s own options and it’s own custom parser and if ArgumentParser find them it raises an error. Using this class allows not to define all possible options in each module that uses ArgumentParser.
taf.plugins.pytest_caselogger¶
pytest_caselogger.py
Plugin is getting logs for each test case
-
class
taf.plugins.pytest_caselogger.CaseLoggerExecutor(env)[source]¶ Bases:
objectBase class for TAF caselogger functionality.
-
__init__(env)[source]¶ Initialize CaseLoggerExecutor instance.
Parameters: env (testlib.common3.Environment) – Environment instance from config
-
-
class
taf.plugins.pytest_caselogger.CaseLoggerPlugin[source]¶ Bases:
objectBase class for caselogger plugin functionality.
-
caselogger(request, suitelogger, env)[source]¶ Call caselogger on test case setup/teardown
Parameters: - request (pytest.request) – pytest request instance
- suitelogger – pytest fixture
- env (testlib.common3.Environment) – ‘env’ pytest fixture from pytest_onsenv.py
-
suitelogger(request, env_main)[source]¶ Call caselogger on test suite teardown.
Parameters: - request (pytest.request) – pytest request instance
- env_main (testlib.common3.Environment) – ‘env_main’ pytest fixture from pytest_onsenv.py
Returns: instance of CaseLoggerExecutor class
Return type:
-
taf.plugins.pytest_heat_checker¶
pytest_heat_checker.py
Plugin is checking temperature
-
class
taf.plugins.pytest_heat_checker.HeatChecker(env, item)[source]¶ Bases:
objectBase class for HeatChecker functionality.
-
__init__(env, item)[source]¶ Initialize HeatChecker instance.
Parameters: - env (testlib.common3.Environment) – Environment instance.
- item (pytest.Item) – Test case instance.
-
-
class
taf.plugins.pytest_heat_checker.HeatCheckerPlugin[source]¶ Bases:
objectLog device’s temperature.
-
heatcheck(request, env)[source]¶ Call heat checker on test case setup/teardown.
Parameters: - request (pytest.request) – Pytest request instance.
- env (testlib.common3.Environment) – ‘env’ pytest fixture from pytest_onsenv.py.
-
taf.plugins.pytest_helpers¶
pytest_helpers.py
pytest specific helpers functions
-
taf.plugins.pytest_helpers.get_brief(item, tc_name)[source]¶ Parse doc-string and return brief.
Parameters: - item (pytest.Item) – pytest test case item
- tc_name (str) – test case name
Returns: test case docstring’s brief
Return type:
-
taf.plugins.pytest_helpers.get_failure_reason(data)[source]¶ Return test case failure reason from report string.
Parameters: data (str) – test case report Returns: failure reason or None Return type: str
-
taf.plugins.pytest_helpers.get_html_xml_path(path, build_name)[source]¶ Parse and replace $BUILD_NAME variable in the path.
Parameters: Returns: modified path to html report
Return type:
-
taf.plugins.pytest_helpers.get_skipped_reason(data)[source]¶ Return test case skip reason from report string.
Parameters: data (str) – test case report Returns: skip reason or None Return type: str
-
taf.plugins.pytest_helpers.get_steps(item, tc_name)[source]¶ Parse and return test steps.
Parameters: - item (pytest.Item) – pytest test case item
- tc_name (str) – test case name
Returns: test case’s steps
Return type:
-
taf.plugins.pytest_helpers.get_suite_name(nodeid)[source]¶ Return suitename from nodeid string.
Parameters: nodeid (str) – pytest.Item nodeid string Returns: test suite name Return type: str
taf.plugins.pytest_loganalyzer¶
pytest_loganalyzer.py
Plugin is checking device’s log after each test case is executed
-
class
taf.plugins.pytest_loganalyzer.LogAnalyzer(switch)[source]¶ Bases:
object-
IGNORE_RES= [re.compile('^Runtime journal is using ')]¶
-
__init__(switch)[source]¶ Initialize LogAnalyzer instance.
Parameters: switch (dict{SwitchGeneral}) – switch dictionary
-
_check_log_duplicates(log_output)[source]¶ Check if duplicated records are present in device log.
Parameters: log_output (str) – output of device log
-
_check_log_errors(log_output)[source]¶ Check if errors with specific priority are present in device log.
Parameters: log_output (str) – output of device log
-
class_logger= <logging.LoggerAdapter object>¶
-
command= "date '+%Y-%m-%d %T'"¶
-
error_priority= 3¶
-
ignore(entry)[source]¶ Check if duplicate can be ignored.
Parameters: entry (dict) – journalctl json decoded dict Returns: if we should ignore this message when checking duplicates Return type: bool
-
runtest_setup_flag= {}¶
-
start_time= {}¶
-
-
class
taf.plugins.pytest_loganalyzer.LogAnalyzerPlugin[source]¶ Bases:
object-
log_analyzer(request, env, log_analyzer_setup)[source]¶ Validate device’s logs on test teardown.
Parameters: - request (pytest.request) – pytest request
- log_analyzer_setup (LogAnalyzer) – LogAnalyzer instance
-
log_analyzer_setup(env_main)[source]¶ Setup LogAnalyzer plugin after devices had been started.
Parameters: env_main (common3.Env) – pytest fixture Returns: LogAnalyzer instance Return type: LogAnalyzer
-
taf.plugins.pytest_multiple_run¶
pytest_multiple_run.py
Re-run test case n times
taf.plugins.pytest_multipletg¶
pytest_multipletg.py
Work with several TGs like with one instance
Note
If setup JSON file contains several TG devices they will be handled as one instance.
Use @pytest.mark.multiple_tgs class level marker in order to disable this functionality for particular test suites.
-
class
taf.plugins.pytest_multipletg.MultipleTGClass(env)[source]¶ Bases:
object-
class_logger= <logging.LoggerAdapter object>¶
-
taf.plugins.pytest_onsenv¶
pytest_onsenv.py
Creates env fixture for ons test cases
-
class
taf.plugins.pytest_onsenv.EnvTest(request, env)[source]¶ Bases:
objectCleanup/Check testing environment.
-
class
taf.plugins.pytest_onsenv.OnsEnvPlugin[source]¶ Bases:
object-
env(request, env_main)[source]¶ Clear devices from environment.
Parameters: request (pytest fixture) – pytest.request Returns: Environment instance Return type: testlib.common3.Environment
-
env_init(request)[source]¶ Validate command line options.
Parameters: request (pytest.request) – pytest request Returns: Environment instance Return type: testlib.common3.Environment
-
env_main(request, env_init)[source]¶ Start/stop devices from environment.
Parameters: request (pytest.request) – pytest request Returns: Environment instance Return type: testlib.common3.Environment
-
taf.plugins.pytest_pidchecker¶
pytest_pidchecker.py
Plugin is checking processes for being restarted
-
class
taf.plugins.pytest_pidchecker.PidChecker(env, flag, item)[source]¶ Bases:
objectBase class for TAF pidchecker functionality.
-
__init__(env, flag, item)[source]¶ Create PidChecker instance.
Parameters: - env (testlib.common3.Environment) – Environment instance from ‘env’ fixture.
- flag (bool) – Flag to know if plugin should skip process validation.
- item (pytest.Item) – Test case instance.
-
_check_processes_setup(switch, tc_name)[source]¶ Check processes on setup.
Parameters: - switch (testlib.switch_general.SwitchGeneral) – switch instance from test environment.
- tc_name (str) – test case’s name.
-
_check_processes_teardown(switch, tc_name)[source]¶ Check process on teardown.
Parameters: - switch (testlib.switch_general.SwitchGeneral) – switch instance from test environment.
- tc_name (str) – test case’s name.
-
-
class
taf.plugins.pytest_pidchecker.PidCheckerPlugin[source]¶ Bases:
objectPidCheckerPlugin implementation.
-
pidcheck(request, env)[source]¶ Call ONS processes verification on test case setup/teardown.
Parameters: - request (pytest.request) – pytest request instance.
- env (testlib.common3.Environment) – ‘env’ pytest fixture from pytest_onsenv.py.
-
taf.plugins.pytest_random_collection¶
pytest_random_collection.py
Choose one test case from test suite randomly if random marker is set
-
class
taf.plugins.pytest_random_collection.RandomChoice(seed)[source]¶ Bases:
objectChoose one test case from test suite randomly if random marker is set.
taf.plugins.pytest_reportingserver¶
pytest_reportingserver.py
XML-RPC reporting server plugin
-
class
taf.plugins.pytest_reportingserver.ReportingServer(opts)[source]¶ Bases:
objectLogging xmlrpc server class.
-
REPORTINGSRV_PATH= 'reporting_server.py'¶
-
REPORTINGSRV_TIMEOUT= 30¶
-
UNDEFINED_BUILD= 'Undefined'¶
-
_get_build_info(item=None)[source]¶ Get info about build.
Parameters: item (pytest.Item) – test case item Returns: str, “build”: str}: build info Return type: dict{“platform”
-
_send_post_queue(item=None, buildname=None, sanity=False)[source]¶ Send info about test execution to the Reporting Server.
Parameters:
-
_send_post_request(item)[source]¶ Send post request to reporting server or add it to queue.
Parameters: item (pytest.Item) – test case item
-
_sessionstart(item)[source]¶ Tell to XMLRPC Server that we are going to interact with it.
Parameters: item (pytest.Item) – test case item
-
buildname(env_prop=None)[source]¶ Return buildname for current session.
Parameters: env_prop (dict) – environment information e.g. build, name, etc. Returns: buildname Return type: str
-
check_server(timeout=1)[source]¶ Check if xmlrpc server is alive.
Parameters: timeout (int) – timeout for server verification
-
class_logger= <logging.LoggerAdapter object>¶
-
launch_server(port=None)[source]¶ Launch xmlrpc server.
Parameters: port (int) – port to launch xmlrpc server
-
pytest_keyboard_interrupt(excinfo)[source]¶ Handle KeyboardInterrupt.
Parameters: excinfo (py.code.ExceptionInfo) – exception info
-
pytest_runtest_call(item)[source]¶ Create TC instance and send it to the Reporting Server.
Parameters: item (pytest.Item) – test case item
-
pytest_runtest_logreport(report)[source]¶ Send update TC run status to the Reporting Server.
Parameters: report (pytest.BaseReport) – pytets report
-
pytest_runtest_setup(item)[source]¶ Add info about test case start time.
Parameters: item (pytest.Item) – test case item
-
pytest_sessionfinish(session)[source]¶ Tell to XMLRPC Server that we have finished interaction.
Parameters: session (pytest.Session) – test session
-
-
class
taf.plugins.pytest_reportingserver.ReportingServerConfigBase[source]¶ Bases:
objectReporting Server configuration.
-
taf.plugins.pytest_reportingserver.imp_plugins(dest)[source]¶ Import all py modules from <dest> subfolder.
taf.plugins.pytest_returns¶
pytest_returns.py
Collect return results from testcases instead of ‘PASSED’ message
-
class
taf.plugins.pytest_returns.ReturnsPlugin[source]¶ Bases:
object-
PYTEST_REPORT_STATUSES= {'failed': {'letter': 'F', 'outcome': 'failed', 'msg': 'FAILED'}, 'skipped': {'letter': 'S', 'outcome': 'skipped', 'msg': 'SKIPPED'}, 'passed': {'letter': 'P', 'outcome': 'passed', 'msg': 'PASSED'}}¶
-
REPORT_RESULT_GETTER= operator.itemgetter('outcome', 'letter', 'msg')¶
-
RESULT_FAILED= 'failed'¶
-
RESULT_PASSED= 'passed'¶
-
RESULT_SKIPPED= 'skipped'¶
-
taf.plugins.pytest_skip_filter¶
pytest_skip_filter.py
Verify skipif condition on collect stage and remove skipped tests from test run
taf.plugins.pytest_smartrerun¶
pytest_smartrerun.py
Plugin is collecting failed test cases from specific Test Plan in Jira and run them again
taf.plugins.pytest_start_from_case¶
pytest_start_from_case.py
Starting tests execution from the specified test case not from the beginning
Examples:
# complete test-name
$ py.test PATH_TO_TESTS --start_from_case test_my_func
# not complete test-name
$ py.test PATH_TO_TESTS --start_from_case test*func
# or
$ py.test PATH_TO_TESTS --start_from_case *func
# parameterized tests
$ py.test PATH_TO_TESTS --start_from_case test*[1]
# or
$ py.test PATH_TO_TESTS --start_from_case test*1
taf.plugins.pytest_sut_monitor¶
pytest_sut_monitor.py
Collect monitoring info based on Colletcd RRDs
Note
- For correct functioning collectd should be properly configured:
- Collectd server should be configured in the lab
- Collectd client should be configured on device
- On device should be configured hostname equal to the ‘name’ value in JSON
-
class
taf.plugins.pytest_sut_monitor.SutMonitor(env)[source]¶ Bases:
objectMain functionality for collectd client/server manipulation.
-
__init__(env)[source]¶ Initialize SutMonitor object instance.
Parameters: env (testlib.common3.Environment) – TAF environment instance
-
class_logger= <logging.LoggerAdapter object>¶
-
copy_file(remote_file, local_file)[source]¶ Copy file from Collect server host to TAF host.
Parameters:
-
exec_command(command)[source]¶ Execute shell command on Collectd server host.
Parameters: command (str) – command to execute Returns: command execution output Return type: str
-
is_not_empty(folder, start, end, gtype)[source]¶ Check if RRD folder contains non-empty data.
Parameters: Returns: True if folder contains non-empty data
Return type:
-
-
class
taf.plugins.pytest_sut_monitor.SutMonitorPlugin[source]¶ Bases:
objectSutMonitorPlugin implementation.
-
monitor_init(env_init)[source]¶ Initialize SutMonitor on session start.
Parameters: env_init (testlib.common3.Environment) – ‘env_init’ pytest fixture from pytest_onsenv.py
-
pytest_runtest_makereport(item, call)[source]¶ Add generated graphs to the pytest report in order to access from reporting plugin.
-
test_monitor(request, env, monitor)[source]¶ Gather collectd info for certain test case.
Parameters: - request (pytest.request) – pytest request object
- env (testlib.common3.Environment) – env fixture
- monitor_start (SutMonitor) – monitor_start fixture
-
taf.plugins.pytest_syslog¶
pytest_syslog.py
Plugin writes messages to SysLogHandler
Note
For correct functioning syslog should be properly configured, e.g.
On device should be configured hostname seacliff9.
The following lines should be added to syslog config:
# This is criteria for seacliff messages if $hostname contains 'seacliff9' then /var/log/switches/seacliff09.log # This s criteria for our log messages if $msg contains 'seacliff9' and $programname == 'pytest_syslog' then /var/log/switches/seacliff9.log
Also it is good to configure logrotate (e.g. /etc/logrotate.d/switches) file of :
Examples:
/var/log/switches/*.log
{
rotate 730
weekly
missingok
notifempty
delaycompress
compress
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
- Known issues:
- rsyslog could miss log messages from remote host if it cannot resolve host FQDN 10 times. To disable dns resolving add -x option to /etc/default/rsyslog (for debian based distros).
-
class
taf.plugins.pytest_syslog.SyslogNotifier[source]¶ Bases:
objectSend syslog messages.
-
_create_header(env_prop, stage)[source]¶ Send syslog header/footer message for each device in config.
Parameters: Returns: None
Examples:
self._create_header(env_object.config, {"py.test PID": "5216", "chipName": "8086", "cpuArchitecture": "8bit"}, "SessionStart")
-
_update_tc_status(tcname, status)[source]¶ Send syslog TC status message for each device in config.
Parameters: Returns: None
Examples:
self._update_tc_status(env_object.config, "test_some_feature_1", "started")
-
get_last_record_from_log(log, item)[source]¶ Return last log records for TC.
Parameters: - log (str) – log file
- item (pytest.Item) – test case item
Returns: Log related to specified test item
Return type:
-
get_log_path(switch_name)[source]¶ Return log path from environment.json for switch.
Parameters: switch_name (str) – switch name Returns: path to log for specified device Return type: str
-
is_test_completed(report)[source]¶ Return True if make_report hook called after TC and TC failed.
Parameters: report (pytest.Report) – pytest report Returns: True if test is complited without errors Return type: bool
-
taf.plugins.pytest_test_duration¶
pytest_test_duration.py
Plugin is controlling test execution by time or count of iteration
-
class
taf.plugins.pytest_test_duration.Duration(option=None)[source]¶ Bases:
objectMain functionality for test duration manipulation.
-
__init__(option=None)[source]¶ Initialize Duration object instance.
Parameters: option (str, e.g "30s", "2.5H") – time to interrupt test(cmd option)
-
taf.plugins.pytest_workload¶
pytest_workload.py
Add workload on SUTs using stress tool
-
class
taf.plugins.pytest_workload.ARGS(class_name, config, opts, shared, workers)¶ Bases:
tuple-
__getnewargs__()¶ Return self as a plain tuple. Used by copy and pickle.
-
static
__new__(_cls, class_name, config, opts, shared, workers)¶ Create new instance of ARGS(class_name, config, opts, shared, workers)
-
__repr__()¶ Return a nicely formatted representation string
-
_asdict()¶ Return a new OrderedDict which maps field names to their values.
-
classmethod
_make(iterable, new=<built-in method __new__ of type object at 0xa395c0>, len=<built-in function len>)¶ Make a new ARGS object from a sequence or iterable
-
_replace(_self, **kwds)¶ Return a new ARGS object replacing specified fields with new values
-
class_name¶ Alias for field number 0
-
config¶ Alias for field number 1
-
opts¶ Alias for field number 2
Alias for field number 3
-
workers¶ Alias for field number 4
-
-
class
taf.plugins.pytest_workload.WorkloadContinuous(env, workers)[source]¶ Bases:
objectMain functionality for workload manipulation.
-
__init__(env, workers)[source]¶ Initialize WorkloadContinuous object instance.
Parameters: env (testlib.common3.Environment) – TAF environment instance
-
class_logger= <logging.LoggerAdapter object>¶
-
-
class
taf.plugins.pytest_workload.WorkloadInterrupted(env, workers)[source]¶ Bases:
objectMain functionality for workload manipulation.
-
__init__(env, workers)[source]¶ Initialize WorkloadInterrupted object instance.
Parameters: env (testlib.common3.Environment) – TAF environment instance
-
class_logger= <logging.LoggerAdapter object>¶
-
-
class
taf.plugins.pytest_workload.WorkloadPlugin(workload_type, workers)[source]¶ Bases:
objectWorkloadPlugin implementation.
-
test_workload(request, env, workload)[source]¶ Gather collectd info for certain test case.
Parameters: - request (pytest.request) – pytest request object
- env (testlib.common3.Environment) – env fixture
- monitor_start (SutMonitor) – monitor_start fixture
-
workload_init(env_init)[source]¶ Initialize WorkloadPlugin on session start.
Parameters: env_init (testlib.common3.Environment) – ‘env_init’ pytest fixture from pytest_onsenv.py
-
taf.plugins.reports_conf¶
taf.plugins.reports_conf¶
taf.plugins.reports_conf.SYNAPSERT¶
SYNAPSERT.py
SYNAPSERT class
-
class
taf.plugins.reports_conf.SYNAPSERT.ReportingServerConfig[source]¶ Bases:
objectReporting Server configuration.
-
static
_configure(config)[source]¶ Checking tm_update option.
Parameters: config (bool) – get options
-
static
_get_build_name(options)[source]¶ Return spesified buildname.
Parameters: options (str) – get options
-
static
_sessionstart(log_class, item, name, buildname)[source]¶ Tell to XMLRPC Server that we are going to interact with it.
Parameters:
-
class_logger= <logging.LoggerAdapter object>¶
-
static
taf.plugins.reports_conf.XML¶
XML.py
XML and HTML report classes