aboutsummaryrefslogtreecommitdiff
path: root/kolla/image
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2023-04-20 16:32:54 +0100
committerMark Goddard <mark@stackhpc.com>2023-04-27 12:19:31 +0000
commita5351473e08ee18cbc86edfb52da708ad558fe85 (patch)
tree7caa13885a8d0559dd7d47f32a8c56715c1b1143 /kolla/image
parentbc2d3e4ef4aed12a5329f697967bd325339a7bff (diff)
downloadkolla-a5351473e08ee18cbc86edfb52da708ad558fe85.tar.gz
kolla-a5351473e08ee18cbc86edfb52da708ad558fe85.zip
Summary JSON file
Add support for writing the build summary to a JSON file. This is more machine-friendly than the current approach of writing to standard output at the end of the build. The file is configured via [DEFAULT] summary_json_file. Change-Id: I9868af5d00977750d0673fc48f8863a99f878dc8
Diffstat (limited to 'kolla/image')
-rw-r--r--kolla/image/build.py5
-rw-r--r--kolla/image/kolla_worker.py20
2 files changed, 21 insertions, 4 deletions
diff --git a/kolla/image/build.py b/kolla/image/build.py
index fdf1635c8..86f0d8a71 100644
--- a/kolla/image/build.py
+++ b/kolla/image/build.py
@@ -11,7 +11,6 @@
# limitations under the License.
import contextlib
-import json
import logging
import queue
import shutil
@@ -195,8 +194,6 @@ def run_build():
raise
if conf.summary:
- results = kolla.summary()
- if conf.format == 'json':
- print(json.dumps(results))
+ kolla.summary()
kolla.cleanup()
return kolla.get_image_statuses()
diff --git a/kolla/image/kolla_worker.py b/kolla/image/kolla_worker.py
index 1a665ddd4..e7ee35574 100644
--- a/kolla/image/kolla_worker.py
+++ b/kolla/image/kolla_worker.py
@@ -564,6 +564,26 @@ class KollaWorker(object):
'name': name,
})
+ if self.conf.format == 'json':
+
+ def json_summary(f, **kwargs):
+ json.dump(results, f, **kwargs)
+
+ if self.conf.summary_json_file:
+ try:
+ with open(self.conf.summary_json_file, "w") as f:
+ json_summary(f, indent=4)
+ except OSError as e:
+ LOG.error(f'Failed to write JSON build summary to '
+ '{self.conf.summary_json_file}')
+ LOG.error(f'Exception caught: {e}')
+ sys.exit(1)
+
+ else:
+ # NOTE(mgoddard): Keep single line output for
+ # backwards-compatibility.
+ json_summary(sys.stdout)
+
return results
def get_image_statuses(self):