Add InfluxDb HA tests

* Reboot mon node and check functionality
* Shutdown mon node and check functionality
* Kill influxdb on 1 node, and check functionality
* Kill influxdb-relay on 1 node and check functionality
* Gracefully stop influxdb on 2 nodes and check functionality
* Gracefully stop influxdb-relay on 2 nodes and check functionality

Change-Id: I21a123fa6ebb0f71250106f6df68cd5f412ad9fc
diff --git a/tcp_tests/tests/system/test_failover.py b/tcp_tests/tests/system/test_failover.py
index a8bb6b8..11173ce 100644
--- a/tcp_tests/tests/system/test_failover.py
+++ b/tcp_tests/tests/system/test_failover.py
@@ -11,7 +11,6 @@
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 #    License for the specific language governing permissions and limitations
 #    under the License.
-
 import pytest
 
 from tcp_tests import logger
@@ -148,8 +147,10 @@
             1. Prepare salt on hosts
             2. Setup controller nodes
             3. Setup compute, monitoring nodes
-            4. Restart mon01
-            5. Run LMA smoke after failover
+            4. Check targets before restart
+            5. Restart mon01
+            6. Check targets after restart
+            6. Run LMA smoke after failover
 
 
         """
@@ -160,15 +161,30 @@
 
         # STEP #4
         show_step(4)
-        openstack_actions.warm_restart_nodes('mon01')
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        sl_deployed.check_prometheus_targets(mon_nodes)
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
         # STEP #5
         show_step(5)
+        openstack_actions.warm_restart_nodes('mon01')
+        # STEP #6
+        show_step(6)
+        sl_deployed.check_prometheus_targets(mon_nodes)
+        # STEP #7
+        show_step(7)
         # Run SL component tetsts
-        sl_deployed.run_sl_functional_tests(
-            'cfg01',
-            '/root/stacklight-pytest/stacklight_tests/',
-            'tests/prometheus/test_smoke.py',
-            'test_alerts.py')
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
         LOG.info("*************** DONE **************")
 
     @pytest.mark.grab_versions
@@ -182,8 +198,9 @@
             1. Prepare salt on hosts
             2. Setup controller nodes
             3. Setup compute, monitoring nodes
-            4. Shutdown mon01
-            5. Run LMA smoke after failover
+            4. Check LMA before mon node shutdown
+            5. Shutdown mon01 node
+            6. Run LMA tests after failover
 
 
         """
@@ -194,12 +211,259 @@
 
         # STEP #4
         show_step(4)
-        openstack_actions.warm_shutdown_openstack_nodes('mon01')
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        sl_deployed.check_prometheus_targets(mon_nodes)
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
         # STEP #5
         show_step(5)
