Merge "Update unit test related to vyos_vrouter"
[functest.git] / functest / opnfv_tests / openstack / refstack_client / refstack_client.py
index 220b08f..42befe2 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
+
 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
-# matthew.lijun@huawei.com wangwulin@huawei.com
+#
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Apache License, Version 2.0
 # which accompanies this distribution, and is available at
@@ -10,7 +11,6 @@
 
 from __future__ import division
 
-
 import argparse
 import logging
 import os
@@ -28,7 +28,9 @@ from functest.opnfv_tests.openstack.refstack_client.tempest_conf \
 from functest.opnfv_tests.openstack.tempest import conf_utils
 from functest.utils.constants import CONST
 import functest.utils.functest_utils as ft_utils
-import functest.utils.openstack_utils as os_utils
+
+__author__ = ("Matthew Li <matthew.lijun@huawei.com>,"
+              "Linda Wang <wangwulin@huawei.com>")
 
 # logging configuration """
 LOGGER = logging.getLogger(__name__)
@@ -42,10 +44,10 @@ class RefstackClient(testcase.TestCase):
         if "case_name" not in kwargs:
             kwargs["case_name"] = "refstack_defcore"
         super(RefstackClient, self).__init__(**kwargs)
+        self.tempestconf = None
         self.conf_path = pkg_resources.resource_filename(
             'functest',
             'opnfv_tests/openstack/refstack_client/refstack_tempest.conf')
-        self.tempestconf = None
         self.functest_test = pkg_resources.resource_filename(
             'functest', 'opnfv_tests')
         self.defcore_list = 'openstack/refstack_client/defcore.txt'
@@ -59,6 +61,13 @@ class RefstackClient(testcase.TestCase):
                 CONST.__getattribute__('OS_INSECURE').lower() == 'true'):
             self.insecure = '-k'
 
+    def generate_conf(self):
+        if not os.path.exists(conf_utils.REFSTACK_RESULTS_DIR):
+            os.makedirs(conf_utils.REFSTACK_RESULTS_DIR)
+
+        self.tempestconf = TempestConf()
+        self.tempestconf.generate_tempestconf()
+
     def run_defcore(self, conf, testlist):
         """Run defcore sys command."""
         cmd = ("refstack-client test {0} -c {1} -v --test-list {2}"
@@ -70,7 +79,7 @@ class RefstackClient(testcase.TestCase):
         """Run default defcore sys command."""
         options = ["-v"] if not self.insecure else ["-v", self.insecure]
         cmd = (["refstack-client", "test", "-c", self.confpath] +
-               options + ["--test-list",  self.defcorelist])
+               options + ["--test-list", self.defcorelist])
         LOGGER.info("Starting Refstack_defcore test case: '%s'.", cmd)
 
         with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
@@ -89,8 +98,16 @@ class RefstackClient(testcase.TestCase):
                             stderr=subprocess.STDOUT)
 
     def parse_refstack_result(self):
-        """Parse Refstact results."""
+        """Parse Refstack results."""
         try:
+            with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
+                                   "refstack.log"), 'r') as logfile:
+                for line in logfile.readlines():
+                    if 'Tests' in line:
+                        break
+                    if re.search(r"\} tempest\.", line):
+                        LOGGER.info(line.replace('\n', ''))
+
             with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
                                    "refstack.log"), 'r') as logfile:
                 output = logfile.read()
@@ -146,12 +163,10 @@ class RefstackClient(testcase.TestCase):
         """
         self.start_time = time.time()
 
-        if not os.path.exists(conf_utils.REFSTACK_RESULTS_DIR):
-            os.makedirs(conf_utils.REFSTACK_RESULTS_DIR)
-
         try:
-            self.tempestconf = TempestConf()
-            self.tempestconf.generate_tempestconf()
+            # Make sure that Tempest is configured
+            if not self.tempestconf:
+                self.generate_conf()
             self.run_defcore_default()
             self.parse_refstack_result()
             res = testcase.TestCase.EX_OK
@@ -198,41 +213,6 @@ class RefstackClient(testcase.TestCase):
 
         return res
 
-    def create_snapshot(self):
-        """
-        Run the Tempest cleanup utility to initialize OS state.
-        For details, see https://docs.openstack.org/tempest/latest/cleanup.html
-
-        :return: TestCase.EX_OK
-        """
-        LOGGER.info("Initializing the saved state of the OpenStack deployment")
-
-        # Make sure that the verifier is configured
-        conf_utils.configure_verifier(self.tempestconf.DEPLOYMENT_DIR)
-
-        os_utils.init_tempest_cleanup(
-            self.tempestconf.DEPLOYMENT_DIR, 'tempest.conf',
-            os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
-                         "tempest-cleanup-init.log")
-        )
-
-        return super(RefstackClient, self).create_snapshot()
-
-    def clean(self):
-        """
-        Run the Tempest cleanup utility to delete and destroy OS resources.
-        For details, see https://docs.openstack.org/tempest/latest/cleanup.html
-        """
-        LOGGER.info("Initializing the saved state of the OpenStack deployment")
-
-        os_utils.init_tempest_cleanup(
-            self.tempestconf.DEPLOYMENT_DIR, 'tempest.conf',
-            os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
-                         "tempest-cleanup.log")
-        )
-
-        return super(RefstackClient, self).clean()
-
 
 class RefstackClientParser(object):  # pylint: disable=too-few-public-methods
     """Command line argument parser helper."""