From 0544c7079c48c8d55c3da43c8020987715561da6 Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Tue, 7 Apr 2020 10:38:32 -0500 Subject: [PATCH] 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 --- mariadb/templates/bin/_start.py.tpl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mariadb/templates/bin/_start.py.tpl b/mariadb/templates/bin/_start.py.tpl index 22309cb72..04dc4b53d 100644 --- a/mariadb/templates/bin/_start.py.tpl +++ b/mariadb/templates/bin/_start.py.tpl @@ -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):