diff --git a/slapos/monitor/monitor.py b/slapos/monitor/monitor.py index 38214f3c99760eb5b75ef52f1c9fa590d9dc04f4..dc90c9a5dec05db59c2b9ab180a8f4219a5f00d7 100644 --- a/slapos/monitor/monitor.py +++ b/slapos/monitor/monitor.py @@ -94,6 +94,8 @@ class Monitoring(object): self.pid_file = config.get("monitor", "pid-file") self.monitor_promise_folder = softConfigGet(config, "monitor", "monitor-promise-folder") + self.promise_timeout_file = softConfigGet(config, "monitor", + "promises-timeout-file") self.config_folder = os.path.join(self.private_folder, 'config') self.report_folder = self.private_folder @@ -101,6 +103,7 @@ class Monitoring(object): self.promise_output_file = config.get("monitor", "promise-output-file") self.bootstrap_is_ok = True + def loadConfig(self, pathes, config=None): if config is None: config = ConfigParser.ConfigParser() @@ -411,6 +414,7 @@ class Monitoring(object): "monitor-promises.pid"), '--output "%s"' % self.public_folder, '--promise_folder "%s"' % self.promise_folder, + '--timeout_file "%s"' % self.promise_timeout_file, '--monitor_promise_folder "%s"' % self.monitor_promise_folder, '--monitor_url "%s/jio_private/"' % self.webdav_url, # XXX hardcoded, '--history_folder "%s"' % self.public_folder, diff --git a/slapos/monitor/runpromise.py b/slapos/monitor/runpromise.py index b0dbdda4cb414a5a1ba66cda3144b18a2e5356c4..7f31edc741aa1f7edb25ec0962a0b4818a6a66f3 100644 --- a/slapos/monitor/runpromise.py +++ b/slapos/monitor/runpromise.py @@ -12,8 +12,8 @@ import glob import argparse import traceback -# Promise timeout after 12 seconds -promise_timeout = 12 +# Promise timeout after 20 seconds by default +promise_timeout = 20 def parseArguments(): """ @@ -32,6 +32,9 @@ def parseArguments(): help='Folder where to find Custom monitor promises to execute.') parser.add_argument('--promise_name', help='Title to give to this promise.') + parser.add_argument('--timeout_file', + default='', + help='File containing Max timeout for each promise run.') parser.add_argument('--promise_type', default='status', help='Type of promise to execute. [status, report].') @@ -52,6 +55,15 @@ class RunPromise(object): def __init__(self, config_parser): self.config = config_parser + self.promise_timeout = promise_timeout + if self.config.timeout_file and \ + os.path.exists(self.config.timeout_file): + with open(self.config.timeout_file) as tf: + timeout = tf.read() + if timeout.isdigit(): + self.promise_timeout = int(timeout) + else: + print "%s it not a valid promise-timeout value" % timeout def runpromise(self): @@ -298,7 +310,7 @@ class RunPromise(object): process_handler.stdin = None sleep_time = 0.1 - increment_limit = int(promise_timeout / sleep_time) + increment_limit = int(self.promise_timeout / sleep_time) for current_increment in range(0, increment_limit): if process_handler.poll() is None: time.sleep(sleep_time) @@ -318,7 +330,7 @@ class RunPromise(object): message = process_handler.stderr.read() if message is None: message = process_handler.stdout.read() or "" - message += '\nPROMISE TIME OUT AFTER %s SECONDS' % promise_timeout + message += '\nPROMISE TIME OUT AFTER %s SECONDS' % self.promise_timeout result_dict["message"] = message promise_result_list.append(result_dict)