aboutsummaryrefslogtreecommitdiff
path: root/kolla/tests
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/tests
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/tests')
-rw-r--r--kolla/tests/test_build.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py
index eb42595b8..5b748ef13 100644
--- a/kolla/tests/test_build.py
+++ b/kolla/tests/test_build.py
@@ -727,6 +727,53 @@ class KollaWorkerTest(base.TestCase):
self.assertEqual('error', results['failed'][0]['status']) # bad
self.assertEqual('error', results['failed'][1]['status']) # bad2
+ @mock.patch('json.dump')
+ def test_summary_json_format(self, dump_mock):
+ self.conf.set_override('format', 'json')
+ kolla = build.KollaWorker(self.conf)
+ kolla.images = self.images
+ kolla.image_statuses_good['good'] = build.Status.BUILT
+ kolla.image_statuses_bad['bad'] = build.Status.ERROR
+ kolla.image_statuses_allowed_to_fail['bad2'] = build.Status.ERROR
+ kolla.image_statuses_unmatched['unmatched'] = build.Status.UNMATCHED
+ results = kolla.summary()
+ dump_mock.assert_called_once_with(results, sys.stdout)
+
+ @mock.patch('json.dump')
+ def test_summary_json_format_file(self, dump_mock):
+ tmpdir = tempfile.mkdtemp()
+ file_path = os.path.join(tmpdir, 'summary.json')
+ try:
+ self.conf.set_override('format', 'json')
+ self.conf.set_override('summary_json_file', file_path)
+ kolla = build.KollaWorker(self.conf)
+ kolla.images = self.images
+ kolla.image_statuses_good['good'] = build.Status.BUILT
+ kolla.image_statuses_bad['bad'] = build.Status.ERROR
+ kolla.image_statuses_allowed_to_fail['bad2'] = build.Status.ERROR
+ kolla.image_statuses_unmatched['unmatched'] = (
+ build.Status.UNMATCHED)
+ results = kolla.summary()
+ dump_mock.assert_called_once_with(results, mock.ANY, indent=4)
+ self.assertEqual(dump_mock.call_args[0][1].name, file_path)
+ finally:
+ os.remove(file_path)
+ os.rmdir(tmpdir)
+
+ @mock.patch('builtins.open')
+ def test_summary_json_format_file_error(self, open_mock):
+ open_mock.side_effect = OSError
+ self.conf.set_override('format', 'json')
+ self.conf.set_override('summary_json_file', 'fake-file')
+ kolla = build.KollaWorker(self.conf)
+ kolla.images = self.images
+ kolla.image_statuses_good['good'] = build.Status.BUILT
+ kolla.image_statuses_bad['bad'] = build.Status.ERROR
+ kolla.image_statuses_allowed_to_fail['bad2'] = build.Status.ERROR
+ kolla.image_statuses_unmatched['unmatched'] = (
+ build.Status.UNMATCHED)
+ self.assertRaises(SystemExit, kolla.summary)
+
@mock.patch('shutil.copytree')
def test_work_dir(self, copytree_mock):
self.conf.set_override('work_dir', 'tmp/foo')