Make LogRequestHandler configurable

Make it possible to manipulate the simple and regexp
tests the LogRequestHandler class uses to check error
messages for potential error states.

This is accomplished by moving the simple and regexp test
strings to class members, where they can be easily
manipulated by users of the pylorax module.

It's also now possible to set the log request handler class
for a LogMonitor.

This functionality can then be used for example like this:

customized_log_request_handler = monitor.LogRequestHandler
customized_log_request_handler.simple_tests.remove("Call Trace:")
log_monitor = monitor.LogMonitor(install_log,
                                 timeout=opts.timeout,
                                 log_request_handler_class = customized_log_request_handler)

This way installation will continue even if there was a call
trace in the logs. In a similar way additional tests and regexps can be
also added.

(cherry picked from commit d5d3dd3be3)
This commit is contained in:
Martin Kolman 2018-05-24 19:44:57 +02:00 committed by Brian C. Lane
parent 760d70f158
commit 68e850d57a

View File

@ -34,6 +34,26 @@ class LogRequestHandler(socketserver.BaseRequestHandler):
for patterns that would indicate that the installation failed. for patterns that would indicate that the installation failed.
self.server.log_error is set True when this happens. self.server.log_error is set True when this happens.
""" """
simple_tests = [
"Traceback (",
"traceback script(s) have been run",
"Out of memory:",
"Call Trace:",
"insufficient disk space:",
"Not enough disk space to download the packages",
"error populating transaction after",
"crashed on signal",
"packaging: Missed: NoSuchPackage",
"packaging: Installation failed",
"The following error occurred while installing. This is a fatal error"
]
re_tests = [
r"packaging: base repo .* not valid",
r"packaging: .* requires .*"
]
def setup(self): def setup(self):
"""Start writing to self.server.log_path""" """Start writing to self.server.log_path"""
@ -99,25 +119,13 @@ class LogRequestHandler(socketserver.BaseRequestHandler):
""" """
if "IGNORED" in line: if "IGNORED" in line:
return return
simple_tests = ["Traceback (",
"Out of memory:", for t in self.simple_tests:
"Call Trace:",
"insufficient disk space:",
"Not enough disk space to download the packages",
"error populating transaction after",
"traceback script(s) have been run",
"crashed on signal",
"packaging: Missed: NoSuchPackage",
"packaging: Installation failed",
"The following error occurred while installing. This is a fatal error"]
re_tests = [r"packaging: base repo .* not valid",
r"packaging: .* requires .*"]
for t in simple_tests:
if t in line: if t in line:
self.server.log_error = True self.server.log_error = True
self.server.error_line = line self.server.error_line = line
return return
for t in re_tests: for t in self.re_tests:
if re.search(t, line): if re.search(t, line):
self.server.log_error = True self.server.log_error = True
self.server.error_line = line self.server.error_line = line
@ -168,7 +176,7 @@ class LogMonitor(object):
This needs to be running before the virt-install runs, it expects This needs to be running before the virt-install runs, it expects
there to be a listener on the port used for the virtio log port. there to be a listener on the port used for the virtio log port.
""" """
def __init__(self, log_path=None, host="localhost", port=0, timeout=None): def __init__(self, log_path=None, host="localhost", port=0, timeout=None, log_request_handler_class=LogRequestHandler):
""" """
Start a thread to monitor the logs. Start a thread to monitor the logs.
@ -182,7 +190,7 @@ class LogMonitor(object):
If log_path isn't set then it only monitors the logs, instead of If log_path isn't set then it only monitors the logs, instead of
also writing them to disk. also writing them to disk.
""" """
self.server = LogServer(log_path, (host, port), LogRequestHandler, timeout=timeout) self.server = LogServer(log_path, (host, port), log_request_handler_class, timeout=timeout)
self.host, self.port = self.server.server_address self.host, self.port = self.server.server_address
self.log_path = log_path self.log_path = log_path
self.server_thread = threading.Thread(target=self.server.handle_request) self.server_thread = threading.Thread(target=self.server.handle_request)