Browse Source

Merge "Read old json data right before writing new data"

tags/3.4.0
Zuul 5 months ago
parent
commit
e2520b93c3
1 changed files with 9 additions and 8 deletions
  1. 9
    8
      zuul/ansible/callback/zuul_json.py

+ 9
- 8
zuul/ansible/callback/zuul_json.py View File

@@ -55,7 +55,6 @@ class CallbackModule(CallbackBase):
55 55
     def __init__(self, display=None):
56 56
         super(CallbackModule, self).__init__(display)
57 57
         self.results = []
58
-        self.output = []
59 58
         self.playbook = {}
60 59
         logging_config = logconfig.load_job_config(
61 60
             os.environ['ZUUL_JOB_LOG_CONFIG'])
@@ -63,11 +62,6 @@ class CallbackModule(CallbackBase):
63 62
         self.output_path = os.path.splitext(
64 63
             logging_config.job_output_file)[0] + '.json'
65 64
 
66
-        # For now, just read in the old file and write it all out again
67
-        # This may well not scale from a memory perspective- but let's see how
68
-        # it goes.
69
-        if os.path.exists(self.output_path):
70
-            self.output = json.load(open(self.output_path, 'r'))
71 65
         self._playbook_name = None
72 66
 
73 67
     def _new_playbook(self, play):
@@ -173,9 +167,16 @@ class CallbackModule(CallbackBase):
173 167
 
174 168
         self.playbook['plays'] = self.results
175 169
         self.playbook['stats'] = summary
176
-        self.output.append(self.playbook)
177 170
 
178
-        json.dump(self.output, open(self.output_path, 'w'),
171
+        # For now, just read in the old file and write it all out again
172
+        # This may well not scale from a memory perspective- but let's see how
173
+        # it goes.
174
+        output = []
175
+        if os.path.exists(self.output_path):
176
+            output = json.load(open(self.output_path, 'r'))
177
+        output.append(self.playbook)
178
+
179
+        json.dump(output, open(self.output_path, 'w'),
179 180
                   indent=4, sort_keys=True, separators=(',', ': '))
180 181
 
181 182
     v2_runner_on_failed = v2_runner_on_ok

Loading…
Cancel
Save