Merge "remove failing influx testcases"
[yardstick.git] / yardstick / cmd / cli.py
index f2406bf..05bf8f0 100644 (file)
@@ -11,6 +11,7 @@
 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,11 +20,13 @@ 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
 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 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
 
 CONF = cfg.CONF
 cli_opts = [
 
 CONF = cfg.CONF
 cli_opts = [
@@ -62,10 +65,12 @@ class YardstickCLI():
         'runner': runner.RunnerCommands,
         'scenario': scenario.ScenarioCommands,
         'testcase': testcase.TestcaseCommands,
         'runner': runner.RunnerCommands,
         'scenario': scenario.ScenarioCommands,
         'testcase': testcase.TestcaseCommands,
-        'plugin': plugin.PluginCommands
+        'plugin': plugin.PluginCommands,
+        'env': env.EnvCommand
     }
 
     def __init__(self):
     }
 
     def __init__(self):
+        self.opts = []
         self._version = 'yardstick version %s ' % \
             get_distribution('yardstick').version
 
         self._version = 'yardstick version %s ' % \
             get_distribution('yardstick').version
 
@@ -111,7 +116,12 @@ class YardstickCLI():
                                          title="Command categories",
                                          help="Available categories",
                                          handler=parser)
                                          title="Command categories",
                                          help="Available categories",
                                          handler=parser)
-        CONF.register_cli_opt(category_opt)
+        self._register_opt(category_opt)
+
+    def _register_opt(self, opt):
+
+        CONF.register_cli_opt(opt)
+        self.opts.append(opt)
 
     def _load_cli_config(self, argv):
 
 
     def _load_cli_config(self, argv):
 
@@ -121,15 +131,12 @@ class YardstickCLI():
 
     def _handle_global_opts(self):
 
 
     def _handle_global_opts(self):
 
-        # handle global opts
-        logger = logging.getLogger('yardstick')
-        logger.setLevel(logging.WARNING)
-
+        _init_logging()
         if CONF.verbose:
         if CONF.verbose:
-            logger.setLevel(logging.INFO)
+            LOG.setLevel(logging.INFO)
 
         if CONF.debug:
 
         if CONF.debug:
-            logger.setLevel(logging.DEBUG)
+            LOG.setLevel(logging.DEBUG)
 
     def _dispath_func_notask(self):
 
 
     def _dispath_func_notask(self):
 
@@ -137,28 +144,39 @@ class YardstickCLI():
         func = CONF.category.func
         func(CONF.category)
 
         func = CONF.category.func
         func(CONF.category)
 
-    def _dispath_func_task(self, task_id, timestamp):
+    def _dispath_func_task(self, task_id):
 
         # dispatch to category parser
         func = CONF.category.func
 
         # dispatch to category parser
         func = CONF.category.func
-        func(CONF.category, task_id=task_id, timestamp=timestamp)
+        func(CONF.category, task_id=task_id)
+
+    def _clear_config_opts(self):
+
+        CONF.clear()
+        CONF.unregister_opts(self.opts)
 
     def main(self, argv):    # pragma: no cover
         '''run the command line interface'''
 
     def main(self, argv):    # pragma: no cover
         '''run the command line interface'''
-        self._register_cli_opt()
+        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._dispath_func_notask()
+        finally:
+            self._clear_config_opts()
 
 
-    def api(self, argv, task_id, timestamp):    # pragma: no cover
+    def api(self, argv, task_id):    # pragma: no cover
         '''run the api interface'''
         '''run the api interface'''
-        self._register_cli_opt()
+        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_task(task_id, timestamp)
+            self._dispath_func_task(task_id)
+        finally:
+            self._clear_config_opts()