kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: kafka-2005; Generate html report for system tests; patched by Ashish Singh; reviewed by Jun Rao
Date Thu, 11 Jun 2015 22:27:57 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 9f80665ec -> ab76dbd1f


kafka-2005; Generate html report for system tests; patched by Ashish Singh; reviewed by Jun
Rao


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/ab76dbd1
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/ab76dbd1
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/ab76dbd1

Branch: refs/heads/trunk
Commit: ab76dbd1f7f0bfdc9841baee64cfa37de1d870fb
Parents: 9f80665
Author: Ashish Singh <asingh@cloudera.com>
Authored: Thu Jun 11 15:27:51 2015 -0700
Committer: Jun Rao <junrao@gmail.com>
Committed: Thu Jun 11 15:27:51 2015 -0700

----------------------------------------------------------------------
 system_test/system_test_runner.py | 135 ++++++++++++++++++++++++++++++++-
 1 file changed, 131 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/ab76dbd1/system_test/system_test_runner.py
----------------------------------------------------------------------
diff --git a/system_test/system_test_runner.py b/system_test/system_test_runner.py
index 5078d44..d6251b2 100644
--- a/system_test/system_test_runner.py
+++ b/system_test/system_test_runner.py
@@ -52,6 +52,131 @@ logging.config.fileConfig('logging.conf')
 # message to facilitate debugging.
 d = {'name_of_class': '(system_test_runner)'}
 
+class report:
+  systemTestEnv = None
+  reportString = ""
+  reportFileName = "system_test_report.html"
+  systemTestReport = None
+  header = """<head>
+  <title>Kafka System Test Report</title>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
+  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
+  </head>"""
+  footer = """ """
+
+  def __init__(self, systemTestEnv):
+    self.totalSkipped = 0
+    self.totalPassed = 0
+    self.totalTests = 0
+    self.totalFailed = 0
+    self.systemTestEnv = systemTestEnv
+    self.systemTestReport = open(self.reportFileName, 'w')
+
+  def __del__(self):
+    self.systemTestReport.close()
+    self.systemTestReport = None
+
+  def writeHtmlPage(self, body):
+    html = """
+    <!DOCTYPE html>
+    <html lang="en">
+    """
+    html += self.header
+    html += body
+    html += self.footer
+    html += """
+    </html>
+    """
+    self.systemTestReport.write(html)
+
+  def wrapIn(self, tag, content):
+    html = "\n<" + tag + ">"
+    html += "\n  " + content
+    html += "\n</" + tag.split(" ")[0] + ">"
+    return html
+
+  def genModal(self, className, caseName, systemTestResult):
+    key = "validation_status"
+    id = className + "_" + caseName
+    info = self.wrapIn("h4", "Validation Status")
+    for validatedItem in sorted(systemTestResult[key].iterkeys()):
+      testItemStatus = systemTestResult[key][validatedItem]
+      info += validatedItem + " : " + testItemStatus
+    return self.wrapIn("div class=\"modal fade\" id=\"" + id + "\" tabindex=\"-1\" role=\"dialog\"
aria-labelledby=\"" + id + "Label\" aria-hidden=\"true\"",
+                       self.wrapIn("div class=\"modal-dialog\"",
+                                   self.wrapIn("div class=\"modal-content\"",
+                                               self.wrapIn("div class=\"modal-header\"",
+                                                           self.wrapIn("h4 class=\"modal-title\"
id=\"" + id + "Label\"",
+                                                                       className + " - "
+ caseName)) +
+                                                self.wrapIn("div class=\"modal-body\"",
+                                                            info) +
+                                                self.wrapIn("div class=\"modal-footer\"",
+                                                            self.wrapIn("button type=\"button\"
class=\"btn btn-default\" data-dismiss=\"modal\"", "Close")))))
+
+  def summarize(self):
+    testItemsTableHeader = self.wrapIn("thead",
+                                       self.wrapIn("tr",
+                                                   self.wrapIn("th", "Test Class Name") +
+                                                   self.wrapIn("th", "Test Case Name") +
+                                                   self.wrapIn("th", "Validation Status")))
+    testItemsTableBody = ""
+    modals = ""
+
+    for systemTestResult in self.systemTestEnv.systemTestResultsList:
+      self.totalTests += 1
+      if "_test_class_name" in systemTestResult:
+        testClassName = systemTestResult["_test_class_name"]
+      else:
+        testClassName = ""
+
+      if "_test_case_name" in systemTestResult:
+        testCaseName = systemTestResult["_test_case_name"]
+      else:
+        testCaseName = ""
+
+      if "validation_status" in systemTestResult:
+        testItemStatus = "SKIPPED"
+        for key in systemTestResult["validation_status"].iterkeys():
+          testItemStatus = systemTestResult["validation_status"][key]
+          if "FAILED" == testItemStatus:
+            break;
+        if "FAILED" == testItemStatus:
+          self.totalFailed += 1
+          validationStatus = self.wrapIn("div class=\"text-danger\" data-toggle=\"modal\"
data-target=\"#" + testClassName + "_" + testCaseName + "\"", "FAILED")
+          modals += self.genModal(testClassName, testCaseName, systemTestResult)
+        elif "PASSED" == testItemStatus:
+          self.totalPassed += 1
+          validationStatus = self.wrapIn("div class=\"text-success\"", "PASSED")
+        else:
+          self.totalSkipped += 1
+          validationStatus = self.wrapIn("div class=\"text-warning\"", "SKIPPED")
+      else:
+        self.reportString += "|"
+
+      testItemsTableBody += self.wrapIn("tr",
+                                       self.wrapIn("td", testClassName) +
+                                       self.wrapIn("td", testCaseName) +
+                                       self.wrapIn("td", validationStatus))
+
+    testItemsTableBody = self.wrapIn("tbody", testItemsTableBody)
+    testItemsTable = self.wrapIn("table class=\"table table-striped\"", testItemsTableHeader
+ testItemsTableBody)
+
+    statsTblBody = self.wrapIn("tr class=\"active\"", self.wrapIn("td", "Total tests") +
self.wrapIn("td", str(self.totalTests)))
+    statsTblBody += self.wrapIn("tr class=\"success\"", self.wrapIn("td", "Total tests passed")
+ self.wrapIn("td", str(self.totalPassed)))
+    statsTblBody += self.wrapIn("tr class=\"danger\"", self.wrapIn("td", "Total tests failed")
+ self.wrapIn("td", str(self.totalFailed)))
+    statsTblBody += self.wrapIn("tr class=\"warning\"", self.wrapIn("td", "Total tests skipped")
+ self.wrapIn("td", str(self.totalSkipped)))
+    testStatsTable = self.wrapIn("table class=\"table\"", statsTblBody)
+
+    body = self.wrapIn("div class=\"container\"",
+                          self.wrapIn("h2", "Kafka System Test Report") +
+                          self.wrapIn("div class=\"row\"", self.wrapIn("div class=\"col-md-4\"",
testStatsTable)) +
+                          self.wrapIn("div class=\"row\"", self.wrapIn("div class=\"col-md-6\"",
testItemsTable)) +
+                          modals)
+    self.writeHtmlPage(self.wrapIn("body", body))
+
 def main():
     nLogger = logging.getLogger('namedLogger')
     aLogger = logging.getLogger('anonymousLogger')
