sgarbuz | 3b25247 | 2019-07-19 11:22:22 +0300 | [diff] [blame] | 1 | import time |
| 2 | |
| 3 | __copyright__ = "Copyright 2019, Mirantis Inc." |
| 4 | __license__ = "Apache 2.0" |
| 5 | |
| 6 | try: |
| 7 | # Trying to import MySQLdb |
| 8 | import MySQLdb |
| 9 | except ImportError: |
| 10 | try: |
| 11 | # MySQLdb import failed, try to import PyMySQL |
| 12 | import pymysql |
| 13 | pymysql.install_as_MySQLdb() |
| 14 | import MySQLdb |
| 15 | except ImportError: |
| 16 | MySQLdb = None |
| 17 | |
| 18 | def __virtual__(): |
| 19 | ''' |
| 20 | Confirm that a python mysql client is installed. |
| 21 | ''' |
| 22 | return bool(MySQLdb), 'No python mysql client installed.' if MySQLdb is None else '' |
| 23 | |
| 24 | def check_state(name, retries=18, timeout=10): |
| 25 | """ |
| 26 | Ensure that galera node in Operational state. |
| 27 | |
| 28 | :param timeout: number of seconds to wait before retries |
| 29 | :param retries: number of retries |
| 30 | """ |
| 31 | |
| 32 | for i in range(retries): |
| 33 | out = __salt__['mysql.status']() |
| 34 | |
| 35 | if isinstance(out, dict) and out.get('wsrep_evs_state') == 'OPERATIONAL': |
| 36 | break |
| 37 | time.sleep(timeout) |
| 38 | else: |
| 39 | return {"result": False, |
| 40 | "name": name, |
| 41 | "changes": {}, |
| 42 | "comment": "Galera node is not in operational state : %s" % out['wsrep_evs_state']} |
| 43 | return {"result": True, "name": name, "changes": {}, "comment": "Galera node is in operational state : %s" % out['wsrep_evs_state']} |