Add task call entry in cli for REST API 89/23089/3
authorchenjiankun <chenjiankun1@huawei.com>
Thu, 13 Oct 2016 09:23:22 +0000 (09:23 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Wed, 9 Nov 2016 01:15:38 +0000 (01:15 +0000)
JIRA: YARDSTICK-368

This is to add api entry for api, the way to use cli will not be changed
The command line will use main method, and the api will use api method
The **kwargs in do_start will receive the args from api entry

Change-Id: Ic487344436f4596cd2efd70e008c8ea862778f2e
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
yardstick/cmd/cli.py
yardstick/cmd/commands/task.py

index dd74836..f2406bf 100644 (file)
@@ -101,8 +101,7 @@ class YardstickCLI():
             cmd_subparsers = subparser.add_subparsers(title='subcommands')
             self._find_actions(cmd_subparsers, command_object)
 
-    def main(self, argv):
-        '''run the command line interface'''
+    def _register_cli_opt(self):
 
         # register subcommands to parse additional command line arguments
         def parser(subparsers):
@@ -114,10 +113,14 @@ class YardstickCLI():
                                          handler=parser)
         CONF.register_cli_opt(category_opt)
 
+    def _load_cli_config(self, argv):
+
         # load CLI args and config files
         CONF(argv, project="yardstick", version=self._version,
              default_config_files=find_config_files(CONFIG_SEARCH_PATHS))
 
+    def _handle_global_opts(self):
+
         # handle global opts
         logger = logging.getLogger('yardstick')
         logger.setLevel(logging.WARNING)
@@ -128,6 +131,34 @@ class YardstickCLI():
         if CONF.debug:
             logger.setLevel(logging.DEBUG)
 
+    def _dispath_func_notask(self):
+
         # dispatch to category parser
         func = CONF.category.func
         func(CONF.category)
+
+    def _dispath_func_task(self, task_id, timestamp):
+
+        # dispatch to category parser
+        func = CONF.category.func
+        func(CONF.category, task_id=task_id, timestamp=timestamp)
+
+    def main(self, argv):    # pragma: no cover
+        '''run the command line interface'''
+        self._register_cli_opt()
+
+        self._load_cli_config(argv)
+
+        self._handle_global_opts()
+
+        self._dispath_func_notask()
+
+    def api(self, argv, task_id, timestamp):    # pragma: no cover
+        '''run the api interface'''
+        self._register_cli_opt()
+
+        self._load_cli_config(argv)
+
+        self._handle_global_opts()
+
+        self._dispath_func_task(task_id, timestamp)
index b38e084..a10a2a8 100644 (file)
@@ -51,7 +51,7 @@ class TaskCommands(object):
              output_file_default, default=output_file_default)
     @cliargs("--suite", help="process test suite file instead of a task file",
              action="store_true")
-    def do_start(self, args):
+    def do_start(self, args, **kwargs):
         '''Start a benchmark scenario.'''
 
         atexit.register(atexit_handler)