diff options
author | Linghui Zeng <linghui.zeng@huawei.com> | 2016-11-14 10:29:21 +0800 |
---|---|---|
committer | Linghui Zeng <linghui.zeng@huawei.com> | 2016-11-15 12:35:55 +0000 |
commit | b90fc8907f0c4ba716d6332159f881f880965277 (patch) | |
tree | ef45a29df64a4d401c796e6da6ede3c5f857af00 | |
parent | 64b221bee631cf52bf6a1109c16f9544eff58f80 (diff) |
dovetail tool: replace the hard-coded "Tescase" and modify some classmethod
JIRA: DOVETAIL-45
1. In the testcase.py file, we replace the hard-coded "Tesecase" with "cls" or "self" based on
the specific contexts.
2. For all the four committed files, we modify some classmethod into staticmethod because each
method is basically just a function, called syntactically like a method, but without access
to the object and its' internals (attributes and other methods).
Change-Id: Ieb452f476a2d33ae9aca4c904ae7d2c92b68689e
Signed-off-by: Linghui Zeng <linghui.zeng@huawei.com>
-rw-r--r-- | dovetail/container.py | 12 | ||||
-rw-r--r-- | dovetail/parser.py | 4 | ||||
-rw-r--r-- | dovetail/report.py | 25 | ||||
-rw-r--r-- | dovetail/testcase.py | 29 |
4 files changed, 36 insertions, 34 deletions
diff --git a/dovetail/container.py b/dovetail/container.py index 6d7ac94d..57ce2144 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -29,8 +29,8 @@ class Container: def get(cls, type): return cls.container_list[type] - @classmethod - def get_docker_image(cls, type): + @staticmethod + def get_docker_image(type): return '%s:%s' % (dovetail_config[type]['image_name'], dovetail_config[type]['docker_tag']) @@ -62,14 +62,14 @@ class Container: dt_utils.exec_cmd(cmd, logger) cls.has_pull_latest_image[type] = True - @classmethod - def clean(cls, container_id): + @staticmethod + def clean(container_id): cmd1 = 'sudo docker stop %s' % (container_id) dt_utils.exec_cmd(cmd1, logger) cmd2 = 'sudo docker rm %s' % (container_id) dt_utils.exec_cmd(cmd2, logger) - @classmethod - def exec_cmd(cls, container_id, sub_cmd, exit_on_error=False): + @staticmethod + def exec_cmd(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) diff --git a/dovetail/parser.py b/dovetail/parser.py index a9edb36e..621d20a3 100644 --- a/dovetail/parser.py +++ b/dovetail/parser.py @@ -20,8 +20,8 @@ logger = dt_logger.Logger('parser.py').getLogger() class Parser: '''preprocess configuration files''' - @classmethod - def parse_cmd(cls, cmd, testcase): + @staticmethod + def parse_cmd(cmd, testcase): cmd_lines = None try: template = jinja2.Template(cmd, undefined=jinja2.StrictUndefined) diff --git a/dovetail/report.py b/dovetail/report.py index 127c191d..a828d4f3 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -30,8 +30,8 @@ class Report: results = {'functest': {}, 'yardstick': {}} - @classmethod - def check_result(cls, testcase, db_result): + @staticmethod + def check_result(testcase, db_result): checker = CheckerFactory.create(testcase.script_type()) checker.check(testcase, db_result) @@ -92,8 +92,8 @@ class Report: return rpt_text # save to disk as default - @classmethod - def save(cls, report): + @staticmethod + def save(report): report_file_name = dovetail_config['report_file'] try: with open(os.path.join(dovetail_config['result_dir'], @@ -127,8 +127,8 @@ class Report: class CrawlerFactory: - @classmethod - def create(cls, type): + @staticmethod + def create(type): if type == 'functest': return FunctestCrawler() @@ -234,8 +234,8 @@ class YardstickCrawler: class CheckerFactory: - @classmethod - def create(cls, type): + @staticmethod + def create(type): if type == 'functest': return FunctestChecker() @@ -247,13 +247,15 @@ class CheckerFactory: class ResultChecker: - def check(cls): + @staticmethod + def check(): return 'PASS' class FunctestChecker: - def check(cls, testcase, db_result): + @staticmethod + def check(testcase, db_result): sub_testcase_list = testcase.sub_testcase() if not db_result: @@ -286,7 +288,8 @@ class FunctestChecker: class YardstickChecker: - def check(cls, testcase, result): + @staticmethod + def check(testcase, result): if not result: testcase.passed(False) else: diff --git a/dovetail/testcase.py b/dovetail/testcase.py index d505420a..b1c3b621 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -27,8 +27,8 @@ class Testcase: self.testcase['passed'] = False self.cmds = [] self.sub_testcase_status = {} - Testcase.update_script_testcase(self.script_type(), - self.script_testcase()) + self.update_script_testcase(self.script_type(), + self.script_testcase()) def prepare_cmd(self): for cmd in dovetail_config[self.script_type()]['testcase']['cmds']: @@ -65,14 +65,13 @@ class Testcase: def exceed_max_retry_times(self): # logger.debug('retry times:%d' % self.testcase['retry']) - return Testcase._exceed_max_retry_times(self.script_type(), - self.script_testcase()) + return self._exceed_max_retry_times(self.script_type(), + self.script_testcase()) def increase_retry(self): # self.testcase['retry'] = self.testcase['retry'] + 1 # return self.testcase['retry'] - return Testcase._increase_retry(self.script_type(), - self.script_testcase()) + return self._increase_retry(self.script_type(), self.script_testcase()) def passed(self, passed=None): if passed is not None: @@ -80,14 +79,14 @@ class Testcase: return self.testcase['passed'] def script_result_acquired(self, acquired=None): - return Testcase._result_acquired(self.script_type(), - self.script_testcase(), acquired) + return self._result_acquired(self.script_type(), + self.script_testcase(), acquired) def pre_condition(self): - return Testcase.pre_condition_cls(self.script_type()) + return self.pre_condition_cls(self.script_type()) def post_condition(self): - return Testcase.post_condition_cls(self.script_type()) + return self.post_condition_cls(self.script_type()) # testcase in upstream testing project script_testcase_list = {'functest': {}, 'yardstick': {}} @@ -107,12 +106,12 @@ class Testcase: cls.scrpit_testcase_list[script_type]['cleaned'] = cleaned return cls.script_testcase_list[script_type]['cleaned'] - @classmethod - def pre_condition_cls(cls, script_type): + @staticmethod + def pre_condition_cls(script_type): return dovetail_config[script_type]['pre_condition'] - @classmethod - def post_condition_cls(cls, script_type): + @staticmethod + def post_condition_cls(script_type): return dovetail_config[script_type]['post_condition'] @classmethod @@ -147,7 +146,7 @@ class Testcase: with open(os.path.join(root, testcase_file)) as f: testcase_yaml = yaml.safe_load(f) cls.testcase_list[testcase_yaml.keys()[0]] = \ - Testcase(testcase_yaml) + cls(testcase_yaml) logger.debug(cls.testcase_list) @classmethod |