unify test result check for feature project and apply to parser 07/18007/2
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Thu, 4 Aug 2016 03:25:15 +0000 (11:25 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Thu, 4 Aug 2016 07:06:18 +0000 (15:06 +0800)
add check_test_result() method to unify test result process

JIRA: FUNCTEST-405

Change-Id: Iee4d2876cbbf372f8c3e3bf94448036669bc7f7e
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
ci/testcases.yaml
testcases/vnf/RNC/parser.py
utils/functest_utils.py

index 315969a..221d2fc 100644 (file)
@@ -257,7 +257,7 @@ tiers:
                     scenario: '(ocl)|(nosdn)|^(os-odl)((?!bgpvpn).)*$'
             -
                 name: parser
-                criteria: 'status == "PASS"'
+                criteria: 'ret == 0'
                 blocking: false
                 description: >-
                     Test suite from Parser project.
index 485af0e..91d5bb0 100644 (file)
@@ -32,33 +32,18 @@ logger = ft_logger.Logger("parser").getLogger()
 
 
 def main():
-    EXIT_CODE = -1
     project = 'parser'
     case_name = 'parser-basics'
     cmd = 'cd %s/tests && ./functest_run.sh' % PARSER_REPO
-    start_time = time.time()
 
+    start_time = time.time()
     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
-
     stop_time = time.time()
-    duration = round(stop_time - start_time, 1)
-    if ret == 0:
-        EXIT_CODE = 0
-        logger.info("parser OK")
-        test_status = 'OK'
-    else:
-        logger.info("parser FAILED")
-        test_status = 'NOK'
-
-    details = {
-        'timestart': start_time,
-        'duration': duration,
-        'status': test_status,
-    }
 
-    status = "FAIL"
-    if details['status'] == "OK":
-        status = "PASS"
+    status, details = functest_utils.check_test_result(case_name,
+                                                       ret,
+                                                       start_time,
+                                                       stop_time)
 
     functest_utils.logger_test_results(logger,
                                        project,
@@ -73,7 +58,7 @@ def main():
                                       stop_time,
                                       status,
                                       details)
-    exit(EXIT_CODE)
+    exit(ret)
 
 if __name__ == '__main__':
     main()
index b001430..4373152 100644 (file)
@@ -353,16 +353,33 @@ def check_success_rate(case_name, success_rate):
     success_rate = float(success_rate)
     criteria = get_criteria_by_test(case_name)
 
-    def get_value(op):
+    def get_criteria_value(op):
         return float(criteria.split(op)[1].rstrip('%'))
 
     status = 'FAIL'
     ops = ['==', '>=']
     for op in ops:
         if op in criteria:
-            c_value = get_value(op)
+            c_value = get_criteria_value(op)
             if eval("%s %s %s" % (success_rate, op, c_value)):
                 status = 'PASS'
             break
 
     return status
+
+
+def check_test_result(test_name, ret, start_time, stop_time):
+    def get_criteria_value():
+        return get_criteria_by_test(test_name).split('==')[1].strip()
+
+    status = 'FAIL'
+    if str(ret) == get_criteria_value():
+        status = 'PASS'
+
+    details = {
+        'timestart': start_time,
+        'duration': round(stop_time - start_time, 1),
+        'status': status,
+    }
+
+    return status, details