@@ -98,7 +223,7 @@ def main():
             nLogger.info("SKIPPING : checking remote machines", extra=d)
         print
 
-    # get all defined names within a module: 
+    # get all defined names within a module:
     definedItemList = dir(SystemTestEnv)
     aLogger.debug("=================================================")
     aLogger.debug("SystemTestEnv keys:")
@@ -129,7 +254,7 @@ def main():
                     and not moduleFileName.startswith("__"):
 
                     # found a test module file
-                    nLogger.info("found a test module file : " + moduleFileName, extra=d)

+                    nLogger.info("found a test module file : " + moduleFileName, extra=d)
 
                     testModuleClassName = system_test_utils.sys_call("grep ^class " + testModulePathName
+ "/" + \
                                           moduleFileName + " | sed 's/^class //g' | sed 's/(.*):.*//g'")
@@ -138,7 +263,7 @@ def main():
                     # collect the test suite class data
                     testSuiteClassDict           = {}
                     testSuiteClassDict["suite"]  = dirName
-                    extLenToRemove               = systemTestEnv.SYSTEM_TEST_MODULE_EXT.__len__()
* -1 
+                    extLenToRemove               = systemTestEnv.SYSTEM_TEST_MODULE_EXT.__len__()
* -1
                     testSuiteClassDict["module"] = moduleFileName[:extLenToRemove]
                     testSuiteClassDict["class"]  = testModuleClassName
                     testSuiteClassDictList.append(testSuiteClassDict)
@@ -149,7 +274,7 @@ def main():
 
                     # add testsuite directory to sys.path such that the module can be loaded
                     sys.path.append(systemTestEnv.SYSTEM_TEST_BASE_DIR + "/" + suiteName)
- 
+
                     if not systemTestEnv.printTestDescriptionsOnly:
                         aLogger.info("=================================================")
                         aLogger.info("Running Test for : ")
@@ -165,6 +290,8 @@ def main():
                     instance.runTest()
                 print
 
+    report(systemTestEnv).summarize()
+
     if not systemTestEnv.printTestDescriptionsOnly:
         totalFailureCount = 0
         print


Mime
View raw message