Merge "fix(mariadb): handle IndexError"

This commit is contained in:
Zuul 2020-04-08 00:55:23 +00:00 committed by Gerrit Code Review
commit 9e48974fcf
1 changed files with 9 additions and 4 deletions

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):