Bugfix: tar results dir cannot be parsed by web portal 31/43131/2
authorxudan <xudan16@huawei.com>
Tue, 26 Sep 2017 07:44:13 +0000 (03:44 -0400)
committerxudan <xudan16@huawei.com>
Tue, 26 Sep 2017 08:09:35 +0000 (04:09 -0400)
The directory tree of results tar file is wrong, so web portal cannot parse it.
Reset the tar file.

JIRA: DOVETAIL-508

Change-Id: I8475323294e84ca51242b700570926d5c0177390
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/report.py

index fa6a0ba..995b332 100644 (file)
@@ -14,6 +14,7 @@ import re
 import os
 import datetime
 import tarfile
+import time
 
 from pbr import version
 
@@ -165,14 +166,19 @@ class Report(object):
 
     @classmethod
     def save_logs(cls):
-        logs_gz = "logs.tar.gz"
+        file_suffix = time.strftime('%d_%H_%M', time.localtime(time.time()))
+        logs_gz = "logs_{}.tar.gz".format(file_suffix)
         result_dir = dt_cfg.dovetail_config['result_dir']
 
-        with tarfile.open(os.path.join(result_dir, logs_gz), "w:gz") as f_out:
+        cwd = os.getcwd()
+        os.chdir(os.path.join(result_dir, '..'))
+        tar_file = os.path.join(result_dir, '..', logs_gz)
+        with tarfile.open(tar_file, "w:gz") as f_out:
             files = os.listdir(result_dir)
             for f in files:
                 if f not in ['workspace']:
-                    f_out.add(os.path.join(result_dir, f))
+                    f_out.add(os.path.join('results', f))
+        os.chdir(cwd)
 
     # save to disk as default
     @classmethod