fix(mariadb): handle IndexError

This patch set handles an unexpected IndexError stacktrace when the
galera cluster's data file does not return with an expected key with a
colon (:) in the string.

Change-Id: I4f58e97753a0f68468a02b98676e031176145e44
Signed-off-by: Tin Lam <tin@irrational.io>
This commit is contained in:
Tin Lam 2020-04-07 10:38:32 -05:00
parent 19a1fbf8f7
commit 0544c7079c

View File

@ -487,10 +487,15 @@ def get_grastate_val(key):
key -- the key to extract the value of
"""
logger.debug("Reading grastate.dat key={0}".format(key))
with open("/var/lib/mysql/grastate.dat", "r") as myfile:
grastate_raw = [s.strip() for s in myfile.readlines()]
return [i for i in grastate_raw
if i.startswith("{0}:".format(key))][0].split(':')[1].strip()
try:
with open("/var/lib/mysql/grastate.dat", "r") as myfile:
grastate_raw = [s.strip() for s in myfile.readlines()]
return [i for i in grastate_raw
if i.startswith("{0}:".format(key))][0].split(':')[1].strip()
except IndexError:
logger.warn("IndexError: Unable to find %s with ':' in grastate.dat",
key)
return []
def set_grastate_val(key, value):