Browse Source

Fix log_url parsing for new job types

Previously, the log_dir was determined by taking the dirname() of the
log_url twice, which works when all collected 'testrepository.subunit'
files were located under 'logs/'. Now that the worker is collecting
subunit files from all jobs, this assumption can result in the Zuul
UUID being cut off from the generated log_dir. This change adds a
check to make sure path segments are only removed when the log_dir
is 'logs/' or 'logs/old/'.

Change-Id: I75c53c498261e44989cdb7bf49d909ebde2b2699
Tim Buckley 3 years ago
parent
commit
3663cc2be0
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      files/subunit-gearman-worker.py

+ 11
- 1
files/subunit-gearman-worker.py View File

@@ -180,7 +180,17 @@ class Subunit2SQLProcessor(object):
180 180
         # Set run metadata from gearman
181 181
         log_url = subunit.pop('log_url', None)
182 182
         if log_url:
183
-            log_dir = os.path.dirname(os.path.dirname(log_url))
183
+            log_dir = os.path.dirname(log_url)
184
+
185
+            # log_dir should be the top-level directory containing a job run,
186
+            # but the subunit file may be nested in 0 - 2 subdirectories (top,
187
+            # logs/, or logs/old/), so we need to safely correct the path here
188
+            log_base = os.path.basename(log_dir)
189
+            if log_base == 'logs':
190
+                log_dir = os.path.dirname(log_dir)
191
+            elif log_base == 'old':
192
+                log_dir = os.path.dirname(os.path.dirname(log_dir))
193
+
184 194
             shell.CONF.set_override('artifacts', log_dir)
185 195
         shell.CONF.set_override('run_meta', subunit)
186 196
         # Parse subunit stream and store in DB

Loading…
Cancel
Save