Bad status on rally_sanity
[functest.git] / ci / tier_handler.py
index 46dbc43..27b9cbc 100644 (file)
 
 import re
 
+LINE_LENGTH = 72
+
+
+def split_text(text, max_len):
+    words = text.split()
+    lines = []
+    line = ""
+    for word in words:
+        if len(line) + len(word) < max_len - 1:
+            line += word + " "
+        else:
+            lines.append(line)
+            line = word + " "
+    if line != "":
+        lines.append(line)
+    return lines
+
 
 class Tier:
-    def __init__(self, name, order, ci, description=""):
+
+    def __init__(self, name, order, ci_loop, description=""):
         self.tests_array = []
         self.name = name
         self.order = order
-        self.ci = ci
+        self.ci_loop = ci_loop
         self.description = description
 
     def add_test(self, testcase):
@@ -50,40 +68,96 @@ class Tier:
     def get_name(self):
         return self.name
 
+    def get_order(self):
+        return self.order
+
+    def get_ci_loop(self):
+        return self.ci_loop
+
     def __str__(self):
-        return ("Tier info:\n"
-                "    Name: " + self.name + "\n"
-                "    Description: " + self.description + "\n"
-                "    Order: " + str(self.order) + "\n"
-                "    Test cases: " + str(self.get_test_names()) + "\n")
+        lines = split_text(self.description, LINE_LENGTH - 6)
+
+        out = ""
+        out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
+        out += ("| Tier:  " + self.name.ljust(LINE_LENGTH - 10) + "|\n")
+        out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
+        out += ("| Order: " + str(self.order).ljust(LINE_LENGTH - 10) + "|\n")
+        out += ("| CI Loop: " + str(self.ci_loop).ljust(LINE_LENGTH - 12) +
+                "|\n")
+        out += ("| Description:".ljust(LINE_LENGTH - 1) + "|\n")
+        for line in lines:
+            out += ("|    " + line.ljust(LINE_LENGTH - 7) + " |\n")
+        out += ("| Test cases:".ljust(LINE_LENGTH - 1) + "|\n")
+        tests = self.get_test_names()
+        if len(tests) > 0:
+            for i in range(len(tests)):
+                out += ("|    - %s |\n" % tests[i].ljust(LINE_LENGTH - 9))
+        else:
+            out += ("|    (There are no supported test cases "
+                    .ljust(LINE_LENGTH - 1) + "|\n")
+            out += ("|    in this tier for the given scenario) "
+                    .ljust(LINE_LENGTH - 1) + "|\n")
+        out += ("|".ljust(LINE_LENGTH - 1) + "|\n")
+        out += ("+%s+\n" % ("-" * (LINE_LENGTH - 2)))
+        return out
 
 
 class TestCase:
-    def __init__(self, name, dependency, description=""):
+
+    def __init__(self, name, dependency, criteria, blocking, description=""):
         self.name = name
         self.dependency = dependency
         self.description = description
+        self.criteria = criteria
+        self.blocking = blocking
 
     def is_compatible(self, ci_installer, ci_scenario):
-        if re.search(self.dependency.get_installer(), ci_installer) is None:
+        try:
+            if ci_installer is not None:
+                if re.search(self.dependency.get_installer(),
+                             ci_installer) is None:
+                    return False
+            if ci_scenario is not None:
+                if re.search(self.dependency.get_scenario(),
+                             ci_scenario) is None:
+                    return False
+            return not (ci_scenario is None and ci_installer is None)
+        except TypeError:
             return False
 
-        if re.search(self.dependency.get_scenario(), ci_scenario) is None:
-            return False
-
-        return True
-
     def get_name(self):
         return self.name
 
+    def get_criteria(self):
+        return self.criteria
+
+    def get_blocking(self):
+        return self.blocking
+
     def __str__(self):
-        return ("Testcase info:\n"
-                "    Name: " + self.name + "\n"
-                "    Description: " + self.description + "\n"
-                "    " + str(self.dependency) + "\n")
+        lines = split_text(self.description, LINE_LENGTH - 6)
+
+        out = ""
+        out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
+        out += ("| Testcase:  " + self.name.ljust(LINE_LENGTH - 14) + "|\n")
+        out += ("+%s+\n" % ("=" * (LINE_LENGTH - 2)))
+        out += ("| Description:".ljust(LINE_LENGTH - 1) + "|\n")
+        for line in lines:
+            out += ("|    " + line.ljust(LINE_LENGTH - 7) + " |\n")
+        out += ("| Criteria:  " +
+                self.criteria.ljust(LINE_LENGTH - 14) + "|\n")
+        out += ("| Dependencies:".ljust(LINE_LENGTH - 1) + "|\n")
+        installer = self.dependency.get_installer()
+        scenario = self.dependency.get_scenario()
+        out += ("|   - Installer:" + installer.ljust(LINE_LENGTH - 17) + "|\n")
+        out += ("|   - Scenario :" + scenario.ljust(LINE_LENGTH - 17) + "|\n")
+        out += ("|".ljust(LINE_LENGTH - 1) + "|\n")
+        out += ("+%s+\n" % ("-" * (LINE_LENGTH - 2)))
+        return out
 
 
 class Dependency:
+
     def __init__(self, installer, scenario):
         self.installer = installer
         self.scenario = scenario