Merge "Add virtlet confirmance test run"
diff --git a/tcp_tests/fixtures/k8s_fixtures.py b/tcp_tests/fixtures/k8s_fixtures.py
index 356a51b..50635d3 100644
--- a/tcp_tests/fixtures/k8s_fixtures.py
+++ b/tcp_tests/fixtures/k8s_fixtures.py
@@ -15,6 +15,7 @@
 import pytest
 
 from tcp_tests.helpers import ext
+from tcp_tests.helpers import utils
 from tcp_tests import logger
 from tcp_tests.managers import k8smanager
 
@@ -80,3 +81,19 @@
                             args='systemctl restart keepalived.service')
 
     return k8s_actions
+
+
+@pytest.fixture(scope='function', autouse=True)
+def grab_virtlet_results(request, func_name, underlay, k8s_deployed):
+    """Finalizer to extract virtlet conformance logs"""
+
+    grab_virtlet_result = request.keywords.get('grab_virtlet_results', None)
+
+    def test_fin():
+        if hasattr(request.node, 'rep_call') and \
+                (request.node.rep_call.passed or request.node.rep_call.failed)\
+                and grab_virtlet_result:
+            artifact_name = utils.extract_name_from_mark(grab_virtlet_result) \
+                            or "{}".format(func_name)
+            k8s_deployed.download_virtlet_conformance_log(artifact_name)
+    request.addfinalizer(test_fin)
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index 6394141..1126011 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -12,6 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import os
 import time
 from uuid import uuid4
 
@@ -496,3 +497,44 @@
                "tail -n +3 | awk {{'print $2'}}".format(domain_id))
         result = self.__underlay.check_call(cmd, node_name=self.ctl_host)
         return result['stdout'].strip()
+
+    def run_virtlet_conformance(self, timeout=60 * 60,
+                                log_file='virtlet_conformance.log'):
+        if self.__config.k8s.run_extended_virtlet_conformance:
+            ci_image = "cloud-images.ubuntu.com/xenial/current/" \
+                       "xenial-server-cloudimg-amd64-disk1.img"
+            cmd = ("set -o pipefail; "
+                   "docker run --net=host {0} /virtlet-e2e-tests "
+                   "-include-cloud-init-tests -image {2} "
+                   "-sshuser ubuntu -memoryLimit 1024 "
+                   "-alsologtostderr -cluster-url http://127.0.0.1:8080 "
+                   "-ginkgo.focus '\[Conformance\]' "
+                   "| tee {1}".format(
+                    self.__config.k8s_deploy.kubernetes_virtlet_image,
+                    log_file, ci_image))
+        else:
+            cmd = ("set -o pipefail; "
+                   "docker run --net=host {0} /virtlet-e2e-tests "
+                   "-alsologtostderr -cluster-url http://127.0.0.1:8080 "
+                   "-ginkgo.focus '\[Conformance\]' "
+                   "| tee {1}".format(
+                    self.__config.k8s_deploy.kubernetes_virtlet_image,
+                    log_file))
+        LOG.info("Executing: {}".format(cmd))
+        with self.__underlay.remote(
+                node_name=self.ctl_host) as remote:
+            result = remote.check_call(cmd, timeout=timeout)
+            stderr = result['stderr']
+            stdout = result['stdout']
+            LOG.info("Test results stdout: {}".format(stdout))
+            LOG.info("Test results stderr: {}".format(stderr))
+        return result
+
+    def download_virtlet_conformance_log(self,
+                                         log_file='virtlet_conformance.log'):
+        master_host = self.__config.salt.salt_master_host
+        with self.__underlay.remote(host=master_host) as r:
+            cmd = "rsync {0}:/root/{1} /root/".format(self.ctl_host, log_file)
+            r.check_call(cmd, raise_on_err=False)
+            LOG.info("Downloading the artifact {0}".format(log_file))
+            r.download(destination=log_file, target=os.getcwd())
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index 0b69c58..8129f68 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -302,6 +302,8 @@
            help="", default=443),
     ct.Cfg("k8s_conformance_run", ct.Boolean(),
            default=False),
+    ct.Cfg("run_extended_virtlet_conformance", ct.Boolean(),
+           default=False),
     ct.Cfg('k8s_conformance_image', ct.String(),
            default='docker-prod-virtual.docker.mirantis.net/mirantis/'
                    'kubernetes/k8s-conformance:v1.7.5-2')
diff --git a/tcp_tests/tests/system/test_virtlet_actions.py b/tcp_tests/tests/system/test_virtlet_actions.py
index 0dbc296..21f7454 100644
--- a/tcp_tests/tests/system/test_virtlet_actions.py
+++ b/tcp_tests/tests/system/test_virtlet_actions.py
@@ -89,6 +89,20 @@
         show_step(4)
         k8s_deployed.delete_vm(target_yaml)
 
+    @pytest.mark.grab_versions
+    @pytest.mark.grab_virtlet_results(name='virtlet_conformance.log')
+    @pytest.mark.fail_snapshot
+    def test_virtlet_conformance(self, show_step, config, k8s_deployed):
+        """Test run of virtlet conformance tests
+
+        Scenario:
+            1. Perform virtlet conformance
+
+        """
+
+        show_step(1)
+        k8s_deployed.run_virtlet_conformance()
+
     @pytest.mark.skip(reason="No configuration with ceph and k8s")
     def test_rbd_flexvolume_driver(self, show_step, config, k8s_deployed):
         """Test for deploying a VM with Ceph RBD volume using flexvolumeDriver