Gracefully handle log following output
If the Zookeeper node goes away (e.g. VM is deleted), return a reasonable error message instead of a stack trace.
This commit is contained in:
parent
983daceaed
commit
0c9d6db14f
|
@ -529,6 +529,7 @@ def follow_console_log(zk_conn, domain, lines=10):
|
||||||
# Print the initial data and begin following
|
# Print the initial data and begin following
|
||||||
print(loglines, end='')
|
print(loglines, end='')
|
||||||
|
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
# Grab the next line set
|
# Grab the next line set
|
||||||
new_console_log = zkhandler.readdata(zk_conn, '/domains/{}/consolelog'.format(dom_uuid))
|
new_console_log = zkhandler.readdata(zk_conn, '/domains/{}/consolelog'.format(dom_uuid))
|
||||||
|
@ -553,6 +554,10 @@ def follow_console_log(zk_conn, domain, lines=10):
|
||||||
print(diff_console_log, end='')
|
print(diff_console_log, end='')
|
||||||
# Wait a second
|
# Wait a second
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
except kazoo.exceptions.NoNodeError:
|
||||||
|
return False, 'ERROR: VM has gone away.'
|
||||||
|
except:
|
||||||
|
return False, 'ERROR: Lost connection to Zookeeper node.'
|
||||||
|
|
||||||
return True, ''
|
return True, ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue