From e5b312fc2d09346c75be9e0df2aa9eb20ee4529f Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Fri, 25 Nov 2016 02:57:50 +0000 Subject: ArgsAlreadyParsedError: arguments already parsed: cannot register CLI option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- yardstick/cmd/cli.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py index 3896ce47c..ee8d1c529 100644 --- a/yardstick/cmd/cli.py +++ b/yardstick/cmd/cli.py @@ -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() -- cgit 1.2.3-korg