dovetail tool: replace the hard-coded "Tescase" and modify some classmethod 01/24301/2
authorLinghui Zeng <linghui.zeng@huawei.com>
Mon, 14 Nov 2016 02:29:21 +0000 (10:29 +0800)
committerLinghui Zeng <linghui.zeng@huawei.com>
Tue, 15 Nov 2016 12:35:55 +0000 (12:35 +0000)
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>
dovetail/container.py
dovetail/parser.py
dovetail/report.py
dovetail/testcase.py

index 6d7ac94..57ce214 100644 (file)
@@ -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)
index a9edb36..621d20a 100644 (file)
@@ -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)
index 127c191..a828d4f 100644 (file)
@@ -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:
index d505420..b1c3b62 100644 (file)
@@ -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