Bugfix: functest only keeps the last test case's log 51/40051/3
authorxudan <xudan16@huawei.com>
Thu, 24 Aug 2017 02:18:31 +0000 (22:18 -0400)
committerxudan <xudan16@huawei.com>
Mon, 28 Aug 2017 06:58:00 +0000 (02:58 -0400)
JIRA: DOVETAIL-490

1. Dovetail just keeps the last tempest/defcore/ipv6/bgpvpn test's log file.
2. All log files should be kept, so users and developers can know the reason
   of failed test cases.
3. tempest logs will be stored in directory tempest_logs/
4. defcore logs will be stored in directory defcore_logs/
5. IPv6 logs will be stored in directory ipv6_logs/
6. bgpvpn logs will be stored in directory bgpvpn_logs/
7. All vping logs are in functest.log

Change-Id: I79eae79cb32d65ce1ada3dd6f4c6dfd3945fc512
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/test_runner.py
dovetail/testcase.py

index 603156f..b520196 100644 (file)
@@ -113,6 +113,9 @@ class DockerRunner(object):
 
         Container.clean(container_id, self.type)
 
+    def save_logs(self):
+        pass
+
 
 class FunctestRunner(DockerRunner):
 
@@ -120,6 +123,27 @@ class FunctestRunner(DockerRunner):
         self.type = 'functest'
         super(FunctestRunner, self).__init__(testcase)
 
+    def save_logs(self):
+        validate_testcase = self.testcase.validate_testcase()
+        test_area = self.testcase.name().split(".")[1]
+        result_path = os.path.join(os.environ["DOVETAIL_HOME"], 'results')
+        dest_path = os.path.join(result_path, test_area + '_logs')
+        dest_file = os.path.join(dest_path, self.testcase.name() + '.log')
+        if validate_testcase == 'tempest_custom':
+            source_file = os.path.join(result_path, 'tempest', 'tempest.log')
+        elif validate_testcase == 'refstack_defcore':
+            source_file = os.path.join(result_path, 'refstack', 'refstack.log')
+        elif validate_testcase == 'bgpvpn':
+            source_file = os.path.join(result_path, 'bgpvpn.log')
+        else:
+            source_file = None
+        if source_file:
+            if os.path.isfile(source_file):
+                os.renames(source_file, dest_file)
+            else:
+                self.logger.error("Tempest log file for test case {} is not "
+                                  "found.".format(self.testcase.name()))
+
 
 class YardstickRunner(DockerRunner):
 
index bdfd3d3..b681996 100644 (file)
@@ -157,6 +157,7 @@ class Testcase(object):
         runner = TestRunnerFactory.create(self)
         try:
             runner.run()
+            runner.save_logs()
         except AttributeError as e:
             self.logger.exception(
                 'Test case: {} Exception: {}'.format(self.name, e))