2d3d047a8c
Add a series of libraries and resources that are used by the suite setup and test cases functionality. - Libraries - Libraries written in python mostly to serve the installation and deployment of StarlingX from robot test cases. - Resources – Libraries in robot format that are used as a pool of keywords to be used by the entire set of test cases. - Utils – Libraries written in python that expose functionality to configure the framework at host machine level. - Variables – Global variables that are used to setup the framework as well as test cases. Story: 2004828 Task: 29004 Depends-On: I6ead335412150fb8d64a6abf7909cf702d0d248c Change-Id: I796dcaf71089424dd37a050691fd0ee003ad3176 Signed-off-by: Jose Perez Carranza <jose.perez.carranza@intel.com>
140 lines
3.6 KiB
Python
140 lines
3.6 KiB
Python
"""Provides Useful functions for Robot Framework"""
|
|
|
|
from __future__ import print_function
|
|
|
|
import configparser
|
|
import datetime
|
|
import errno
|
|
import os
|
|
|
|
from robot.api import TestData
|
|
|
|
|
|
class Suite(object):
|
|
"""Implement a series of suite attributes
|
|
|
|
To define properties of a suite recognized by robot-framework.
|
|
|
|
"""
|
|
|
|
def __init__(self, name, main_suite_path):
|
|
self.name = name
|
|
self.main_suite = TestData(source=main_suite_path)
|
|
self.path = self.__get_suite_path(self.main_suite)
|
|
try:
|
|
self.data = TestData(source=self.path)
|
|
except TypeError as err:
|
|
print('ERROR: Suite {0} not found'.format(self.name))
|
|
raise err
|
|
|
|
def __get_suite_path(self, main_suite):
|
|
"""Return path of an specific test suite
|
|
|
|
Args:
|
|
main_suite = main suite test Data
|
|
Returns:
|
|
found_path = path of the suite found
|
|
|
|
"""
|
|
|
|
if main_suite.name == self.name:
|
|
return main_suite.source
|
|
for child in main_suite.children:
|
|
found_path = self.__get_suite_path(child)
|
|
if found_path:
|
|
return found_path
|
|
|
|
|
|
def get_config():
|
|
"""Read configuration file defined on execution directory
|
|
|
|
Returns:
|
|
config = Instance with configuration values parsed
|
|
from specified file
|
|
|
|
"""
|
|
|
|
config = configparser.ConfigParser()
|
|
config.read('stx.config')
|
|
return config
|
|
|
|
|
|
def check_results_dir(suite_dir):
|
|
"""Check if results directory already exist, if not, create it
|
|
|
|
Args:
|
|
suite_dir = Path to the main suite
|
|
Returns:
|
|
resdir = Directory where results will be stored
|
|
|
|
"""
|
|
|
|
results_dir = os.path.join(suite_dir, 'Results')
|
|
if not os.path.exists(results_dir):
|
|
os.makedirs(results_dir)
|
|
|
|
return results_dir
|
|
|
|
|
|
def create_output_dir(res_dir, suite_name):
|
|
"""Create directory under results to store the execution results
|
|
|
|
Args:
|
|
res_dir = Results dir where the results will be stored
|
|
suite_name = Name of the suite under execution
|
|
Returns:
|
|
out_dir = Path to the dir created with the results
|
|
"""
|
|
start_time = datetime.datetime.now()
|
|
frmt = '%Y%m%d%H%M%S'
|
|
out_dir = '{}/{}_{}'.format(res_dir, start_time.strftime(frmt), suite_name)
|
|
os.makedirs(out_dir)
|
|
|
|
return out_dir
|
|
|
|
|
|
def link_latest_run(suite_dir, out_dir):
|
|
"""Create a symlink to point to the latest execution results
|
|
|
|
Args:
|
|
suite_dir = Path to the main suite on the execution dir
|
|
out_dir = Output dir where the most recent execution results
|
|
are stored
|
|
|
|
Return:
|
|
latest_run = Path of created file with a symlink
|
|
|
|
"""
|
|
latest_run = os.path.join(suite_dir, 'latest-results')
|
|
|
|
try:
|
|
os.symlink(out_dir, latest_run)
|
|
except OSError as err:
|
|
if err.errno == errno.EEXIST:
|
|
os.remove(latest_run)
|
|
os.symlink(out_dir, latest_run)
|
|
else:
|
|
raise err
|
|
|
|
return latest_run
|
|
|
|
|
|
def list_suites(suite, tree_format):
|
|
"""Print in a readable format the list of suites and test cases
|
|
|
|
Args:
|
|
suite = Specific suite data
|
|
tree_format = format to be displayed on stdout
|
|
|
|
"""
|
|
|
|
print('[S] {}{}'.format(tree_format, suite.name))
|
|
if suite.testcase_table.tests:
|
|
tree_format += '.....'
|
|
for test in suite.testcase_table:
|
|
print('(T) {}{}'.format(tree_format, test.name))
|
|
else:
|
|
tree_format += '....|'
|
|
for child in suite.children:
|
|
list_suites(child, tree_format)
|