summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-12-18 01:33:02 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-12-18 01:33:02 +0000
commite268fa7ae7c17604ecad787d6940fdf77426dc0f (patch)
treeff9144429cec5a98d81d8038d67af096e8df3bd8
parent9d0f99349d2ea4499670708aacb1569cad0389aa (diff)
parent32c0d6daa4742911c999aff47a18e085f68769af (diff)
Merge "pretty cli format: runner/scenario/testcase list"
-rw-r--r--requirements.txt2
-rw-r--r--yardstick/benchmark/core/__init__.py12
-rw-r--r--yardstick/benchmark/core/runner.py18
-rw-r--r--yardstick/benchmark/core/scenario.py16
-rw-r--r--yardstick/cmd/__init__.py16
-rw-r--r--yardstick/cmd/commands/testcase.py17
6 files changed, 30 insertions, 51 deletions
diff --git a/requirements.txt b/requirements.txt
index 7715f8510..dec58b6b6 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -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
diff --git a/yardstick/benchmark/core/__init__.py b/yardstick/benchmark/core/__init__.py
index 70036ea1e..3e3aa99a1 100644
--- a/yardstick/benchmark/core/__init__.py
+++ b/yardstick/benchmark/core/__init__.py
@@ -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("+")
diff --git a/yardstick/benchmark/core/runner.py b/yardstick/benchmark/core/runner.py
index 64acdaa99..b5e457c41 100644
--- a/yardstick/benchmark/core/runner.py
+++ b/yardstick/benchmark/core/runner.py
@@ -10,9 +10,10 @@
""" 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"""
diff --git a/yardstick/benchmark/core/scenario.py b/yardstick/benchmark/core/scenario.py
index 28eb65230..3366172a5 100644
--- a/yardstick/benchmark/core/scenario.py
+++ b/yardstick/benchmark/core/scenario.py
@@ -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"""
diff --git a/yardstick/cmd/__init__.py b/yardstick/cmd/__init__.py
index 3756d9ebb..e69de29bb 100644
--- a/yardstick/cmd/__init__.py
+++ b/yardstick/cmd/__init__.py
@@ -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("+")
diff --git a/yardstick/cmd/commands/testcase.py b/yardstick/cmd/commands/testcase.py
index a151871b3..7bdcdf003 100644
--- a/yardstick/cmd/commands/testcase.py
+++ b/yardstick/cmd/commands/testcase.py
@@ -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)