blob: f44f42b6d6e3446ff759a1f699d9dc321d9a5bfe [file] [log] [blame]
sgarbuz3b252472019-07-19 11:22:22 +03001import time
2
3__copyright__ = "Copyright 2019, Mirantis Inc."
4__license__ = "Apache 2.0"
5
6try:
7 # Trying to import MySQLdb
8 import MySQLdb
9except 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
18def __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
24def 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']}