Merge "Add cookied-cicd-k8s-calico and cookied-cicd-k8s-calico-sl"
diff --git a/tcp_tests/fixtures/runtest_fixtures.py b/tcp_tests/fixtures/runtest_fixtures.py
new file mode 100644
index 0000000..6f13cba
--- /dev/null
+++ b/tcp_tests/fixtures/runtest_fixtures.py
@@ -0,0 +1,39 @@
+#    Copyright 2018 Mirantis, Inc.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    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 settings
+from tcp_tests.managers.runtestmanager import RuntestManager
+
+
+@pytest.fixture(scope='function')
+def tempest_actions(underlay, salt_actions):
+    """
+    Run tempest tests
+    """
+    tempest_threads = settings.TEMPEST_THREADS
+    tempest_exclude_test_args = settings.TEMPEST_EXCLUDE_TEST_ARGS
+    tempest_pattern = settings.TEMPEST_PATTERN
+    cluster_name = settings.LAB_CONFIG_NAME
+    domain_name = "{}.local".format(cluster_name)
+    target = settings.TEMPEST_TARGET
+    runtest = RuntestManager(
+        underlay, salt_actions,
+        cluster_name=cluster_name,
+        domain_name=domain_name,
+        tempest_threads=tempest_threads,
+        tempest_exclude_test_args=tempest_exclude_test_args,
+        tempest_pattern=tempest_pattern,
+        target=target)
+    return runtest
diff --git a/tcp_tests/helpers/oslo_cfg_types.py b/tcp_tests/helpers/oslo_cfg_types.py
index aff8db0..f7be2d7 100644
--- a/tcp_tests/helpers/oslo_cfg_types.py
+++ b/tcp_tests/helpers/oslo_cfg_types.py
@@ -133,5 +133,5 @@
         res = super(Cfg, self)._get_from_namespace(namespace, group_name)
         # Use the value from enviroment variable instead of config
         if hasattr(self, 'environment_value'):
-            res = (self.environment_value, res[1])
+            res = self.environment_value
         return res
diff --git a/tcp_tests/managers/runtestmanager.py b/tcp_tests/managers/runtestmanager.py
index 229a3ff..8957091 100644
--- a/tcp_tests/managers/runtestmanager.py
+++ b/tcp_tests/managers/runtestmanager.py
@@ -293,3 +293,13 @@
 
         return {'inspect': inspect,
                 'logs': logs}
+
+    def prepare_and_run_tempest(self, username='root'):
+        """
+        Run tempest tests
+        """
+        tempest_timeout = settings.TEMPEST_TIMEOUT
+        self.prepare()
+        test_res = self.run_tempest(tempest_timeout)
+        self.fetch_arficats(username=username)
+        self.save_runtime_logs(**test_res)
diff --git a/tcp_tests/settings.py b/tcp_tests/settings.py
index 169d089..50f3337 100644
--- a/tcp_tests/settings.py
+++ b/tcp_tests/settings.py
@@ -76,3 +76,8 @@
 TEMPEST_IMAGE_VERSION = os.environ.get('TEMPEST_IMAGE_VERSION', 'pike')
 TEMPEST_PATTERN = os.environ.get('TEMPEST_PATTERN', 'tempest')
 TEMPEST_TIMEOUT = int(os.environ.get('TEMPEST_TIMEOUT', 60 * 60 * 5))
+TEMPEST_THREADS = int(os.environ.get('TEMPEST_THREADS', 2))
+TEMPEST_EXCLUDE_TEST_ARGS = os.environ.get(
+    'TEMPEST_EXCLUDE_TEST_ARGS',
+    '--blacklist-file mcp_pike_lvm_skip.list')
+TEMPEST_TARGET = os.environ.get('TEMPEST_TARGET', 'gtw01')
diff --git a/tcp_tests/templates/shared-backup-restore.yaml b/tcp_tests/templates/shared-backup-restore.yaml
index c85e684..2ec4d5d 100644
--- a/tcp_tests/templates/shared-backup-restore.yaml
+++ b/tcp_tests/templates/shared-backup-restore.yaml
@@ -57,7 +57,7 @@
 - description: Refresh grains for the xtrabackup client node
   cmd: salt -C 'I@xtrabackup:client' saltutil.sync_grains
   node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
+  retry: {count: 5, delay: 10}
   skip_fail: false
 
 - description: Update the mine for the xtrabackup client node
