Bugfix: kubernetes context do not implement _get_network
[yardstick.git] / yardstick / cmd / cli.py
index d141731..d2c49e8 100644 (file)
@@ -7,10 +7,11 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-'''
+"""
 Command-line interface to yardstick
 Command-line interface to yardstick
-'''
+"""
 
 
+from __future__ import absolute_import
 import logging
 import os
 import sys
 import logging
 import os
 import sys
@@ -19,23 +20,21 @@ from pkg_resources import get_distribution
 from argparse import RawDescriptionHelpFormatter
 from oslo_config import cfg
 
 from argparse import RawDescriptionHelpFormatter
 from oslo_config import cfg
 
+from yardstick import _init_logging, _LOG_STREAM_HDLR
 from yardstick.cmd.commands import task
 from yardstick.cmd.commands import runner
 from yardstick.cmd.commands import scenario
 from yardstick.cmd.commands import testcase
 from yardstick.cmd.commands import plugin
 from yardstick.cmd.commands import env
 from yardstick.cmd.commands import task
 from yardstick.cmd.commands import runner
 from yardstick.cmd.commands import scenario
 from yardstick.cmd.commands import testcase
 from yardstick.cmd.commands import plugin
 from yardstick.cmd.commands import env
+from yardstick.cmd.commands import report
 
 CONF = cfg.CONF
 cli_opts = [
     cfg.BoolOpt('debug',
                 short='d',
                 default=False,
 
 CONF = cfg.CONF
 cli_opts = [
     cfg.BoolOpt('debug',
                 short='d',
                 default=False,
-                help='increase output verbosity to debug'),
-    cfg.BoolOpt('verbose',
-                short='v',
-                default=False,
-                help='increase output verbosity to info')
+                help='increase output verbosity to debug')
 ]
 CONF.register_cli_opts(cli_opts)
 
 ]
 CONF.register_cli_opts(cli_opts)
 
@@ -54,8 +53,8 @@ def find_config_files(path_list):
     return None
 
 
     return None
 
 
-class YardstickCLI():
-    '''Command-line interface to yardstick'''
+class YardstickCLI():   # pragma: no cover
+    """Command-line interface to yardstick"""
 
     # Command categories
     categories = {
 
     # Command categories
     categories = {
@@ -64,7 +63,8 @@ class YardstickCLI():
         'scenario': scenario.ScenarioCommands,
         'testcase': testcase.TestcaseCommands,
         'plugin': plugin.PluginCommands,
         'scenario': scenario.ScenarioCommands,
         'testcase': testcase.TestcaseCommands,
         'plugin': plugin.PluginCommands,
-        'env': env.EnvCommand
+        'env': env.EnvCommand,
+        'report': report.ReportCommands
     }
 
     def __init__(self):
     }
 
     def __init__(self):
@@ -73,7 +73,7 @@ class YardstickCLI():
             get_distribution('yardstick').version
 
     def _find_actions(self, subparsers, actions_module):
             get_distribution('yardstick').version
 
     def _find_actions(self, subparsers, actions_module):
-        '''find action methods'''
+        """find action methods"""
         # Find action methods inside actions_module and
         # add them to the command parser.
         # The 'actions_module' argument may be a class
         # Find action methods inside actions_module and
         # add them to the command parser.
         # The 'actions_module' argument may be a class
@@ -92,7 +92,7 @@ class YardstickCLI():
             subparser.set_defaults(func=callback)
 
     def _add_command_parsers(self, categories, subparsers):
             subparser.set_defaults(func=callback)
 
     def _add_command_parsers(self, categories, subparsers):
-        '''add commands to command-line parser'''
+        """add commands to command-line parser"""
         for category in categories:
             command_object = categories[category]()
             desc = command_object.__doc__ or ''
         for category in categories:
             command_object = categories[category]()
             desc = command_object.__doc__ or ''
@@ -129,15 +129,9 @@ class YardstickCLI():
 
     def _handle_global_opts(self):
 
 
     def _handle_global_opts(self):
 
-        # handle global opts
-        logger = logging.getLogger('yardstick')
-        logger.setLevel(logging.WARNING)
-
-        if CONF.verbose:
-            logger.setLevel(logging.INFO)
-
+        _init_logging()
         if CONF.debug:
         if CONF.debug:
-            logger.setLevel(logging.DEBUG)
+            _LOG_STREAM_HDLR.setLevel(logging.DEBUG)
 
     def _dispath_func_notask(self):
 
 
     def _dispath_func_notask(self):
 
@@ -157,25 +151,27 @@ class YardstickCLI():
         CONF.unregister_opts(self.opts)
 
     def main(self, argv):    # pragma: no cover
         CONF.unregister_opts(self.opts)
 
     def main(self, argv):    # pragma: no cover
-        '''run the command line interface'''
-        self._register_cli_opt()
+        """run the command line interface"""
+        try:
+            self._register_cli_opt()
 
 
-        self._load_cli_config(argv)
+            self._load_cli_config(argv)
 
 
-        self._handle_global_opts()
+            self._handle_global_opts()
 
 
-        self._dispath_func_notask()
-
-        self._clear_config_opts()
+            self._dispath_func_notask()
+        finally:
+            self._clear_config_opts()
 
     def api(self, argv, task_id):    # pragma: no cover
 
     def api(self, argv, task_id):    # pragma: no cover
-        '''run the api interface'''
-        self._register_cli_opt()
-
-        self._load_cli_config(argv)
+        """run the api interface"""
+        try:
+            self._register_cli_opt()
 
 
-        self._handle_global_opts()
+            self._load_cli_config(argv)
 
 
-        self._dispath_func_task(task_id)
+            self._handle_global_opts()
 
 
-        self._clear_config_opts()
+            self._dispath_func_task(task_id)
+        finally:
+            self._clear_config_opts()