-        sl_deployed.run_sl_functional_tests(
-            'cfg01',
-            '/root/stacklight-pytest/stacklight_tests/',
-            'tests/prometheus/test_smoke.py',
-            'test_alerts.py')
+        openstack_actions.warm_shutdown_openstack_nodes('mon01')
+        # STEP #6
+        show_step(6)
+        # Run SL component tetsts
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
+        LOG.info("*************** DONE **************")
+
+    @pytest.mark.grab_versions
+    @pytest.mark.fail_snapshot
+    def test_kill_influxdb_relay_mon01_node(self, underlay,
+                                            openstack_deployed,
+                                            openstack_actions,
+                                            sl_deployed):
+        """Test kill influxdb relay on mon01 node
+
+        Scenario:
+            1. Prepare salt on hosts
+            2. Setup controller nodes
+            3. Setup compute, monitoring nodes
+            4. Check LMA before mon node shutdown
+            5. Kill influxdb relay on mon01 node
+            6. Post data into influx
+            7. Get data from all healthy nodes
+            8. Start influx db
+            9. Request data on mon01
+            10. Run LMA tests after fail and compare with result before fail
+
+
+        """
+        # STEP #1,2,3
+        # STEP #4
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
+        # STEP #5
+
+        sl_deployed.kill_sl_service_on_node('mon01', 'influxdb-relay')
+        # STEP #6
+
+        sl_deployed.post_data_into_influx('mon02')
+        # STEP #7
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon02')
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon03')
+        # STEP #8
+
+        sl_deployed.start_service('mon01', 'influxdb-relay')
+        # STEP #9
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon01')
+        # STEP #10
+
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
+        LOG.info("*************** DONE **************")
+
+    @pytest.mark.grab_versions
+    @pytest.mark.fail_snapshot
+    def test_kill_influxdb_mon01_node(self, underlay,
+                                      openstack_deployed,
+                                      openstack_actions,
+                                      sl_deployed):
+        """Test kill influxdb on mon01 node
+
+        Scenario:
+            1. Prepare salt on hosts
+            2. Setup controller nodes
+            3. Setup compute, monitoring nodes
+            4. Check LMA before mon node shutdown
+            5. Kill influxdb on mon01 node
+            6. Post data into influx
+            7. Get data from all healthy nodes
+            8. Start influx db
+            9. Request data on mon01
+            10. Run LMA tests after fail and compare with result before fail
+
+
+        """
+        # STEP #1,2,3
+
+        # STEP #4
+
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
+        # STEP #5
+
+        sl_deployed.kill_sl_service_on_node('mon01', 'influxd')
+
+        sl_deployed.post_data_into_influx('mon02')
+        # STEP #7
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon02')
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon03')
+        # STEP #8
+
+        sl_deployed.start_service('mon01', 'influxd')
+        # STEP #9
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon01')
+        # STEP #10
+
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
+        LOG.info("*************** DONE **************")
+
+    @pytest.mark.grab_versions
+    @pytest.mark.fail_snapshot
+    def test_stop_influxdb_relay_mon_nodes(self, underlay,
+                                            openstack_deployed,
+                                            openstack_actions,
+                                            sl_deployed):
+        """Test stop influxdb relay on mon01 node
+
+        Scenario:
+            1. Prepare salt on hosts
+            2. Setup controller nodes
+            3. Setup compute, monitoring nodes
+            4. Check LMA before mon node shutdown
+            5. Stop influxdb relay on mon01 and mon02 nodes
+            6. Post data into influx
+            7. Get data from all healthy nodes
+            8. Start influx db
+            9. Request data on mon01, 02
+            10. Run LMA tests after fail and compare with result before fail
+
+
+        """
+        # STEP #1,2,3
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
+        # STEP #5
+
+        sl_deployed.stop_sl_service_on_node('mon01', 'influxdb-relay')
+        sl_deployed.stop_sl_service_on_node('mon02', 'influxdb-relay')
+        # STEP #6
+
+        sl_deployed.post_data_into_influx('mon03')
+        # STEP #7
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon03')
+        # STEP #8
+
+        sl_deployed.start_service('mon01', 'influxdb-relay')
+        sl_deployed.start_service('mon02', 'influxdb-relay')
+        # STEP #9
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon01')
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon02')
+        # STEP #10
+
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
+        LOG.info("*************** DONE **************")
+
+    @pytest.mark.grab_versions
+    @pytest.mark.fail_snapshot
+    def test_stop_influxdb_mon_nodes(self, underlay,
+                                      openstack_deployed,
+                                      openstack_actions,
+                                      sl_deployed):
+        """Test stop influxdb on mon01 node
+
+        Scenario:
+            1. Prepare salt on hosts
+            2. Setup controller nodes
+            3. Setup compute, monitoring nodes
+            4. Check LMA before mon node shutdown
+            5. Stop influxdb on mon01 and mon02 node
+            6. Post data into influx
+            7. Get data from all healthy nodes
+            8. Start influx db
+            9. Request data on mon01
+            10. Run LMA tests after fail and compare with result before fail
+
+
+        """
+        # STEP #1,2,3
+        mon_nodes = sl_deployed.get_monitoring_nodes()
+        LOG.debug('Mon nodes list {0}'.format(mon_nodes))
+        before_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        failed_tests = [test['name'] for test in
+                        before_result if 'passed' not in test['outcome']]
+        # STEP #5
+
+        sl_deployed.stop_sl_service_on_node('mon01', 'influxdb')
+        sl_deployed.stop_sl_service_on_node('mon02', 'influxdb')
+        # STEP #6
+
+        sl_deployed.post_data_into_influx('mon03')
+        # STEP #7
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon03')
+        # STEP #8
+
+        sl_deployed.start_service('mon01', 'influxdb')
+        sl_deployed.start_service('mon02', 'influxdb')
+        # STEP #9
+
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon01')
+        assert 'mymeas' in sl_deployed.check_data_in_influxdb('mon02')
+        # STEP #10
+      
+        after_result = sl_deployed.run_sl_tests_json(
+            'cfg01', '/root/stacklight-pytest/stacklight_tests/',
+            'tests/prometheus/', 'test_alerts.py')
+        for test in after_result:
+            if test['name'] not in failed_tests:
+                assert 'passed' in test['outcome'], \
+                    'Failed test {}'.format(test)
         LOG.info("*************** DONE **************")