[fix] Put mysql import in try,catch in case it hasn't been installed

This commit is contained in:
William Wernert
2020-11-10 10:00:21 -05:00
parent dba30fb0ed
commit 22b7de819c

View File

@@ -7,10 +7,15 @@ def status():
def mysql_conn(retry):
from MySQLdb import _mysql
import time
log = logging.getLogger(__name__)
try:
from MySQLdb import _mysql
except ImportError as e:
log.error(e)
return False
from time import sleep
mainint = __salt__['pillar.get']('sensor:mainint', __salt__['pillar.get']('manager:mainint'))
mainip = __salt__['grains.get']('ip_interfaces').get(mainint)[0]
@@ -30,7 +35,7 @@ def mysql_conn(retry):
except Exception as e:
log.error(e)
break
time.sleep(1)
sleep(1)
if not mysql_up:
log.error(f'Could not connect to MySQL server on {mainip} after {retry} attempts.')