Add shared sl tests yaml

Change-Id: Ic9422d44e58e2ce5d08a6371a855b7e60f8766e2
Reviewed-on: https://review.gerrithub.io/377203
Reviewed-by: Tatyanka Leontovich <tleontovich@mirantis.com>
Tested-by: Tatyanka Leontovich <tleontovich@mirantis.com>
diff --git a/tcp_tests/managers/k8s/cluster.py b/tcp_tests/managers/k8s/cluster.py
index 424ab32..4bda03f 100644
--- a/tcp_tests/managers/k8s/cluster.py
+++ b/tcp_tests/managers/k8s/cluster.py
@@ -58,7 +58,7 @@
             auth = base64.encodestring(auth_string.encode()).decode()[:-1]
             auth = "Basic {}".format(auth)
             self._client = api_client.ApiClient(
-                '{schema}://{host}:{port}/'.format(
+                '{schema}://{host}:{port}'.format(
                     schema=schema, host=host, port=port))
             self._client.set_default_header('Authorization', auth)
             restcli_impl = self._client.RESTClient.IMPL
@@ -67,7 +67,7 @@
 
         else:
             self._client = api_client.ApiClient(
-                '{schema}://{host}:{port}/'.format(
+                '{schema}://{host}:{port}'.format(
                     schema=schema, host=host, port=port))
         self._api = apiv_api.ApivApi(self._client)
         self._bapi = apisbatchv_api.ApisbatchvApi(self._client)
diff --git a/tcp_tests/managers/sl_manager.py b/tcp_tests/managers/sl_manager.py
index ccb6030..705816d 100644
--- a/tcp_tests/managers/sl_manager.py
+++ b/tcp_tests/managers/sl_manager.py
@@ -12,6 +12,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import os
+
 from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
 from tcp_tests.managers.clients.prometheus import prometheus_client
 from tcp_tests import logger
@@ -76,3 +78,22 @@
                 tmp = line.split(':')
                 service_stat_dict.update({tmp[0]: tmp[1]})
         return service_stat_dict
+
+    def run_sl_functional_tests(self, node_to_run, path_tests_to_run):
+        target_node_name = [node_name for node_name
+                            in self.__underlay.node_names()
+                            if node_to_run in node_name]
+        with self.__underlay.remote(node_name=target_node_name[0]) as node_remote:
+            cmd = "python -k {}".format(path_tests_to_run)
+            result = node_remote.execute(cmd)
+            LOG.debug("Test execution result is {}".format(result))
+        return result
+
+    def download_sl_test_report(self, stored_node, file_path):
+        target_node_name = [node_name for node_name
+                            in self.__underlay.node_names()
+                            if stored_node in node_name]
+        with self.__underlay.remote(node_name=target_node_name[0]) as r:
+            r.download(
+                destination=file_path,
+                target=os.getcwd())
diff --git a/tcp_tests/templates/shared-sl-tests.yaml b/tcp_tests/templates/shared-sl-tests.yaml
new file mode 100644
index 0000000..e0f7823
--- /dev/null
+++ b/tcp_tests/templates/shared-sl-tests.yaml
@@ -0,0 +1,34 @@
+{# Collection of sl tests macroses shared across different deployments #}
+
+{% set SL_TEST_BRANCH = os_env('SL_TEST_BRANCH','master') %}
+{% set SL_TEST_REPO = os_env('SL_TEST_REPO','https://github.com/dkalashnik/stacklight-pytest') %}
+{% set SL_TEST_TO_RUN = os_env('set SL_TEST_TO_RUN','stacklight_tests/tests/prometheus/test_smoke.py') %}
+
+{%- macro MACRO_CLONE_SL_TESTS() %}
+{############################################################}
+- description: Clone repo and install tests on cfg node
+  cmd: |
+    set -e;
+    git clone -b {{ SL_TEST_BRANCH }} {{ SL_TEST_REPO }} /root/stacklight-pytest;
+    cd /root/stacklight-pytest;
+    python setup.py sdist;
+    pip install dist/stacklight_tests-1.0.tar.gz --process-dependency-links
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 1}
+  skip_fail: false
+{%- endmacro %}
+
+
+{%- macro MACRO_CONFIGURE_TESTS() %}
+{#######################################################}
+- description: Configure tests
+  cmd: |
+    set -e;
+    stl-tests gen-config-mk;
+    cp /usr/local/lib/python2.7/dist-packages/stacklight_tests/fixtures/config.yaml /root/stacklight-pytest/stacklight_tests/fixtures/config.yaml;
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 1}
+  skip_fail: false
+{%- endmacro %}
+
+
diff --git a/tcp_tests/templates/virtual-mcp-ocata-dvr/sl.yaml b/tcp_tests/templates/virtual-mcp-ocata-dvr/sl.yaml
index b5d7bc5..c5c710a 100644
--- a/tcp_tests/templates/virtual-mcp-ocata-dvr/sl.yaml
+++ b/tcp_tests/templates/virtual-mcp-ocata-dvr/sl.yaml
@@ -1,5 +1,5 @@
 {% from 'virtual-mcp-ocata-dvr/underlay.yaml' import HOSTNAME_CFG01 with context %}
-
+{% import 'shared-sl-tests.yaml' as SHARED_SL_TESTS with context %}
 # Install docker swarm
 - description: Install keepalived on mon nodes
   cmd: salt --hard-crash --state-output=mixed --state-verbose=False
@@ -139,19 +139,7 @@
 - description: Update mine
   cmd: salt -C 'I@salt:minion' mine.update; sleep 5;
   node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 10}
-  skip_fail: false
-
-# Change environment configuration before deploy
-- description: Set SL docker images deploy parameters
-  cmd: |
-  {% for sl_opt, value in config.sl_deploy.items() %}
-    {% if value|string() %}
-    salt-call reclass.cluster_meta_set {{ sl_opt }} {{ value }};
-    {% endif %}
-  {% endfor %}
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
+  retry: {count: 5, delay: 15}
   skip_fail: false
 
 # Configure the services running in Docker Swarm
@@ -185,3 +173,5 @@
   retry: {count: 1, delay: 10}
   skip_fail: false
 
+{{  SHARED_SL_TESTS.MACRO_CLONE_SL_TESTS() }}
+{{  SHARED_SL_TESTS.MACRO_CONFIGURE_TESTS() }}
diff --git a/tcp_tests/templates/virtual-mcp11-k8s-contrail/sl.yaml b/tcp_tests/templates/virtual-mcp11-k8s-contrail/sl.yaml
index d277c56..f7fb360 100644
--- a/tcp_tests/templates/virtual-mcp11-k8s-contrail/sl.yaml
+++ b/tcp_tests/templates/virtual-mcp11-k8s-contrail/sl.yaml
@@ -123,19 +123,7 @@
 - description: Update mine
   cmd: salt -C 'I@salt:minion' mine.update; sleep 5;
   node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 10}
-  skip_fail: false
-
-# Change environment configuration before deploy
-- description: Set SL docker images deploy parameters
-  cmd: |
-  {% for sl_opt, value in config.sl_deploy.items() %}
-    {% if value|string() %}
-    salt-call reclass.cluster_meta_set {{ sl_opt }} {{ value }};
-    {% endif %}
-  {% endfor %}
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
+  retry: {count: 3, delay: 10}
   skip_fail: false
 
 # Configure the services running in Docker Swarm
diff --git a/tcp_tests/tests/system/test_install_mcp11_ovs_ocata.py b/tcp_tests/tests/system/test_install_mcp11_ovs_ocata.py
index b06b991..d46d33f 100644
--- a/tcp_tests/tests/system/test_install_mcp11_ovs_ocata.py
+++ b/tcp_tests/tests/system/test_install_mcp11_ovs_ocata.py
@@ -24,6 +24,7 @@
     """Test class for testing mcp11 vxlan deploy"""
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8119
     def test_mcp11_ocata_ovs_install(self, underlay, openstack_deployed,
                                           show_step):
         """Test for deploying an mcp environment and check it
@@ -36,6 +37,7 @@
         LOG.info("*************** DONE **************")
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8119
     def test_mcp11_ocata_ovs_sl_install(self, underlay, config,
                                         openstack_deployed,
                                         sl_deployed, sl_actions, show_step):
@@ -88,9 +90,18 @@
         for entry in current_targets:
             assert 'up' in entry['health'], \
                 'Next target is down {}'.format(entry)
+        # Run SL component tetsts
+        sl_actions.run_sl_functional_tests(
+            'cfg01',
+            '/root/stacklight-pytest/stacklight_tests/tests/prometheus')
+        # Download report
+        sl_actions.download_sl_test_report(
+            'cfg01',
+            '/root/stacklight-pytest/stacklight_tests')
         LOG.info("*************** DONE **************")
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8120
     def test_mcp11_ocata_dvr_install(self, underlay, openstack_deployed,
                                           show_step):
         """Test for deploying an mcp environment and check it
@@ -103,6 +114,7 @@
         LOG.info("*************** DONE **************")
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8120
     def test_mcp11_ocata_dvr_sl_install(self, underlay, config,
                                         openstack_deployed,
                                         sl_deployed, sl_actions, show_step):
@@ -155,9 +167,23 @@
         for entry in current_targets:
             assert 'up' in entry['health'], \
                 'Next target is down {}'.format(entry)
+
+            # Assert that targets are up
+            for entry in current_targets:
+                assert 'up' in entry['health'], \
+                    'Next target is down {}'.format(entry)
+        # Run SL component tetsts
+        sl_actions.run_sl_functional_tests(
+            'cfg01',
+            '/root/stacklight-pytest/stacklight_tests/tests/prometheus')
+        # Download report
+        sl_actions.download_sl_test_report(
+            'cfg01',
+            '/root/stacklight-pytest/stacklight_tests')
         LOG.info("*************** DONE **************")
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8117
     def test_mcp11_ocata_dpdk_install(self, underlay, openstack_deployed,
                                       show_step):
         """Test for deploying an mcp dpdk environment and check it
@@ -169,6 +195,7 @@
         LOG.info("*************** DONE **************")
 
     @pytest.mark.fail_snapshot
+    @pytest.mark.cz8117
     def test_mcp11_ocata_dvr_decapod_install(self, underlay, decapod_deployed,
                                              openstack_deployed, show_step):
         """Test for deploying an mcp dpdk environment and check it