diff --git a/salt/_modules/mysql.py b/salt/_modules/mysql.py deleted file mode 100644 index f4e35ae76..000000000 --- a/salt/_modules/mysql.py +++ /dev/null @@ -1,35 +0,0 @@ -#!py - -from MySQLdb import _mysql -import logging -import time - -log = logging.getLogger(__name__) - - -def status(retry): - mainint = __salt__['pillar.get']('sensor:mainint', __salt__['pillar.get']('manager:mainint')) - mainip = __salt__['grains.get']('ip_interfaces').get(mainint)[0] - - mysql_up = False - for i in range(0, retry): - log.debug(f'Connection attempt {i+1}') - try: - _mysql.connect( - host=mainip, - user="root", - passwd=__salt__['pillar.get']('secrets:mysql') - ) - mysql_up = True - break - except _mysql.OperationalError as e: - log.debug(e) - except Exception as e: - log.error(e) - break - time.sleep(1) - - if not mysql_up: - log.error(f'Could not connect to MySQL server on {mainip} after {retry} attempts.') - - return mysql_up diff --git a/salt/_modules/so.py b/salt/_modules/so.py index 50c29902f..43ffac250 100644 --- a/salt/_modules/so.py +++ b/salt/_modules/so.py @@ -1,4 +1,38 @@ #!py +import logging + def status(): - return __salt__['cmd.run']('/usr/sbin/so-status') \ No newline at end of file + return __salt__['cmd.run']('/usr/sbin/so-status') + + +def mysql_conn(retry): + from MySQLdb import _mysql + import time + + log = logging.getLogger(__name__) + mainint = __salt__['pillar.get']('sensor:mainint', __salt__['pillar.get']('manager:mainint')) + mainip = __salt__['grains.get']('ip_interfaces').get(mainint)[0] + + mysql_up = False + for i in range(0, retry): + log.debug(f'Connection attempt {i+1}') + try: + _mysql.connect( + host=mainip, + user="root", + passwd=__salt__['pillar.get']('secrets:mysql') + ) + mysql_up = True + break + except _mysql.OperationalError as e: + log.debug(e) + except Exception as e: + log.error(e) + break + time.sleep(1) + + if not mysql_up: + log.error(f'Could not connect to MySQL server on {mainip} after {retry} attempts.') + + return mysql_up \ No newline at end of file diff --git a/salt/mysql/init.sls b/salt/mysql/init.sls index e1f37f29c..121e689f8 100644 --- a/salt/mysql/init.sls +++ b/salt/mysql/init.sls @@ -98,7 +98,7 @@ so-mysql: - onchanges: - docker_container: so-mysql module.run: - - mysql.status: + - so.mysql_conn: - retry: 900 - onchanges: - cmd: so-mysql