diff options
author | Leo wang <grakiss.wanglei@huawei.com> | 2017-06-30 08:12:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-06-30 08:12:58 +0000 |
commit | a6112b4fdd288fee0e04f7821b94dcc533737b58 (patch) | |
tree | 80df16cd236ea5d0f52303f88d610e450049792e | |
parent | 686eeddb26e038665e8c874617257636ff0ac229 (diff) | |
parent | 3d35d647a3fe004cef094890145cbec2edeaf6e6 (diff) |
Merge "Modify Dovetail logs"
-rw-r--r-- | dovetail/container.py | 54 | ||||
-rw-r--r-- | dovetail/parser.py | 9 | ||||
-rw-r--r-- | dovetail/report.py | 47 | ||||
-rwxr-xr-x | dovetail/run.py | 40 | ||||
-rw-r--r-- | dovetail/test_runner.py | 36 | ||||
-rw-r--r-- | dovetail/testcase.py | 29 | ||||
-rw-r--r-- | dovetail/utils/dovetail_utils.py | 20 |
7 files changed, 127 insertions, 108 deletions
diff --git a/dovetail/container.py b/dovetail/container.py index 9f624f36..2108cdc1 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -42,7 +42,8 @@ class Container(object): return '%s:%s' % (dt_cfg.dovetail_config[type]['image_name'], dt_cfg.dovetail_config[type]['docker_tag']) except KeyError as e: - cls.logger.error('There is no %s in %s config file.', e, type) + cls.logger.exception( + 'There is no key {} in {} config file.'.format(e, type)) return None # get the openrc_volume for creating the container @@ -56,7 +57,8 @@ class Container(object): dovetail_config[type]['openrc']) return openrc else: - cls.logger.error("File %s is not exist", dovetail_config['openrc']) + cls.logger.error( + "File {} doesn't exist.".format(dovetail_config['openrc'])) return None # set functest envs and TEST_DB_URL for creating functest container @@ -113,14 +115,14 @@ class Container(object): pod_file = os.path.join(dovetail_config['config_dir'], dovetail_config['pod_file']) if not os.path.isfile(pod_file): - cls.logger.error("File %s doesn't exist.", pod_file) + cls.logger.error("File {} doesn't exist.".format(pod_file)) return None key_file = os.path.join(dovetail_config['config_dir'], dovetail_config['pri_key']) key_container_path = dovetail_config["yardstick"]['result']['key_path'] if not os.path.isfile(key_file): - cls.logger.debug("Key file %s is not found, maybe can use passwd " - "method in %s to do HA test.", key_file, pod_file) + cls.logger.debug("Key file {} is not found, must use password in " + "{} to do HA test.".format(key_file, pod_file)) key_vol = '' else: key_vol = '-v %s:%s ' % (key_file, key_container_path) @@ -166,11 +168,11 @@ class Container(object): for host in hosts_info['hosts_info']: hosts_config += " --add-host " hosts_config += str(host) - cls.logger.info('get hosts info %s', hosts_config) + cls.logger.info('Get hosts info {}.'.format(hosts_config)) except Exception: - cls.logger.warn('fail to get hosts info in %s/hosts.yaml, \ - maybe some issue with domain name resolution', - hosts_config_path) + cls.logger.warn('Failed to get hosts info in {}/hosts.yaml, ' + 'maybe some issues with domain name resolution.' + .format(hosts_config_path)) cacert_volume = "" https_enabled = dt_utils.check_https_enabled(cls.logger) @@ -179,13 +181,14 @@ class Container(object): cls.logger.info("https enabled...") if cacert is not None: if not os.path.isfile(cacert): - cls.logger.error("env variable 'OS_CACERT' is set to %s" - "but the file does not exist", cacert) + cls.logger.error("Env variable 'OS_CACERT' is set to {}" + "but the file does not exist." + .format(cacert)) return None elif not dovetail_config['config_dir'] in cacert: - cls.logger.error("credential file has to be put in %s," - "which can be mount into container", - dovetail_config['config_dir']) + cls.logger.error("Credential file has to be put in {}," + "which can be mount into container." + .format(dovetail_config['config_dir'])) return None cacert_volume = ' -v %s:%s ' % (cacert, cacert) else: @@ -227,15 +230,15 @@ class Container(object): cmd = "sudo docker ps -aq -f 'ancestor=%s'" % (image_id) ret, msg = dt_utils.exec_cmd(cmd, cls.logger) if msg and ret == 0: - cls.logger.debug('image %s has containers, skip.', image_id) + cls.logger.debug('Image {} has containers, skip.'.format(image_id)) return True cmd = 'sudo docker rmi %s' % (image_id) - cls.logger.debug('remove image %s', image_id) + cls.logger.debug('Remove image {}.'.format(image_id)) ret, msg = dt_utils.exec_cmd(cmd, cls.logger) if ret == 0: - cls.logger.debug('remove image %s successfully', image_id) + cls.logger.debug('Remove image {} successfully.'.format(image_id)) return True - cls.logger.error('fail to remove image %s.', image_id) + cls.logger.error('Failed to remove image {}.'.format(image_id)) return False @classmethod @@ -243,9 +246,10 @@ class Container(object): cmd = 'sudo docker pull %s' % (image_name) ret, msg = dt_utils.exec_cmd(cmd, cls.logger) if ret != 0: - cls.logger.error('fail to pull docker image %s!', image_name) + cls.logger.error( + 'Failed to pull docker image {}!'.format(image_name)) return False - cls.logger.debug('success to pull docker image %s!', image_name) + cls.logger.debug('Success to pull docker image {}!'.format(image_name)) return True @classmethod @@ -254,7 +258,8 @@ class Container(object): if not docker_image: return None if cls.has_pull_latest_image[validate_type] is True: - cls.logger.debug('%s is already the newest version.', docker_image) + cls.logger.debug( + '{} is already the newest version.'.format(docker_image)) return docker_image old_image_id = cls.get_image_id(docker_image) if not cls.pull_image_only(docker_image): @@ -262,13 +267,14 @@ class Container(object): cls.has_pull_latest_image[validate_type] = True new_image_id = cls.get_image_id(docker_image) if not new_image_id: - cls.logger.error("fail to get the new image's id %s", docker_image) + cls.logger.error( + "Failed to get the id of image {}.".format(docker_image)) return None if not old_image_id: return docker_image if new_image_id == old_image_id: - cls.logger.debug('image %s has no changes, no need to remove.', - docker_image) + cls.logger.debug('Image {} has no changes, no need to remove.' + .format(docker_image)) else: cls.remove_image(old_image_id) return docker_image diff --git a/dovetail/parser.py b/dovetail/parser.py index fdde4f9e..1b539c85 100644 --- a/dovetail/parser.py +++ b/dovetail/parser.py @@ -32,15 +32,16 @@ class Parser(object): kwargs = {} for arg in dt_cfg.dovetail_config['parameters']: path = eval(arg['path']) - cls.logger.debug('name: %s, eval path: %s ', - arg['name'], path) + cls.logger.debug( + 'name: {}, eval path: {}'.format(arg['name'], path)) kwargs[arg['name']] = \ dt_utils.get_obj_by_path(testcase.testcase, path) - cls.logger.debug('kwargs: %s', kwargs) + cls.logger.debug('kwargs: {}'.format(kwargs)) cmd_lines = template.render(**kwargs) except Exception as e: - cls.logger.error('failed to parse cmd %s, exception:%s', cmd, e) + cls.logger.exception( + 'Failed to parse cmd {}, exception: {}'.format(cmd, e)) return None return cmd_lines diff --git a/dovetail/report.py b/dovetail/report.py index b864de98..08780b88 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -112,8 +112,8 @@ class Report(object): '|'.join(dt_cfg.dovetail_config['testarea_supported'])) area = pattern.findall(testcase['name']) if not area: - cls.logger.error("testcase %s not in supported testarea", - testcase['name']) + cls.logger.error("Test case {} not in supported testarea." + .format(testcase['name'])) return None area = area[0] testarea_scope.append(area) @@ -170,9 +170,9 @@ class Report(object): with open(os.path.join(dt_cfg.dovetail_config['result_dir'], report_file_name), 'w') as report_file: report_file.write(report) - cls.logger.info('save report to %s', report_file_name) + cls.logger.info('Save report to {}'.format(report_file_name)) except Exception: - cls.logger.error('Failed to save: %s', report_file_name) + cls.logger.exception('Failed to save: {}'.format(report_file_name)) @classmethod def get_result(cls, testcase): @@ -180,7 +180,7 @@ class Report(object): type = testcase.validate_type() crawler = CrawlerFactory.create(type) if crawler is None: - cls.logger.error('crawler is None:%s', testcase.name()) + cls.logger.error('Crawler is None: {}'.format(testcase.name())) return None # if validate_testcase in cls.results[type]: @@ -191,12 +191,12 @@ class Report(object): if result is not None: cls.results[type][validate_testcase] = result # testcase.script_result_acquired(True) - cls.logger.debug('testcase: %s -> result acquired', - validate_testcase) + cls.logger.debug( + 'Test case: {} -> result acquired'.format(validate_testcase)) else: retry = testcase.increase_retry() - cls.logger.debug('testcase: %s -> result acquired retry:%d', - validate_testcase, retry) + cls.logger.debug('Test case: {} -> result acquired retry: {}' + .format(validate_testcase, retry)) return result @@ -206,7 +206,7 @@ class FunctestCrawler(object): def __init__(self): self.type = 'functest' - self.logger.debug('create crawler:%s', self.type) + self.logger.debug('Create crawler: {}'.format(self.type)) @classmethod def create_log(cls): @@ -234,14 +234,15 @@ class FunctestCrawler(object): os.path.join(dovetail_config['result_dir'], dovetail_config[self.type]['result']['file_path']) if not os.path.exists(file_path): - self.logger.info('result file not found: %s', file_path) + self.logger.error('Result file not found: {}'.format(file_path)) return None if testcase_name in dt_cfg.dovetail_config['functest_testcase']: complex_testcase = False elif testcase_name in dt_cfg.dovetail_config['functest_testsuite']: complex_testcase = True else: - self.logger.error("Wrong Functest test case %s.", testcase_name) + self.logger.error( + "Wrong Functest test case {}.".format(testcase_name)) return None with open(file_path, 'r') as f: for jsonfile in f: @@ -264,7 +265,8 @@ class FunctestCrawler(object): "errors": error_case, "skipped": skipped_case} except KeyError as e: - self.logger.error("Result data don't have key %s.", e) + self.logger.exception( + "Result data don't have key {}.".format(e)) return None except ValueError: continue @@ -273,20 +275,20 @@ class FunctestCrawler(object): 'timestop': timestop, 'duration': duration, 'details': details} - self.logger.debug('Results: %s', str(json_results)) + self.logger.debug('Results: {}'.format(str(json_results))) return json_results def crawl_from_url(self, testcase=None): url = "%s?case=%s&last=1" % \ (dt_cfg.dovetail_config['report_dest'], testcase.validate_testcase()) - self.logger.debug("Query to rest api: %s", url) + self.logger.debug("Query to rest api: {}".format(url)) try: data = json.load(urllib2.urlopen(url)) return data['results'][0] except Exception as e: - self.logger.error("Cannot read content from the url: %s, " - "exception: %s", url, e) + self.logger.exception("Cannot read content from the url: {}, " + "exception: {}".format(url, e)) return None @@ -296,7 +298,7 @@ class YardstickCrawler(object): def __init__(self): self.type = 'yardstick' - self.logger.debug('create crawler:%s', self.type) + self.logger.debug('Create crawler: {}'.format(self.type)) @classmethod def create_log(cls): @@ -315,7 +317,7 @@ class YardstickCrawler(object): file_path = os.path.join(dt_cfg.dovetail_config['result_dir'], testcase.name() + '.out') if not os.path.exists(file_path): - self.logger.info('result file not found: %s', file_path) + self.logger.error('Result file not found: {}'.format(file_path)) return None criteria = 'FAIL' with open(file_path, 'r') as f: @@ -327,9 +329,10 @@ class YardstickCrawler(object): if 1 == v: criteria = 'PASS' except KeyError as e: - self.logger.error('pass flag not found %s', e) + self.logger.exception( + 'Pass flag not found {}'.format(e)) json_results = {'criteria': criteria} - self.logger.debug('Results: %s', str(json_results)) + self.logger.debug('Results: {}'.format(str(json_results))) return json_results def crawl_from_url(self, testcase=None): @@ -420,7 +423,7 @@ class FunctestChecker(object): testcase_passed = 'SKIP' for sub_testcase in sub_testcase_list: - self.logger.debug('check sub_testcase:%s', sub_testcase) + self.logger.debug('Check sub_testcase: {}'.format(sub_testcase)) try: if self.get_sub_testcase(sub_testcase, db_result['details']['errors']): diff --git a/dovetail/run.py b/dovetail/run.py index a8fa6470..5c0b2ddb 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -46,11 +46,11 @@ def run_test(testsuite, testarea, logger): duration = 0 start_time = time.time() for testcase_name in testarea_list: - logger.info('>>[testcase]: %s', testcase_name) + logger.info('>>[testcase]: {}'.format(testcase_name)) testcase = Testcase.get(testcase_name) if testcase is None: - logger.error('test case %s is not defined in testcase folder, \ - skipping', testcase_name) + logger.error('Test case {} is not defined in testcase folder, ' + 'skipping.'.format(testcase_name)) continue run_testcase = True @@ -82,21 +82,23 @@ def check_tc_result(testcase, logger): testcase.name(), dovetail_result, logger): logger.info("Results have been pushed to database and stored " - "with local file %s.", dovetail_result) + "with local file {}.".format(dovetail_result)) else: - logger.error("Fail to push results to database.") + logger.error("Failed to push results to database.") if dt_cfg.dovetail_config['report_dest'] == "file": if validate_type.lower() == 'yardstick': result_file = os.path.join(result_dir, testcase.name() + '.out') elif validate_type.lower() == 'functest': result_file = os.path.join(result_dir, functest_result) else: - logger.error("Don't support %s now.", validate_type) + logger.error("Don't support {} now.".format(validate_type)) return if os.path.isfile(result_file): - logger.info("Results have been stored with file %s.", result_file) + logger.info( + "Results have been stored with file {}.".format(result_file)) else: - logger.error("Fail to store results with file %s.", result_file) + logger.error( + "Failed to store results with file {}.".format(result_file)) result = Report.get_result(testcase) Report.check_result(testcase, result) @@ -107,18 +109,20 @@ def validate_input(input_dict, check_dict, logger): yard_tag = input_dict['yard_tag'] valid_tag = check_dict['valid_docker_tag'] if func_tag is not None and func_tag not in valid_tag: - logger.error("func_tag can't be %s, valid in %s", func_tag, valid_tag) + logger.error("The input option 'func_tag' can't be {}, " + "valid values are {}.".format(func_tag, valid_tag)) raise SystemExit(1) if yard_tag is not None and yard_tag not in valid_tag: - logger.error("yard_tag can't be %s, valid in %s", yard_tag, valid_tag) + logger.error("The input option 'yard_tag' can't be {}, " + "valid values are {}.".format(yard_tag, valid_tag)) raise SystemExit(1) # for 'report' option report = input_dict['report'] if report: if not (report.startswith("http") or report == "file"): - logger.error("report can't be %s", input_dict['report']) - logger.info("valid report types are 'file' and 'http'") + logger.error("Report type can't be {}, valid types are 'file' " + "and 'http'.".format(input_dict['report'])) raise SystemExit(1) @@ -147,7 +151,7 @@ def filter_config(input_dict, logger): configs[key.upper()] = value_dict break except KeyError as e: - logger.exception('%s lacks subsection %s', config_key, e) + logger.exception('KeyError {}.'.format(e)) raise SystemExit(1) if not configs: return None @@ -210,7 +214,7 @@ def env_init(logger): openrc = os.path.join(dt_cfg.dovetail_config['config_dir'], dt_cfg.dovetail_config['env_file']) if not os.path.isfile(openrc): - logger.error("openrc file %s does not exist", openrc) + logger.error("File {} does not exist.".format(openrc)) dt_utils.source_env(openrc) @@ -226,9 +230,9 @@ def main(*args, **kwargs): create_logs() logger = dt_logger.Logger('run').getLogger() logger.info('================================================') - logger.info('Dovetail compliance: %s!', (kwargs['testsuite'])) + logger.info('Dovetail compliance: {}!'.format(kwargs['testsuite'])) logger.info('================================================') - logger.info('Build tag: %s', dt_cfg.dovetail_config['build_tag']) + logger.info('Build tag: {}'.format(dt_cfg.dovetail_config['build_tag'])) env_init(logger) copy_userconfig_files(logger) dt_utils.check_docker_version(logger) @@ -263,8 +267,8 @@ def main(*args, **kwargs): if dt_cfg.dovetail_config['report_dest'] == "file": Report.generate(testsuite_yaml, testarea, duration) else: - logger.error('invalid input commands, testsuite %s testarea %s', - kwargs['testsuite'], testarea) + logger.error('Invalid input commands, testsuite {} testarea {}' + .format(kwargs['testsuite'], testarea)) dt_cfg.load_config_files() diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index 6ae410c1..b3fd7a3f 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -22,7 +22,7 @@ class DockerRunner(object): def __init__(self, testcase): self.testcase = testcase - self.logger.debug('create runner: %s', self.type) + self.logger.debug('Create runner: {}'.format(self.type)) @classmethod def create_log(cls): @@ -31,8 +31,8 @@ class DockerRunner(object): def pre_copy(self, container_id=None, dest_path=None, src_file=None, exist_file=None): if not dest_path: - self.logger.error("There has no dest_path in %s config file.", - self.testcase.name()) + self.logger.error("There has no dest_path in {} config file." + .format(self.testcase.name())) return None if src_file: self.testcase.mk_src_file() @@ -49,8 +49,8 @@ class DockerRunner(object): if dt_cfg.dovetail_config['offline']: exist = Container.check_image_exist(self.testcase.validate_type()) if not exist: - self.logger.error('%s image not exist when running offline', - self.testcase.validate_type()) + self.logger.error("{} image doesn't exist, can't run offline." + .format(self.testcase.validate_type())) return else: if not Container.pull_image(self.testcase.validate_type()): @@ -63,15 +63,15 @@ class DockerRunner(object): img_file = os.path.join(dt_cfg.dovetail_config['config_dir'], img_name) if not os.path.isfile(img_file): - self.logger.error('image %s not found', img_name) + self.logger.error('Image {} not found.'.format(img_name)) return container_id = Container.create(self.testcase.validate_type(), self.testcase.name()) if not container_id: - self.logger.error('failed to create container') + self.logger.error('Failed to create container.') return - self.logger.debug('container id:%s', container_id) + self.logger.debug('container id: {}'.format(container_id)) dest_path = self.testcase.pre_copy_path("dest_path") src_file_name = self.testcase.pre_copy_path("src_file") @@ -95,14 +95,14 @@ class DockerRunner(object): self.testcase.prepared(True) if not self.testcase.prepare_cmd(self.type): - self.logger.error('failed to prepare testcase:%s', - self.testcase.name()) + self.logger.error( + 'Failed to prepare test case: {}'.format(self.testcase.name())) else: for cmd in self.testcase.cmds: ret, msg = Container.exec_cmd(container_id, cmd) if ret != 0: - self.logger.error('Failed to exec %s, ret:%d, msg:%s', - cmd, ret, msg) + self.logger.error('Failed to exec {}, ret: {}, msg: {}' + .format(cmd, ret, msg)) break cmds = self.testcase.post_condition() @@ -140,7 +140,7 @@ class ShellRunner(object): super(ShellRunner, self).__init__() self.testcase = testcase self.type = 'shell' - self.logger.debug('create runner:%s', self.type) + self.logger.debug('Create runner: {}'.format(self.type)) def run(self): testcase_passed = 'PASS' @@ -158,8 +158,8 @@ class ShellRunner(object): self.testcase.prepared(True) if not self.testcase.prepare_cmd(self.type): - self.logger.error('failed to prepare cmd:%s', - self.testcase.name()) + self.logger.error( + 'Failed to prepare cmd: {}'.format(self.testcase.name())) else: for cmd in self.testcase.cmds: ret, msg = dt_utils.exec_cmd(cmd, self.logger) @@ -176,13 +176,13 @@ class ShellRunner(object): result_filename = os.path.join(dt_cfg.dovetail_config['result_dir'], self.testcase.name()) + '.out' - self.logger.debug('save result:%s', result_filename) + self.logger.debug('Save result: {}'.format(result_filename)) try: with open(result_filename, 'w') as f: f.write(json.dumps(result)) except Exception as e: - self.logger.exception('Failed to write result into file:%s, \ - except:%s', result_filename, e) + self.logger.exception('Failed to write result into file: {}, ' + 'exception: {}'.format(result_filename, e)) class TestRunnerFactory(object): diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 2ceb8f20..7b012c88 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -39,7 +39,7 @@ class Testcase(object): return False # self.logger.debug('cmd_lines:%s', cmd_lines) self.cmds.append(cmd_lines) - self.logger.debug('cmds:%s', self.cmds) + self.logger.debug('cmds: {}'.format(self.cmds)) return True def prepare_cmd(self, test_type): @@ -55,7 +55,7 @@ class Testcase(object): return self.parse_cmd(testcase_cmds) if config_cmds: return self.parse_cmd(config_cmds) - self.logger.error('testcase %s has no cmds', self.name()) + self.logger.error('Test case {} has no cmds.'.format(self.name())) return False def __str__(self): @@ -75,7 +75,8 @@ class Testcase(object): def sub_testcase_passed(self, name, passed=None): if passed is not None: - self.logger.debug('sub_testcase_passed:%s %s', name, passed) + self.logger.debug( + 'sub_testcase_passed: {} {}'.format(name, passed)) self.sub_testcase_status[name] = passed return self.sub_testcase_status[name] @@ -111,8 +112,8 @@ class Testcase(object): return pre_condition pre_condition = self.pre_condition_cls(self.validate_type()) if not pre_condition: - self.logger.debug('testcase:%s pre_condition is empty', - self.name()) + self.logger.debug( + 'Test case: {} pre_condition is empty.'.format(self.name())) return pre_condition def pre_copy_path(self, key_name): @@ -131,8 +132,8 @@ class Testcase(object): return post_condition post_condition = self.post_condition_cls(self.validate_type()) if not post_condition: - self.logger.debug('testcae:%s post_condition is empty', - self.name()) + self.logger.debug( + 'Test case: {} post_condition is empty.'.format(self.name())) return post_condition def mk_src_file(self): @@ -143,12 +144,13 @@ class Testcase(object): with open(file_path, 'w+') as src_file: if self.sub_testcase() is not None: for sub_test in self.sub_testcase(): - self.logger.debug('save testcases %s', sub_test) + self.logger.debug( + 'Save test cases {}'.format(sub_test)) src_file.write(sub_test + '\n') - self.logger.debug('save testcases to %s', file_path) + self.logger.debug('Save test cases to {}'.format(file_path)) return file_path except Exception: - self.logger.error('Failed to save: %s', file_path) + self.logger.exception('Failed to save: {}'.format(file_path)) return None def run(self): @@ -156,7 +158,8 @@ class Testcase(object): try: runner.run() except AttributeError as e: - self.logger.exception('testcase:%s except:%s', self.name, e) + self.logger.exception( + 'Test case: {} Exception: {}'.format(self.name, e)) # testcase in upstream testing project # validate_testcase_list = {'functest': {}, 'yardstick': {}, 'shell': {}} @@ -230,8 +233,8 @@ class Testcase(object): cls.testcase_list[next(testcase_yaml.iterkeys())] = \ testcase else: - cls.logger.error('failed to create testcase: %s', - testcase_file) + cls.logger.error('Failed to create test case: {}' + .format(testcase_file)) @classmethod def get(cls, testcase_name): diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index aeb8ea00..8112d28d 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -119,7 +119,7 @@ def source_env(env_file): def check_https_enabled(logger=None): - logger.info("checking if https enabled or not...") + logger.debug("Checking if https enabled or not...") cmd = "openstack catalog show identity |awk '/public/ {print $4}'| \ grep 'https'" ret, msg = exec_cmd(cmd, logger) @@ -135,13 +135,14 @@ def get_ext_net_name(env_file, logger=None): if insecure.lower() == "true": insecure_option = ' --insecure ' else: - logger.warn("env variable OS_INSECURE is %s, if https + no" - "credential used, should be set as True" % insecure) + logger.warn("Env variable OS_INSECURE is {}, if https + no " + "credential used, should be set as True." + .format(insecure)) cmd_check = "openstack %s network list" % insecure_option ret, msg = exec_cmd(cmd_check, logger) if ret: - logger.error("The credentials info in %s is invalid." % env_file) + logger.error("The credentials info in {} is invalid.".format(env_file)) return None cmd = "openstack %s network list --long | grep 'External' | head -1 | \ awk '{print $4}'" % insecure_option @@ -153,7 +154,7 @@ def get_ext_net_name(env_file, logger=None): def store_db_results(db_url, build_tag, testcase, dest_file, logger): url = "%s?build_tag=%s-%s" % (db_url, build_tag, testcase) - logger.debug("Query to rest api: %s", url) + logger.debug("Query to rest api: {}".format(url)) try: data = json.load(urllib2.urlopen(url)) if data['results']: @@ -163,7 +164,8 @@ def store_db_results(db_url, build_tag, testcase, dest_file, logger): else: return False except Exception as e: - logger.error("Cannot read content from %s, exception: %s", url, e) + logger.exception( + "Cannot read content from {}, exception: {}".format(url, e)) return False @@ -176,7 +178,7 @@ def get_duration(start_date, stop_date, logger): res = "%sm%ss" % (delta / 60, delta % 60) return res except ValueError as e: - logger.error("ValueError: %s", e) + logger.exception("ValueError: {}".format(e)) return None @@ -195,12 +197,12 @@ def check_docker_version(logger=None): client_ret, client_ver = \ exec_cmd("sudo docker version -f'{{.Client.Version}}'", logger=logger) if server_ret == 0: - logger.debug("docker server version: %s", server_ver) + logger.debug("docker server version: {}".format(server_ver)) if server_ret != 0 or (LooseVersion(server_ver) < LooseVersion('1.12.3')): logger.error("Don't support this Docker server version. " "Docker server should be updated to at least 1.12.3.") if client_ret == 0: - logger.debug("docker client version: %s", client_ver) + logger.debug("docker client version: {}".format(client_ver)) if client_ret != 0 or (LooseVersion(client_ver) < LooseVersion('1.12.3')): logger.error("Don't support this Docker client version. " "Docker client should be updated to at least 1.12.3.") |