pretty cli format: runner/scenario/testcase list 73/47473/13
authorrexlee8776 <limingjiang@huawei.com>
Mon, 20 Nov 2017 03:28:31 +0000 (03:28 +0000)
committerRex Lee <limingjiang@huawei.com>
Fri, 15 Dec 2017 06:20:51 +0000 (06:20 +0000)
JIRA: YARDSTICK-855

1. using prettytable to reformat cli below:
yardstick runner list
yardstick scenario list
yardstick testcase list
2. remove redundant function print_hbar
3. fix pep8 problems, the framework using do_list dynamicly,
so disable unused-argument check for now.

Change-Id: I79e1226e21fca4624bf4436414917bd07ecabca0
Signed-off-by: rexlee8776 <limingjiang@huawei.com>
requirements.txt
yardstick/benchmark/core/__init__.py
yardstick/benchmark/core/runner.py
yardstick/benchmark/core/scenario.py
yardstick/cmd/__init__.py
yardstick/cmd/commands/testcase.py

index 7715f85..dec58b6 100644 (file)
@@ -10,6 +10,7 @@
 Babel==2.3.4            # BSD; OSI Approved  BSD License
 Jinja2==2.8.1           # BSD; OSI Approved  BSD License
 MarkupSafe==0.23        # BSD; OSI Approved  BSD License
+PTable==0.9.2           # BSD (3 clause); OSI Approved  BSD License
 PyYAML==3.12            # MIT; OSI Approved  MIT License
 SQLAlchemy==1.1.4       # MIT License; OSI Approved  MIT License
 ansible==2.3.2          # GPLv3; OSI Approved  GNU General Public License v3 or later (GPLv3+)
@@ -58,7 +59,6 @@ pbr==1.10.0             # OSI Approved  Apache Software License; Apache License,
 # version 14.5.0 for compatibility with trex traffic generator
 pika==0.10.0            # BSD; OSI Approved  BSD License
 positional==1.1.1       # OSI Approved  Apache Software License
-prettytable==0.7.2      # BSD (3 clause); OSI Approved  BSD License
 pycrypto==2.6.1         # Public Domain
 pyparsing==2.1.10       # MIT License; OSI Approved  MIT License
 pyroute2==0.4.12        # dual license GPLv2+ and Apache v2; OSI Approved  GNU General Public License v2 or later (GPLv2+); OSI Approved  Apache Software License
index 70036ea..3e3aa99 100644 (file)
@@ -6,10 +6,15 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
+"""
+Yardstick benchmark core.
+"""
+
 from __future__ import print_function
 
 
 class Param(object):
+    """This class converts a parameter dictionary to an object."""
 
     def __init__(self, kwargs):
         # list
@@ -31,10 +36,3 @@ class Param(object):
 
         # list
         self.type = kwargs.get('type')
-
-
-def print_hbar(barlen):
-    """print to stdout a horizontal bar"""
-    print("+")
-    print("-" * barlen)
-    print("+")
index 64acdaa..b5e457c 100644 (file)
 """ Handler for yardstick command 'runner' """
 
 from __future__ import absolute_import
-from __future__ import print_function
+
+import prettytable
+
 from yardstick.benchmark.runners.base import Runner
-from yardstick.benchmark.core import print_hbar
 
 
 class Runners(object):  # pragma: no cover
@@ -21,16 +22,15 @@ class Runners(object):  # pragma: no cover
        Set of commands to discover and display runner types.
     """
 
-    def list_all(self, args):
+    def list_all(self, *args):
         """List existing runner types"""
         types = Runner.get_types()
-        print_hbar(78)
-        print("| %-16s | %-60s" % ("Type", "Description"))
-        print_hbar(78)
+        runner_table = prettytable.PrettyTable(['Type', 'Description'])
+        runner_table.align = 'l'
         for rtype in types:
-            print("| %-16s | %-60s" % (rtype.__execution_type__,
-                                       rtype.__doc__.split("\n")[0]))
-        print_hbar(78)
+            runner_table.add_row([rtype.__execution_type__,
+                                  rtype.__doc__.split("\n")[0]])
+        print(runner_table)
 
     def show(self, args):
         """Show details of a specific runner type"""
index 28eb652..3366172 100644 (file)
@@ -10,8 +10,9 @@
 """ Handler for yardstick command 'scenario' """
 
 from __future__ import absolute_import
+import prettytable
+
 from yardstick.benchmark.scenarios.base import Scenario
-from yardstick.benchmark.core import print_hbar
 
 
 class Scenarios(object):    # pragma: no cover
@@ -20,16 +21,15 @@ class Scenarios(object):    # pragma: no cover
        Set of commands to discover and display scenario types.
     """
 
-    def list_all(self, args):
+    def list_all(self, *args):
         """List existing scenario types"""
         types = Scenario.get_types()
-        print_hbar(78)
-        print("| %-16s | %-60s" % ("Type", "Description"))
-        print_hbar(78)
+        scenario_table = prettytable.PrettyTable(['Type', 'Description'])
+        scenario_table.align = 'l'
         for scenario_class in types:
-            print("| %-16s | %-60s" % (scenario_class.get_scenario_type(),
-                                       scenario_class.get_description()))
-        print_hbar(78)
+            scenario_table.add_row([scenario_class.get_scenario_type(),
+                                    scenario_class.get_description()])
+        print(scenario_table)
 
     def show(self, args):
         """Show details of a specific scenario type"""
index 3756d9e..e69de29 100644 (file)
@@ -1,16 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Ericsson AB and others.
-#
-# 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
-##############################################################################
-from __future__ import print_function
-
-
-def print_hbar(barlen):
-    """print to stdout a horizontal bar"""
-    print(("+"), end=' ')
-    print(("-" * barlen), end=' ')
-    print("+")
index a151871..7bdcdf0 100644 (file)
@@ -8,11 +8,11 @@
 ##############################################################################
 
 """ Handler for yardstick command 'testcase' """
-from __future__ import print_function
 from __future__ import absolute_import
 
+import prettytable
+
 from yardstick.benchmark.core.testcase import Testcase
-from yardstick.benchmark.core import print_hbar
 from yardstick.common.utils import cliargs
 from yardstick.cmd.commands import change_osloobj_to_paras
 from yardstick.cmd.commands import Commands
@@ -24,7 +24,7 @@ class TestcaseCommands(Commands):
        Set of commands to discover and display test cases.
     """
 
-    def do_list(self, args):
+    def do_list(self, *args):
         """List existing test cases"""
         testcase_list = self.client.get('/yardstick/testcases')['result']
         self._format_print(testcase_list)
@@ -37,11 +37,8 @@ class TestcaseCommands(Commands):
 
     def _format_print(self, testcase_list):
         """format output"""
-
-        print_hbar(88)
-        print("| %-21s | %-60s" % ("Testcase Name", "Description"))
-        print_hbar(88)
+        case_table = prettytable.PrettyTable(['Testcase Name', 'Description'])
+        case_table.align = 'l'
         for testcase_record in testcase_list:
-            print("| %-16s | %-60s" % (testcase_record['Name'],
-                                       testcase_record['Description']))
-        print_hbar(88)
+            case_table.add_row([testcase_record['Name'], testcase_record['Description']])
+        print(case_table)