Commit cc13ad90 authored by Jonathan Michalon's avatar Jonathan Michalon

Check: add possibility to require a RE match in command output

parent 1d6bc6fe
from lib.subprocess_compat import TimeoutExpired, Popen, PIPE
from threading import Lock
import re
# used for hack in Check.exec_with_timeout() because Popen is not
......@@ -46,7 +47,7 @@ class Check(object):
self.teardown()
return self.ok
def exec_with_timeout(self, command, timeout=2):
def exec_with_timeout(self, command, timeout=2, pattern=''):
self.errmsg = ''
try:
lock.acquire()
......@@ -62,9 +63,14 @@ class Check(object):
p.kill()
out, err = p.communicate()
self.errmsg += "Operation timed out\n"
return False
if p.returncode != 0:
self.errmsg += "stdout: " + str(out) + '\n' + \
"stderr: " + str(err) + '\n'
if re.search(pattern, str(out), flags=re.M) is None:
self.errmsg += "Pattern not found in reply: '%s'\n" + \
"stdout: %s" % (pattern, out.decode())
return False
return p.returncode == 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment