X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=functest%2Fci%2Ftier_handler.py;h=dd3e77ce3365c30551c1c927ceb8b9821e68c8a9;hb=1da439765b20bbc9a1f63d736f4c6284b654d50d;hp=6b4864b5bebfb148eb20c7dcb25b718d8544b860;hpb=9917eb81504cdd5021bed5f18a994ffff433b4ef;p=functest.git diff --git a/functest/ci/tier_handler.py b/functest/ci/tier_handler.py index 6b4864b5b..dd3e77ce3 100644 --- a/functest/ci/tier_handler.py +++ b/functest/ci/tier_handler.py @@ -1,14 +1,18 @@ #!/usr/bin/env python + +# Copyright (c) 2016 Ericsson AB and others. # -# jose.lausuch@ericsson.com # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 -# import re +import textwrap + +import prettytable + LINE_LENGTH = 72 @@ -32,6 +36,7 @@ class Tier(object): def __init__(self, name, order, ci_loop, description=""): self.tests_array = [] + self.skipped_tests_array = [] self.name = name self.order = order self.ci_loop = ci_loop @@ -40,12 +45,18 @@ class Tier(object): def add_test(self, testcase): self.tests_array.append(testcase) + def skip_test(self, testcase): + self.skipped_tests_array.append(testcase) + def get_tests(self): array_tests = [] for test in self.tests_array: array_tests.append(test) return array_tests + def get_skipped_test(self): + return self.skipped_tests_array + def get_test_names(self): array_tests = [] for test in self.tests_array: @@ -75,47 +86,34 @@ class Tier(object): return self.ci_loop def __str__(self): - 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 + msg = prettytable.PrettyTable( + header_style='upper', padding_width=5, + field_names=['tiers', 'order', 'CI Loop', 'description', + 'testcases']) + msg.add_row( + [self.name, self.order, self.ci_loop, + textwrap.fill(self.description, width=40), + textwrap.fill(' '.join([str(x.get_name( + )) for x in self.get_tests()]), width=40)]) + return msg.get_string() class TestCase(object): def __init__(self, name, + enabled, dependency, criteria, blocking, - clean_flag, - description=""): + description="", + project=""): self.name = name + self.enabled = enabled self.dependency = dependency self.criteria = criteria self.blocking = blocking - self.clean_flag = clean_flag self.description = description + self.project = project @staticmethod def is_none(item): @@ -138,35 +136,25 @@ class TestCase(object): def get_name(self): return self.name + def is_enabled(self): + return self.enabled + def get_criteria(self): return self.criteria def is_blocking(self): return self.blocking - def needs_clean(self): - return self.clean_flag + def get_project(self): + return self.project def __str__(self): - 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 + msg = prettytable.PrettyTable( + header_style='upper', padding_width=5, + field_names=['test case', 'description', 'criteria', 'dependency']) + msg.add_row([self.name, textwrap.fill(self.description, width=40), + self.criteria, self.dependency]) + return msg.get_string() class Dependency(object): @@ -182,6 +170,7 @@ class Dependency(object): return self.scenario def __str__(self): - return ("Dependency info:\n" - " installer: " + self.installer + "\n" - " scenario: " + self.scenario + "\n") + delimitator = "\n" if self.get_installer( + ) and self.get_scenario() else "" + return "{}{}{}".format(self.get_installer(), delimitator, + self.get_scenario())