Skip to content
Permalink
Browse files

Add elapsed time to om node wait command

user@node:$ om node wait --duration 50s --filter monitor.frozen=frozen --verbose
elapsed 20.05 seconds

condition monitor.frozen=frozen was met after 20.05 seconds
  • Loading branch information...
arnaudveron committed Jul 16, 2019
1 parent 5c535f3 commit 91a9bc7713c1d8e2e14c3d603279d677a6d86876
Showing with 19 additions and 2 deletions.
  1. +18 −2 lib/node.py
  2. +1 −0 lib/nodemgr_parser.py
@@ -3350,6 +3350,9 @@ def _wait(self, server=None, path=None, duration=None):
if not path:
return

if self.options.verbose:
begin = time.time()

if server is None:
server = rcEnv.nodename

@@ -3383,6 +3386,10 @@ def _wait(self, server=None, path=None, duration=None):
except Exception as exc:
raise ex.excError(exc)

def elapsed(self, begin):
elapsed = time.time() - begin
print("elapsed %.2f seconds"%elapsed)

def eval_cond(val, data):
for match in jsonpath_expr.find(data):
if oper is None:
@@ -3435,15 +3442,21 @@ def match_event(msg):
cluster_data = self._daemon_status()
cluster_data["monitor"]
except KeyError:
raise ex.excError("could fetch cluster data")
raise ex.excError("could not fetch cluster data")

if neg ^ eval_cond(val, cluster_data):
if self.options.verbose:
elapsed(self, begin)
return

if duration:
import signal
def alarm_handler(signum, frame):
print("timeout", file=sys.stderr)
msg = "timeout"
if self.options.verbose:
elapsed = time.time() - begin
msg = "timeout. elapsed %.2f seconds"%elapsed
print(msg, file=sys.stderr)
raise KeyboardInterrupt
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(convert_duration(duration))
@@ -3472,6 +3485,9 @@ def alarm_handler(signum, frame):
if match_event(patch):
break

if self.options.verbose:
elapsed(self, begin)

def events(self, server=None):
try:
self._events(server=server)
@@ -508,6 +508,7 @@
"lists, non-emptry strings).",
"options": [
OPT.duration,
OPT.verbose,
]
},
"wol": {

0 comments on commit 91a9bc7

Please sign in to comment.
You can’t perform that action at this time.