@@ -65,7 +65,7 @@
     salt -C 'I@xtrabackup:client' mine.flush
     salt -C 'I@xtrabackup:client' mine.update
   node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
+  retry: {count: 3, delay: 5}
   skip_fail: false
 
 - description: Apply the xtrabackup client state
diff --git a/tcp_tests/templates/virtual-mcp-pike-dvr-ceph-rgw/ceph.yaml b/tcp_tests/templates/virtual-mcp-pike-dvr-ceph-rgw/ceph.yaml
index 30b046a..e2573e8 100644
--- a/tcp_tests/templates/virtual-mcp-pike-dvr-ceph-rgw/ceph.yaml
+++ b/tcp_tests/templates/virtual-mcp-pike-dvr-ceph-rgw/ceph.yaml
@@ -168,4 +168,3 @@
   skip_fail: false
 
 {{ BACKUP.MACRO_BACKUP_CEPH() }}
-{{ SHARED.RUN_NEW_TEMPEST() }}
\ No newline at end of file
diff --git a/tcp_tests/templates/virtual-mcp-pike-dvr-ssl-barbican/openstack.yaml b/tcp_tests/templates/virtual-mcp-pike-dvr-ssl-barbican/openstack.yaml
index 8a8e6c2..ce846bb 100644
--- a/tcp_tests/templates/virtual-mcp-pike-dvr-ssl-barbican/openstack.yaml
+++ b/tcp_tests/templates/virtual-mcp-pike-dvr-ssl-barbican/openstack.yaml
@@ -359,5 +359,3 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 3, delay: 5}
   skip_fail: false
-
-{{ SHARED.RUN_NEW_TEMPEST() }}
\ No newline at end of file
diff --git a/tcp_tests/templates/virtual-mcp-pike-dvr-ssl/openstack.yaml b/tcp_tests/templates/virtual-mcp-pike-dvr-ssl/openstack.yaml
index 2d13116..21b9d28 100644
--- a/tcp_tests/templates/virtual-mcp-pike-dvr-ssl/openstack.yaml
+++ b/tcp_tests/templates/virtual-mcp-pike-dvr-ssl/openstack.yaml
@@ -344,5 +344,3 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 3, delay: 5}
   skip_fail: false
-
-{{ SHARED.RUN_NEW_TEMPEST() }}
\ No newline at end of file
diff --git a/tcp_tests/templates/virtual-mcp-pike-dvr/openstack.yaml b/tcp_tests/templates/virtual-mcp-pike-dvr/openstack.yaml
index 8dba7d2..487d369 100644
--- a/tcp_tests/templates/virtual-mcp-pike-dvr/openstack.yaml
+++ b/tcp_tests/templates/virtual-mcp-pike-dvr/openstack.yaml
@@ -342,4 +342,3 @@
 {{ BACKUP.MACRO_BACKUP_BACKUPNINJA() }}
 {{ BACKUP.MACRO_BACKUP_XTRABACKUP() }}
 
-{{ SHARED.RUN_NEW_TEMPEST() }}
\ No newline at end of file
diff --git a/tcp_tests/templates/virtual-mcp-pike-ovs-ceph/ceph.yaml b/tcp_tests/templates/virtual-mcp-pike-ovs-ceph/ceph.yaml
index 2c5fddf..976e4bb 100644
--- a/tcp_tests/templates/virtual-mcp-pike-ovs-ceph/ceph.yaml
+++ b/tcp_tests/templates/virtual-mcp-pike-ovs-ceph/ceph.yaml
@@ -166,5 +166,3 @@
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 2, delay: 5}
   skip_fail: false
-
-{{ SHARED.RUN_NEW_TEMPEST() }}
\ No newline at end of file
diff --git a/tcp_tests/tests/system/conftest.py b/tcp_tests/tests/system/conftest.py
index 1214cd3..61dd8e2 100644
--- a/tcp_tests/tests/system/conftest.py
+++ b/tcp_tests/tests/system/conftest.py
@@ -27,6 +27,7 @@
 from tcp_tests.fixtures.k8s_fixtures import *  # noqa
 from tcp_tests.fixtures.drivetrain_fixtures import *  # noqa
 from tcp_tests.fixtures.day1_fixtures import *  # noqa
+from tcp_tests.fixtures.runtest_fixtures import * # noqa
 
 
 __all__ = sorted([  # sort for documentation
@@ -74,5 +75,7 @@
     'k8s_deployed',
     'day1_underlay',
     'day1_cfg_config',
-    'day1_salt_action'
+    'day1_salt_action',
+    # tempest
+    'tempest_actions'
 ])
