From d8313e84aaa6cbe986cc2d6f8ddfd76901006105 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 3 Dec 2016 00:09:02 +0100 Subject: [PATCH] [enh] don't timeout by default on cli --- moulinette/__init__.py | 4 ++-- moulinette/actionsmap.py | 2 +- moulinette/core.py | 4 ++-- moulinette/interfaces/api.py | 2 +- moulinette/interfaces/cli.py | 5 +++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/moulinette/__init__.py b/moulinette/__init__.py index befed213..f29f98f8 100755 --- a/moulinette/__init__.py +++ b/moulinette/__init__.py @@ -109,7 +109,7 @@ def api(namespaces, host='localhost', port=80, routes={}, return 0 def cli(namespaces, args, use_cache=True, output_as=None, - password=None, parser_kwargs={}): + password=None, timeout=None, parser_kwargs={}): """Command line interface Execute an action with the moulinette from the CLI and print its @@ -135,7 +135,7 @@ def cli(namespaces, args, use_cache=True, output_as=None, 'parser_kwargs': parser_kwargs, }, ) - moulinette.run(args, output_as=output_as, password=password) + moulinette.run(args, output_as=output_as, password=password, timeout=timeout) except MoulinetteError as e: import logging logging.getLogger(namespaces[0]).error(e.strerror) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 83ed60eb..467f2461 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -425,7 +425,7 @@ class ActionsMap(object): else: return auth() - def process(self, args, timeout=0, **kwargs): + def process(self, args, timeout=None, **kwargs): """ Parse arguments and process the proper action diff --git a/moulinette/core.py b/moulinette/core.py index e4769d11..9e9a676c 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -534,7 +534,7 @@ class MoulinetteLock(object): lock """ - def __init__(self, namespace, timeout=0, interval=.5): + def __init__(self, namespace, timeout=None, interval=.5): self.namespace = namespace self.timeout = timeout self.interval = interval @@ -573,7 +573,7 @@ class MoulinetteLock(object): self._lock() break - if (time.time() - start_time) > self.timeout: + if self.timeout is not None and (time.time() - start_time) > self.timeout: raise MoulinetteError(errno.EBUSY, m18n.g('instance_already_running')) # Wait before checking again diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 2b715b31..904c4651 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -377,7 +377,7 @@ class _ActionsMapPlugin(object): """ try: - ret = self.actionsmap.process(arguments, route=_route) + ret = self.actionsmap.process(arguments, timeout=30, route=_route) except MoulinetteError as e: raise error_to_response(e) else: diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 0a2eee8f..4f9a6b28 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -322,7 +322,7 @@ class Interface(BaseInterface): self.actionsmap = actionsmap - def run(self, args, output_as=None, password=None): + def run(self, args, output_as=None, password=None, timeout=None): """Run the moulinette Process the action corresponding to the given arguments 'args' @@ -335,6 +335,7 @@ class Interface(BaseInterface): - plain: return a script-readable output - none: do not output the result - password -- The password to use in case of authentication + - timeout -- Number of seconds before this command will timeout because it can't acquire the lock (meaning that another command is currently running), by default there is no timeout and the command will wait until it can get the lock """ if output_as and output_as not in ['json', 'plain', 'none']: @@ -349,7 +350,7 @@ class Interface(BaseInterface): lambda a,h: a(password=password)) try: - ret = self.actionsmap.process(args, timeout=30) + ret = self.actionsmap.process(args, timeout=timeout) except (KeyboardInterrupt, EOFError): raise MoulinetteError(errno.EINTR, m18n.g('operation_interrupted'))