| import time |
| |
| __copyright__ = "Copyright 2019, Mirantis Inc." |
| __license__ = "Apache 2.0" |
| |
| try: |
| # Trying to import MySQLdb |
| import MySQLdb |
| except ImportError: |
| try: |
| # MySQLdb import failed, try to import PyMySQL |
| import pymysql |
| pymysql.install_as_MySQLdb() |
| import MySQLdb |
| except ImportError: |
| MySQLdb = None |
| |
| def __virtual__(): |
| ''' |
| Confirm that a python mysql client is installed. |
| ''' |
| return bool(MySQLdb), 'No python mysql client installed.' if MySQLdb is None else '' |
| |
| def check_state(name, retries=18, timeout=10): |
| """ |
| Ensure that galera node in Operational state. |
| |
| :param timeout: number of seconds to wait before retries |
| :param retries: number of retries |
| """ |
| |
| for i in range(retries): |
| out = __salt__['mysql.status']() |
| |
| if isinstance(out, dict) and out.get('wsrep_evs_state') == 'OPERATIONAL': |
| break |
| time.sleep(timeout) |
| else: |
| return {"result": False, |
| "name": name, |
| "changes": {}, |
| "comment": "Galera node is not in operational state : %s" % out['wsrep_evs_state']} |
| return {"result": True, "name": name, "changes": {}, "comment": "Galera node is in operational state : %s" % out['wsrep_evs_state']} |