diff --git a/tcp_tests/tests/system/test_install_mcp_ovs_pike.py b/tcp_tests/tests/system/test_install_mcp_ovs_pike.py
index c5138f0..f022e0b 100644
--- a/tcp_tests/tests/system/test_install_mcp_ovs_pike.py
+++ b/tcp_tests/tests/system/test_install_mcp_ovs_pike.py
@@ -14,8 +14,6 @@
 
 import pytest
 
-from tcp_tests.managers.runtestmanager import RuntestManager
-
 from tcp_tests import logger
 from tcp_tests import settings
 
@@ -32,8 +30,7 @@
     def test_mcp_pike_ovs_install(self, underlay,
                                   openstack_deployed,
                                   openstack_actions,
-                                  salt_actions,
-                                  config):
+                                  tempest_actions):
         """Test for deploying an mcp environment and check it
         Scenario:
         1. Prepare salt on hosts
@@ -45,27 +42,8 @@
         openstack_actions._salt.local(
             tgt='*', fun='cmd.run',
             args='service ntp stop; ntpd -gq; service ntp start')
-
         if settings.RUN_TEMPEST:
-            tempest_threads = 2
-            tempest_exclude_test_args = ''
-            tempest_pattern = settings.TEMPEST_PATTERN
-            cluster_name = settings.LAB_CONFIG_NAME
-            tempest_timeout = settings.TEMPEST_TIMEOUT
-            domain_name = "{}.local".format(cluster_name)
-            target = 'gtw01'
-            runtest = RuntestManager(
-                underlay, salt_actions,
-                cluster_name=cluster_name,
-                domain_name=domain_name,
-                tempest_threads=tempest_threads,
-                tempest_exclude_test_args=tempest_exclude_test_args,
-                tempest_pattern=tempest_pattern,
-                target=target)
-            runtest.prepare()
-            test_res = runtest.run_tempest(tempest_timeout)
-            runtest.fetch_arficats(username='root')
-            runtest.save_runtime_logs(**test_res)
+            tempest_actions.prepare_and_run_tempest()
 
         LOG.info("*************** DONE **************")
 
@@ -110,21 +88,21 @@
     def test_mcp_pike_dvr_install(self,
                                   underlay,
                                   openstack_deployed,
-                                  openstack_actions):
+                                  openstack_actions,
+                                  tempest_actions):
         """Test for deploying an mcp environment and check it
         Scenario:
         1. Prepare salt on hosts
         2. Setup controller nodes
         3. Setup compute nodes
-
+        4. Run tempest
         """
         openstack_actions._salt.local(
             tgt='*', fun='cmd.run',
             args='service ntp stop; ntpd -gq; service ntp start')
 
         if settings.RUN_TEMPEST:
-            openstack_actions.run_tempest(pattern=settings.PATTERN)
-            openstack_actions.download_tempest_report()
+            tempest_actions.prepare_and_run_tempest()
         LOG.info("*************** DONE **************")
 
     @pytest.mark.grab_versions
diff --git a/tcp_tests/tests/system/test_ovs_pike_ceph.py b/tcp_tests/tests/system/test_ovs_pike_ceph.py
index 080be26..1f62a94 100644
--- a/tcp_tests/tests/system/test_ovs_pike_ceph.py
+++ b/tcp_tests/tests/system/test_ovs_pike_ceph.py
@@ -26,9 +26,11 @@
 
     @pytest.mark.grab_versions
     @pytest.mark.fail_snapshot
-    def test_pike_ceph_all_ovs_install(self, underlay, openstack_deployed,
+    def test_pike_ceph_all_ovs_install(self, underlay,
+                                       openstack_deployed,
                                        ceph_deployed,
-                                       openstack_actions):
+                                       openstack_actions,
+                                       tempest_actions):
         """Test for deploying pike ovs with ceph and check it
         Scenario:
         1. Prepare salt on hosts
@@ -43,7 +45,5 @@
                 args='service ntp stop; ntpd -gq; service ntp start')
 
         if settings.RUN_TEMPEST:
-            openstack_actions.run_tempest(pattern=settings.PATTERN,
-                                          conf_name='ceph_mcp.conf')
-            openstack_actions.download_tempest_report()
+            tempest_actions.prepare_and_run_tempest()
         LOG.info("*************** DONE **************")