Add gauge metrics for Functest reporting dashboard
[releng.git] / utils / test / reporting / functest / reporting-status.py
old mode 100644 (file)
new mode 100755 (executable)
index b76f783..ef567f1
@@ -34,7 +34,7 @@ tempest = tc.TestCase("tempest_smoke_serial", "functest", -1)
 cf = conf.TEST_CONF
 response = requests.get(cf)
 
-functest_yaml_config = yaml.load(response.text)
+functest_yaml_config = yaml.safe_load(response.text)
 
 logger.info("*******************************************")
 logger.info("*   Generating reporting scenario status  *")
@@ -99,8 +99,9 @@ for version in conf.versions:
                 for test_case in testValid:
                     test_case.checkRunnable(installer, s,
                                             test_case.getConstraints())
-                    logger.debug("testcase %s is %s" %
+                    logger.debug("testcase %s (%s) is %s" %
                                  (test_case.getDisplayName(),
+                                  test_case.getName(),
                                   test_case.isRunnable))
                     time.sleep(1)
                     if test_case.isRunnable:
@@ -112,28 +113,29 @@ for version in conf.versions:
                         logger.info(" Searching results for case %s " %
                                     (displayName))
                         result = utils.getResult(dbName, installer, s, version)
-                        # at least 1 result for the test
-                        if result > -1:
-                            logger.info(" >>>> Test score = " + str(result))
-                            test_case.setCriteria(result)
-                            test_case.setIsRunnable(True)
-                            testCases2BeDisplayed.append(tc.TestCase(name,
-                                                                     project,
-                                                                     "",
-                                                                     result,
-                                                                     True,
-                                                                     1))
-                            scenario_score = scenario_score + result
-                        else:
-                            logger.debug("No results found")
+                        # if no result set the value to 0
+                        if result < 0:
+                            result = 0
+                        logger.info(" >>>> Test score = " + str(result))
+                        test_case.setCriteria(result)
+                        test_case.setIsRunnable(True)
+                        testCases2BeDisplayed.append(tc.TestCase(name,
+                                                                 project,
+                                                                 "",
+                                                                 result,
+                                                                 True,
+                                                                 1))
+                        scenario_score = scenario_score + result
 
                 # 2) Manage the test cases for the scenario qualification
                 # concretely Tiers > 3
                 for test_case in otherTestCases:
                     test_case.checkRunnable(installer, s,
                                             test_case.getConstraints())
-                    logger.info("testcase %s is %s" %
-                                (test_case.getName(), test_case.isRunnable))
+                    logger.debug("testcase %s (%s) is %s" %
+                                 (test_case.getDisplayName(),
+                                  test_case.getName(),
+                                  test_case.isRunnable))
                     time.sleep(1)
                     if test_case.isRunnable:
                         dbName = test_case.getDbName()
@@ -173,6 +175,8 @@ for version in conf.versions:
                 scenario_criteria = conf.MAX_SCENARIO_CRITERIA
 
             s_score = str(scenario_score) + "/" + str(scenario_criteria)
+            s_score_percent = float(
+                scenario_score) / float(scenario_criteria) * 100
             s_status = "KO"
             if scenario_score < scenario_criteria:
                 logger.info(">>>> scenario not OK, score = %s/%s" %
@@ -181,7 +185,7 @@ for version in conf.versions:
             else:
                 logger.info(">>>>> scenario OK, save the information")
                 s_status = "OK"
-                path_validation_file = ("./release/" + version +
+                path_validation_file = (conf.REPORTING_PATH + "/release/" + version +
                                         "/validated_scenario_history.txt")
                 with open(path_validation_file, "a") as f:
                     time_format = "%Y-%m-%d %H:%M"
@@ -189,11 +193,13 @@ for version in conf.versions:
                             ";" + installer + ";" + s + "\n")
                     f.write(info)
 
-            scenario_result_criteria[s] = sr.ScenarioResult(s_status, s_score)
+            scenario_result_criteria[s] = sr.ScenarioResult(s_status, s_score,
+                                                            s_score_percent)
             logger.info("--------------------------")
 
         templateLoader = jinja2.FileSystemLoader(conf.REPORTING_PATH)
-        templateEnv = jinja2.Environment(loader=templateLoader)
+        templateEnv = jinja2.Environment(
+            loader=templateLoader, autoescape=True)
 
         TEMPLATE_FILE = "/template/index-status-tmpl.html"
         template = templateEnv.get_template(TEMPLATE_FILE)