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:
Joshua Boniface 2019-09-07 12:30:31 -04:00
parent 983daceaed
commit 0c9d6db14f
1 changed files with 29 additions and 24 deletions

View File

@ -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, ''