Add wsrep.check_state and update verify service sls

Change-Id: I61aff69f046286b93e211d09ae3dc4da47409f6a
Related-Prod: PROD-29630
diff --git a/_states/wsrep.py b/_states/wsrep.py
new file mode 100644
index 0000000..f44f42b
--- /dev/null
+++ b/_states/wsrep.py
@@ -0,0 +1,43 @@
+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']}
diff --git a/galera/upgrade/verify/_service.sls b/galera/upgrade/verify/_service.sls
index 730f8e4..b11f177 100644
--- a/galera/upgrade/verify/_service.sls
+++ b/galera/upgrade/verify/_service.sls
@@ -6,6 +6,5 @@
 {%- set galera = slave %}
 {%- endif %}
 
-galera_task_uprade_verify_service:
-  test.show_notification:
-    - text: "Running galera.upgrade.verify._service"
+galera_check_node_state:
+  wsrep.check_state