Record the test cases passed in tempest 71/38671/4
authorLinda Wang <wangwulin@huawei.com>
Thu, 3 Aug 2017 08:51:37 +0000 (08:51 +0000)
committerLinda Wang <wangwulin@huawei.com>
Wed, 9 Aug 2017 09:05:32 +0000 (09:05 +0000)
Also, convert the test cases recorded with string into list

Change-Id: Ie3980a555b4042e6fe9706320d33d4ec4c06ea0c
Signed-off-by: Linda Wang <wangwulin@huawei.com>
functest/opnfv_tests/openstack/refstack_client/refstack_client.py
functest/opnfv_tests/openstack/tempest/tempest.py
functest/tests/unit/openstack/refstack_client/test_refstack_client.py

index 76bee19..921d69b 100644 (file)
@@ -106,15 +106,15 @@ class RefstackClient(testcase.OSGCTestCase):
             for match in re.findall(r"(- Failed: )(\d+)", output):
                 num_failures = match[1]
                 LOGGER.info("".join(match))
-            success_testcases = ""
+            success_testcases = []
             for match in re.findall(r"\{0\}(.*?)[. ]*ok", output):
-                success_testcases += match + ", "
-            failed_testcases = ""
+                success_testcases.append(match)
+            failed_testcases = []
             for match in re.findall(r"\{0\}(.*?)[. ]*FAILED", output):
-                failed_testcases += match + ", "
-            skipped_testcases = ""
+                failed_testcases.append(match)
+            skipped_testcases = []
             for match in re.findall(r"\{0\}(.*?)[. ]*SKIPPED:", output):
-                skipped_testcases += match + ", "
+                skipped_testcases.append(match)
 
             num_executed = int(num_tests) - int(num_skipped)
 
index e565f5f..4993c74 100644 (file)
@@ -195,17 +195,21 @@ class TempestCommon(testcase.OSGCTestCase):
                                    "tempest.log"), 'r') as logfile:
                 output = logfile.read()
 
-            error_logs = ""
+            success_testcases = []
+            for match in re.findall('(.*?)[. ]*success ', output):
+                success_testcases.append(match)
+            failed_testcases = []
             for match in re.findall('(.*?)[. ]*fail ', output):
-                error_logs += match
-            skipped_testcase = ""
+                failed_testcases.append(match)
+            skipped_testcases = []
             for match in re.findall('(.*?)[. ]*skip:', output):
-                skipped_testcase += match
+                skipped_testcases.append(match)
 
             self.details = {"tests": int(num_tests),
                             "failures": int(num_failures),
-                            "errors": error_logs,
-                            "skipped": skipped_testcase}
+                            "success": success_testcases,
+                            "errors": failed_testcases,
+                            "skipped": skipped_testcases}
         except Exception:
             self.result = 0
 
index 51dbb64..e4e3364 100644 (file)
@@ -55,6 +55,38 @@ class OSRefstackClientTesting(unittest.TestCase):
             refstackclient.run_defcore(config, testlist)
             m.assert_any_call(cmd)
 
+    @mock.patch('functest.opnfv_tests.openstack.refstack_client.'
+                'refstack_client.LOGGER.info')
+    @mock.patch('__builtin__.open', side_effect=Exception)
+    def test_parse_refstack_result_missing_log_file(self, mock_open,
+                                                    mock_logger_info):
+        self.case_name = 'refstack_defcore'
+        self.result = 0
+        self.refstackclient.parse_refstack_result()
+        mock_logger_info.assert_called_once_with(
+            "Testcase %s success_rate is %s%%",
+            self.case_name, self.result)
+
+    def test_parse_refstack_result_default(self):
+        log_file = ('''
+                    {0} tempest.api.compute [18.464988s] ... ok
+                    {0} tempest.api.volume [0.230334s] ... FAILED
+                    {0} tempest.api.network [1.265828s] ... SKIPPED:
+                    Ran: 3 tests in 1259.0000 sec.
+                    - Passed: 1
+                    - Skipped: 1
+                    - Failed: 1
+                   ''')
+        self.details = {"tests": 3,
+                        "failures": 1,
+                        "success": [' tempest.api.compute [18.464988s]'],
+                        "errors": [' tempest.api.volume [0.230334s]'],
+                        "skipped": [' tempest.api.network [1.265828s]']}
+        with mock.patch('__builtin__.open',
+                        mock.mock_open(read_data=log_file)):
+            self.refstackclient.parse_refstack_result()
+            self.assertEqual(self.refstackclient.details, self.details)
+
     def _get_main_kwargs(self, key=None):
         kwargs = {'config': self._config,
                   'testlist': self._testlist}