ArgsAlreadyParsedError: arguments already parsed: cannot register CLI option 77/24877/1
authorchenjiankun <chenjiankun1@huawei.com>
Fri, 25 Nov 2016 02:57:50 +0000 (02:57 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Fri, 25 Nov 2016 02:59:55 +0000 (02:59 +0000)
JIRA: YARDSTICK-216

When I call YardstickCLI  in flask, it will always encounter a
ArgsAlreadyParsedError if the API run test case more than two times.

In YardstickCLI, if I just call CONF.clear(), it will occur another
error due to other opts not unregister. I don’t know if the problem
is on the oslo.config side.

I solve the problem by unregister the opts.

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

index 3896ce4..ee8d1c5 100644 (file)
@@ -66,6 +66,7 @@ class YardstickCLI():
     }
 
     def __init__(self):
+        self.opts = []
         self._version = 'yardstick version %s ' % \
             get_distribution('yardstick').version
 
@@ -111,7 +112,12 @@ class YardstickCLI():
                                          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):
 
@@ -143,6 +149,11 @@ class YardstickCLI():
         func = CONF.category.func
         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'''
         self._register_cli_opt()
@@ -153,6 +164,8 @@ class YardstickCLI():
 
         self._dispath_func_notask()
 
+        self._clear_config_opts()
+
     def api(self, argv, task_id):    # pragma: no cover
         '''run the api interface'''
         self._register_cli_opt()
@@ -162,3 +175,5 @@ class YardstickCLI():
         self._handle_global_opts()
 
         self._dispath_func_task(task_id)
+
+        self._clear_config_opts()