Wait for refstack-client to finish 37/37537/4
authorCédric Ollivier <cedric.ollivier@orange.com>
Fri, 14 Jul 2017 19:05:17 +0000 (21:05 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Mon, 17 Jul 2017 01:07:30 +0000 (03:07 +0200)
The previous implementation waited for /bin/sh to finish instead of
refstack-client. Then tempest still ran in background even if the
tescase was considered as finished.

Now all tempest logs are only printed in the dedicated file.

Change-Id: I94cd7c6fe68f3bc21782d8d9c43feee338c103ae
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/opnfv_tests/openstack/refstack_client/refstack_client.py

index 6ac7217..76bee19 100644 (file)
@@ -65,39 +65,26 @@ class RefstackClient(testcase.OSGCTestCase):
         ft_utils.execute_command(cmd)
 
     def run_defcore_default(self):
-        """Run default defcare sys command."""
-        cmd = ("refstack-client test {0} -c {1} -v --test-list {2}"
-               .format(self.insecure, self.confpath, self.defcorelist))
+        """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])
         LOGGER.info("Starting Refstack_defcore test case: '%s'.", cmd)
 
-        header = ("Refstack environment:\n"
-                  "  SUT: %s\n  Scenario: %s\n  Node: %s\n  Date: %s\n" %
-                  (CONST.__getattribute__('INSTALLER_TYPE'),
-                   CONST.__getattribute__('DEPLOY_SCENARIO'),
-                   CONST.__getattribute__('NODE_NAME'),
-                   time.strftime("%a %b %d %H:%M:%S %Z %Y")))
-
-        f_stdout = open(
-            os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
-                         "refstack.log"), 'w+')
-        f_env = open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
-                                  "environment.log"), 'w+')
-        f_env.write(header)
-
-        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
-                                   stderr=subprocess.STDOUT, bufsize=1)
-
-        with process.stdout:
-            for line in iter(process.stdout.readline, b''):
-                if 'Tests' in line:
-                    break
-                if re.search(r"\} tempest\.", line):
-                    LOGGER.info(line.replace('\n', ''))
-                f_stdout.write(line)
-        process.wait()
-
-        f_stdout.close()
-        f_env.close()
+        with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
+                               "environment.log"), 'w+') as f_env:
+            f_env.write(
+                ("Refstack environment:\n"
+                 "  SUT: {}\n  Scenario: {}\n  Node: {}\n  Date: {}\n").format(
+                    CONST.__getattribute__('INSTALLER_TYPE'),
+                    CONST.__getattribute__('DEPLOY_SCENARIO'),
+                    CONST.__getattribute__('NODE_NAME'),
+                    time.strftime("%a %b %d %H:%M:%S %Z %Y")))
+
+        with open(os.path.join(conf_utils.REFSTACK_RESULTS_DIR,
+                               "refstack.log"), 'w+') as f_stdout:
+            subprocess.call(cmd, shell=False, stdout=f_stdout,
+                            stderr=subprocess.STDOUT)
 
     def parse_refstack_result(self):
         """Parse Refstact results."""