diff options
Diffstat (limited to 'dovetail')
-rw-r--r-- | dovetail/compliance/compliance_set.yml (renamed from dovetail/cert/compliance_set.yml) | 4 | ||||
-rw-r--r-- | dovetail/compliance/proposed_tests.yml (renamed from dovetail/cert/proposed_tests.yml) | 4 | ||||
-rw-r--r-- | dovetail/conf/cmd_config.yml | 18 | ||||
-rw-r--r-- | dovetail/conf/dovetail_config.py | 9 | ||||
-rw-r--r-- | dovetail/container.py | 30 | ||||
-rw-r--r-- | dovetail/parser.py | 19 | ||||
-rw-r--r-- | dovetail/report.py | 94 | ||||
-rwxr-xr-x | dovetail/run.py | 74 | ||||
-rw-r--r-- | dovetail/testcase.py | 44 | ||||
-rw-r--r-- | dovetail/utils/dovetail_logger.py | 4 |
10 files changed, 198 insertions, 102 deletions
diff --git a/dovetail/cert/compliance_set.yml b/dovetail/compliance/compliance_set.yml index b4108b4f..df0d427d 100644 --- a/dovetail/cert/compliance_set.yml +++ b/dovetail/compliance/compliance_set.yml @@ -1,5 +1,5 @@ -certification_compliance_set: - name: certification_compliance_set +compliance_set: + name: compliance_set testcases_list: # Temporarily, one test case kept here as default to run # for use of software development/debug diff --git a/dovetail/cert/proposed_tests.yml b/dovetail/compliance/proposed_tests.yml index 6d6c8d19..fcb7e03a 100644 --- a/dovetail/cert/proposed_tests.yml +++ b/dovetail/compliance/proposed_tests.yml @@ -1,5 +1,5 @@ -certification_proposed_tests: - name: certification_proposed_tests +proposed_tests: + name: proposed_tests testcases_list: # TO DO: will adjust the dovetail tool to support in later patches # run.py --name1 {**/proposed/compliance} --name2 {**/vim/ipv6,etc} diff --git a/dovetail/conf/cmd_config.yml b/dovetail/conf/cmd_config.yml index c2108c58..4e3d0110 100644 --- a/dovetail/conf/cmd_config.yml +++ b/dovetail/conf/cmd_config.yml @@ -31,18 +31,22 @@ cli: - '--DEPLOY_TYPE' - '-T' help: 'DEPLOY_TYPE of the system under test (SUT).' - CI_DEBUG: + DEBUG: flags: - - '--CI_DEBUG' + - '--DEBUG' - '-d' - help: 'CI_DEBUG for showing debug log.' + help: 'DEBUG for showing debug log.' non-envs: - scenario: + testsuite: flags: - - '--scenario' - - '-s' + - '--testsuite' default: 'compliance_set' - help: 'certification scenario.' + help: 'compliance testsuite.' + testarea: + flags: + - '--testarea' + default: 'full' + help: 'compliance testarea within testsuite' tag: flags: - '--tag' diff --git a/dovetail/conf/dovetail_config.py b/dovetail/conf/dovetail_config.py index 5ac23c43..8fa1a6d2 100644 --- a/dovetail/conf/dovetail_config.py +++ b/dovetail/conf/dovetail_config.py @@ -14,9 +14,12 @@ import re class DovetailConfig: - CERT_PATH = './cert/' + COMPLIANCE_PATH = './compliance/' TESTCASE_PATH = './testcase/' - SCENARIO_NAMING_FMT = 'certification_%s' + # testsuite supported tuple, should adjust accordingly + testsuite_supported = ('compliance_set', 'proposed_tests') + # testarea supported tuple, should adjust accordingly + testarea_supported = ('vimops', 'nfvi', 'ipv6') curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -52,6 +55,8 @@ class DovetailConfig: @classmethod def update_config_envs(cls, script_type, key): + if key == 'DEBUG': + os.environ['CI_DEBUG'] = os.environ[key] envs = cls.dovetail_config[script_type]['envs'] old_value = re.findall(r'\s+%s=(.*?)(\s+|$)' % key, envs) if old_value == []: diff --git a/dovetail/container.py b/dovetail/container.py index 15ccc800..2716a089 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -11,7 +11,6 @@ import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils from conf.dovetail_config import DovetailConfig as dt_config -logger = dt_logger.Logger('container.py').getLogger() class Container: @@ -19,6 +18,8 @@ class Container: container_list = {} has_pull_latest_image = {'yardstick': False, 'functest': False} + logger = None + def __init__(cls): pass @@ -26,6 +27,10 @@ class Container: pass @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.Container').getLogger() + + @classmethod def get(cls, type): return cls.container_list[type] @@ -46,10 +51,10 @@ class Container: dovetail_config[type]['result']['dir']) cmd = 'sudo docker run %s %s %s %s %s /bin/bash' % \ (opts, envs, sshkey, result_volume, docker_image) - dt_utils.exec_cmd(cmd, logger) + dt_utils.exec_cmd(cmd, cls.logger) ret, container_id = \ dt_utils.exec_cmd("sudo docker ps | grep " + docker_image + - " | awk '{print $1}' | head -1", logger) + " | awk '{print $1}' | head -1", cls.logger) cls.container_list[type] = container_id return container_id @@ -57,20 +62,21 @@ class Container: def pull_image(cls, type): docker_image = cls.get_docker_image(type) if cls.has_pull_latest_image[type] is True: - logger.debug('%s is already the newest version.' % (docker_image)) + cls.logger.debug('%s is already the newest version.' % + (docker_image)) else: cmd = 'sudo docker pull %s' % (docker_image) - dt_utils.exec_cmd(cmd, logger) + dt_utils.exec_cmd(cmd, cls.logger) cls.has_pull_latest_image[type] = True - @staticmethod - def clean(container_id): + @classmethod + def clean(cls, container_id): cmd1 = 'sudo docker stop %s' % (container_id) - dt_utils.exec_cmd(cmd1, logger) + dt_utils.exec_cmd(cmd1, cls.logger) cmd2 = 'sudo docker rm %s' % (container_id) - dt_utils.exec_cmd(cmd2, logger) + dt_utils.exec_cmd(cmd2, cls.logger) - @staticmethod - def exec_cmd(container_id, sub_cmd, exit_on_error=False): + @classmethod + def exec_cmd(cls, container_id, sub_cmd, exit_on_error=False): cmd = 'sudo docker exec %s /bin/bash -c "%s"' % (container_id, sub_cmd) - dt_utils.exec_cmd(cmd, logger, exit_on_error) + dt_utils.exec_cmd(cmd, cls.logger, exit_on_error) diff --git a/dovetail/parser.py b/dovetail/parser.py index 1740944a..d8f9fa0a 100644 --- a/dovetail/parser.py +++ b/dovetail/parser.py @@ -14,28 +14,33 @@ import utils.dovetail_logger as dt_logger import utils.dovetail_utils as dt_utils from conf.dovetail_config import DovetailConfig as dt_config -logger = dt_logger.Logger('parser.py').getLogger() - class Parser: '''preprocess configuration files''' - @staticmethod - def parse_cmd(cmd, testcase): + logger = None + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.Parser').getLogger() + + @classmethod + def parse_cmd(cls, cmd, testcase): cmd_lines = None try: template = jinja2.Template(cmd, undefined=jinja2.StrictUndefined) kwargs = {} for arg in dt_config.dovetail_config['parameters']: path = eval(arg['path']) - logger.debug('name: %s, eval path: %s ' % (arg['name'], path)) + cls.logger.debug('name: %s, eval path: %s ' % + (arg['name'], path)) kwargs[arg['name']] = \ dt_utils.get_obj_by_path(testcase.testcase, path) - logger.debug('kwargs: %s' % kwargs) + cls.logger.debug('kwargs: %s' % kwargs) cmd_lines = template.render(**kwargs) except Exception as e: - logger.error('failed to parse cmd %s, exception:%s' % (cmd, e)) + cls.logger.error('failed to parse cmd %s, exception:%s' % (cmd, e)) return None return cmd_lines diff --git a/dovetail/report.py b/dovetail/report.py index 7dd8ba2d..52c8ebf9 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -16,8 +16,6 @@ import utils.dovetail_logger as dt_logger from conf.dovetail_config import DovetailConfig as dt_config from testcase import Testcase -logger = dt_logger.Logger('report.py').getLogger() - def get_pass_str(passed): if passed: @@ -30,17 +28,27 @@ class Report: results = {'functest': {}, 'yardstick': {}} + logger = None + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.Report').getLogger() + @staticmethod def check_result(testcase, db_result): checker = CheckerFactory.create(testcase.script_type()) checker.check(testcase, db_result) @classmethod - def generate_json(cls, scenario_yaml): + def generate_json(cls, testsuite_yaml, testarea): report_obj = {} - report_obj['scenario'] = scenario_yaml['name'] + report_obj['testsuite'] = testsuite_yaml['name'] report_obj['testcases_list'] = [] - for testcase_name in scenario_yaml['testcases_list']: + testarea_list = [] + for value in testsuite_yaml['testcases_list']: + if value is not None and (testarea == 'full' or testarea in value): + testarea_list.append(value) + for testcase_name in testarea_list: testcase = Testcase.get(testcase_name) testcase_in_rpt = {} testcase_in_rpt['name'] = testcase_name @@ -62,12 +70,12 @@ class Report: testcase.sub_testcase_passed(sub_test)) }) report_obj['testcases_list'].append(testcase_in_rpt) - logger.info(json.dumps(report_obj)) + cls.logger.info(json.dumps(report_obj)) return report_obj @classmethod - def generate(cls, scenario_yaml): - rpt_data = cls.generate_json(scenario_yaml) + def generate(cls, testsuite_yaml, testarea): + rpt_data = cls.generate_json(testsuite_yaml, testarea) rpt_text = '' split_line = '+-----------------------------------------------------' split_line += '---------------------+\n' @@ -76,7 +84,7 @@ class Report: +==========================================================================+\n\ | report |\n' rpt_text += split_line - rpt_text += '|scenario: %s\n' % rpt_data['scenario'] + rpt_text += '|testsuite: %s\n' % rpt_data['testsuite'] for testcase in rpt_data['testcases_list']: rpt_text += '| [testcase]: %s\t\t\t\t[%s]\n' % \ (testcase['name'], testcase['result']) @@ -87,21 +95,21 @@ class Report: (sub_test['name'], sub_test['result']) rpt_text += split_line - logger.info(rpt_text) + cls.logger.info(rpt_text) cls.save(rpt_text) return rpt_text # save to disk as default - @staticmethod - def save(report): + @classmethod + def save(cls, report): report_file_name = dt_config.dovetail_config['report_file'] try: with open(os.path.join(dt_config.dovetail_config['result_dir'], report_file_name), 'w') as report_file: report_file.write(report) - logger.info('save report to %s' % report_file_name) + cls.logger.info('save report to %s' % report_file_name) except Exception: - logger.error('Failed to save: %s' % report_file_name) + cls.logger.error('Failed to save: %s' % report_file_name) @classmethod def get_result(cls, testcase): @@ -117,11 +125,12 @@ class Report: if result is not None: cls.results[type][script_testcase] = result testcase.script_result_acquired(True) - logger.debug('testcase: %s -> result acquired' % script_testcase) + cls.logger.debug('testcase: %s -> result acquired' % + script_testcase) else: retry = testcase.increase_retry() - logger.debug('testcase: %s -> result acquired retry:%d' % - (script_testcase, retry)) + cls.logger.debug('testcase: %s -> result acquired retry:%d' % + (script_testcase, retry)) return result @@ -140,9 +149,15 @@ class CrawlerFactory: class FunctestCrawler: + logger = None + def __init__(self): self.type = 'functest' + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.FunctestCrawler').getLogger() + def crawl(self, testcase=None): store_type = \ dt_config.dovetail_config[self.type]['result']['store_type'] @@ -158,7 +173,7 @@ class FunctestCrawler: os.path.join(dovetail_config['result_dir'], dovetail_config[self.type]['result']['file_path']) if not os.path.exists(file_path): - logger.info('result file not found: %s' % file_path) + self.logger.info('result file not found: %s' % file_path) return None try: @@ -180,31 +195,37 @@ class FunctestCrawler: "duration": int(dur_sec_int), "tests": int(num_tests), "failures": failed_num, "errors": error_logs}} - logger.debug('Results: %s' % str(json_results)) + self.logger.debug('Results: %s' % str(json_results)) return json_results except Exception as e: - logger.error('Cannot read content from the file: %s, exception: %s' - % (file_path, e)) + self.logger.error('Cannot read content from the file: %s, ' + 'exception: %s' % (file_path, e)) return None def crawl_from_url(self, testcase=None): url = \ dt_config.dovetail_config[self.type]['result']['db_url'] % testcase - logger.debug("Query to rest api: %s" % url) + self.logger.debug("Query to rest api: %s" % url) try: data = json.load(urllib2.urlopen(url)) return data['results'][0] except Exception as e: - logger.error("Cannot read content from the url: %s, exception: %s" - % (url, e)) + self.logger.error("Cannot read content from the url: %s, " + "exception: %s" % (url, e)) return None class YardstickCrawler: + logger = None + def __init__(self): self.type = 'yardstick' + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.YardstickCrawler').getLogger() + def crawl(self, testcase=None): store_type = \ dt_config.dovetail_config[self.type]['result']['store_type'] @@ -218,18 +239,18 @@ class YardstickCrawler: file_path = os.path.join(dt_config.dovetail_config['result_dir'], testcase+'.out') if not os.path.exists(file_path): - logger.info('result file not found: %s' % file_path) + self.logger.info('result file not found: %s' % file_path) return None try: with open(file_path, 'r') as myfile: myfile.read() criteria = 'PASS' json_results = {'criteria': criteria} - logger.debug('Results: %s' % str(json_results)) + self.logger.debug('Results: %s' % str(json_results)) return json_results except Exception as e: - logger.error('Cannot read content from the file: %s, exception: %s' - % (file_path, e)) + self.logger.error('Cannot read content from the file: %s, ' + 'exception: %s' % (file_path, e)) return None def crawl_from_url(self, testcase=None): @@ -258,8 +279,13 @@ class ResultChecker: class FunctestChecker: - @staticmethod - def check(testcase, db_result): + logger = None + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.FunctestChecker').getLogger() + + def check(self, testcase, db_result): sub_testcase_list = testcase.sub_testcase() if not db_result: @@ -280,7 +306,7 @@ class FunctestChecker: all_passed = True for sub_testcase in sub_testcase_list: - logger.debug('check sub_testcase:%s' % sub_testcase) + self.logger.debug('check sub_testcase:%s' % sub_testcase) if sub_testcase in db_result['details']['errors']: testcase.sub_testcase_passed(sub_testcase, False) all_passed = False @@ -292,6 +318,12 @@ class FunctestChecker: class YardstickChecker: + logger = None + + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.YardstickChecker').getLogger() + @staticmethod def check(testcase, result): if not result: diff --git a/dovetail/run.py b/dovetail/run.py index 86194389..e908f3ab 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -13,19 +13,21 @@ import sys import utils.dovetail_logger as dt_logger - +from parser import Parser from container import Container from testcase import Testcase -from testcase import Scenario +from testcase import Testsuite from report import Report +from report import FunctestCrawler +from report import YardstickCrawler +from report import FunctestChecker +from report import YardstickChecker from conf.dovetail_config import DovetailConfig as dt_config -logger = dt_logger.Logger('run.py').getLogger() - -def load_scenario(scenario): - Scenario.load() - return Scenario.get(dt_config.SCENARIO_NAMING_FMT % scenario) +def load_testsuite(testsuite): + Testsuite.load() + return Testsuite.get(testsuite) def set_container_tags(option_str): @@ -40,12 +42,17 @@ def load_testcase(): Testcase.load() -def run_test(scenario): - for testcase_name in scenario['testcases_list']: +def run_test(testsuite, testarea, logger): + testarea_list = [] + for value in testsuite['testcases_list']: + if value is not None and (testarea == 'full' or testarea in value): + testarea_list.append(value) + + for testcase_name in testarea_list: logger.info('>>[testcase]: %s' % (testcase_name)) testcase = Testcase.get(testcase_name) if testcase is None: - logger.error('testcase %s is not defined in testcase folder, \ + logger.error('test case %s is not defined in testcase folder, \ skipping' % (testcase_name)) continue run_testcase = True @@ -82,7 +89,7 @@ def run_test(scenario): Report.check_result(testcase, db_result) -def validate_options(input_dict): +def validate_options(input_dict, logger): # for 'tag' option for key, value in input_dict.items(): if key == 'tag' and value is not None: @@ -101,24 +108,51 @@ def filter_env_options(input_dict): return envs_options +def create_logs(): + Container.create_log() + Parser.create_log() + Report.create_log() + FunctestCrawler.create_log() + YardstickCrawler.create_log() + FunctestChecker.create_log() + YardstickChecker.create_log() + Testcase.create_log() + Testsuite.create_log() + + def main(*args, **kwargs): - """Dovetail certification test entry!""" - logger.info('=======================================') - logger.info('Dovetail certification: %s!' % (kwargs['scenario'])) - logger.info('=======================================') - validate_options(kwargs) + """Dovetail compliance test entry!""" + create_logs() + logger = dt_logger.Logger('run').getLogger() + logger.info('================================================') + logger.info('Dovetail compliance: %s!' % (kwargs['testsuite'])) + logger.info('================================================') + validate_options(kwargs, logger) envs_options = filter_env_options(kwargs) dt_config.update_envs(envs_options) logger.info('Your new envs for functest: %s' % dt_config.dovetail_config['functest']['envs']) logger.info('Your new envs for yardstick: %s' % dt_config.dovetail_config['yardstick']['envs']) - load_testcase() - scenario_yaml = load_scenario(kwargs['scenario']) + if 'tag' in kwargs and kwargs['tag'] is not None: set_container_tags(kwargs['tag']) - run_test(scenario_yaml) - Report.generate(scenario_yaml) + + testarea = kwargs['testarea'] + testsuite_validation = False + testarea_validation = False + if (testarea == 'full') or (testarea in dt_config.testarea_supported): + testarea_validation = True + if kwargs['testsuite'] in dt_config.testsuite_supported: + testsuite_validation = True + if testsuite_validation and testarea_validation: + testsuite_yaml = load_testsuite(kwargs['testsuite']) + load_testcase() + run_test(testsuite_yaml, testarea, logger) + Report.generate(testsuite_yaml, testarea) + else: + logger.error('invalid input commands, testsuite %s testarea %s' % + (kwargs['testsuite'], testarea)) CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 6f0552b6..60ce2b28 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -15,11 +15,11 @@ import utils.dovetail_logger as dt_logger from parser import Parser from conf.dovetail_config import DovetailConfig as dt_config -logger = dt_logger.Logger('testcase.py').getLogger() - class Testcase: + logger = None + def __init__(self, testcase_yaml): self.testcase = testcase_yaml.values()[0] self.testcase['passed'] = False @@ -28,6 +28,10 @@ class Testcase: self.update_script_testcase(self.script_type(), self.script_testcase()) + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.Testcase').getLogger() + def prepare_cmd(self): script_type = self.script_type() for cmd in dt_config.dovetail_config[script_type]['testcase']['cmds']: @@ -52,7 +56,7 @@ class Testcase: def sub_testcase_passed(self, name, passed=None): if passed is not None: - logger.debug('sub_testcase_passed:%s %s' % (name, passed)) + self.logger.debug('sub_testcase_passed:%s %s' % (name, passed)) self.sub_testcase_status[name] = passed return self.sub_testcase_status[name] @@ -146,7 +150,7 @@ class Testcase: testcase_yaml = yaml.safe_load(f) cls.testcase_list[testcase_yaml.keys()[0]] = \ cls(testcase_yaml) - logger.debug(cls.testcase_list) + cls.logger.debug(cls.testcase_list) @classmethod def get(cls, testcase_name): @@ -155,31 +159,37 @@ class Testcase: return None -class Scenario: +class Testsuite: - def __init__(self, scenario): - self.scenario = scenario + logger = None + + def __init__(self, testsuite): + self.testsuite = testsuite self.testcase_list = {} + @classmethod + def create_log(cls): + cls.logger = dt_logger.Logger(__name__+'.Testsuite').getLogger() + def get_test(self, testcase_name): if testcase_name in self.testcase_list: return self.testcase_list[testcase_name] return None - scenario_list = {} + testsuite_list = {} @classmethod def load(cls): - for root, dirs, files in os.walk(dt_config.CERT_PATH): - for scenario_yaml in files: - with open(os.path.join(root, scenario_yaml)) as f: - scenario_yaml = yaml.safe_load(f) - cls.scenario_list.update(scenario_yaml) + for root, dirs, files in os.walk(dt_config.COMPLIANCE_PATH): + for testsuite_yaml in files: + with open(os.path.join(root, testsuite_yaml)) as f: + testsuite_yaml = yaml.safe_load(f) + cls.testsuite_list.update(testsuite_yaml) - logger.debug(cls.scenario_list) + cls.logger.debug(cls.testsuite_list) @classmethod - def get(cls, scenario_name): - if scenario_name in cls.scenario_list: - return cls.scenario_list[scenario_name] + def get(cls, testsuite_name): + if testsuite_name in cls.testsuite_list: + return cls.testsuite_list[testsuite_name] return None diff --git a/dovetail/utils/dovetail_logger.py b/dovetail/utils/dovetail_logger.py index 6a2d38d5..e725e612 100644 --- a/dovetail/utils/dovetail_logger.py +++ b/dovetail/utils/dovetail_logger.py @@ -40,7 +40,7 @@ clean_results_dir() class Logger: def __init__(self, logger_name): - CI_DEBUG = os.getenv('CI_DEBUG') + DEBUG = os.getenv('DEBUG') self.logger = logging.getLogger(logger_name) self.logger.propagate = 0 @@ -50,7 +50,7 @@ class Logger: formatter = logging.Formatter('%(asctime)s - %(name)s - ' '%(levelname)s - %(message)s') ch.setFormatter(formatter) - if CI_DEBUG is not None and CI_DEBUG.lower() == "true": + if DEBUG is not None and DEBUG.lower() == "true": ch.setLevel(logging.DEBUG) else: ch.setLevel(logging.INFO) |