Don't always unpack image build results tuple, as it may be None
Change-Id: I21b1327da1de1bd3cc3018ba37715b0a19c1dbef Closes-Bug: #1587501
This commit is contained in:
parent
4ad1af1328
commit
b3e8ac8371
@ -738,6 +738,11 @@ class KollaWorker(object):
|
|||||||
|
|
||||||
|
|
||||||
def run_build():
|
def run_build():
|
||||||
|
"""Build container images.
|
||||||
|
|
||||||
|
:return: A 3-tuple containing bad, good, and unmatched container image
|
||||||
|
status dicts, or None if no images were built.
|
||||||
|
"""
|
||||||
conf = cfg.ConfigOpts()
|
conf = cfg.ConfigOpts()
|
||||||
common_config.parse(conf, sys.argv[1:], prog='kolla-build')
|
common_config.parse(conf, sys.argv[1:], prog='kolla-build')
|
||||||
|
|
||||||
@ -792,11 +797,12 @@ def run_build():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
bad_results, good_results, unmatched_results = run_build()
|
statuses = run_build()
|
||||||
if len(bad_results):
|
if statuses:
|
||||||
return 1
|
bad_results, good_results, unmatched_results = statuses
|
||||||
else:
|
if bad_results:
|
||||||
return 0
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -218,3 +218,30 @@ class KollaWorkerTest(base.TestCase):
|
|||||||
kolla.images = self.images
|
kolla.images = self.images
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
kolla.filter_images)
|
kolla.filter_images)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch.object(build, 'run_build')
|
||||||
|
class MainTest(base.TestCase):
|
||||||
|
|
||||||
|
def test_images_built(self, mock_run_build):
|
||||||
|
image_statuses = ({}, {'img': 'built'}, {})
|
||||||
|
mock_run_build.return_value = image_statuses
|
||||||
|
result = build.main()
|
||||||
|
self.assertEqual(0, result)
|
||||||
|
|
||||||
|
def test_images_unmatched(self, mock_run_build):
|
||||||
|
image_statuses = ({}, {}, {'img': 'unmatched'})
|
||||||
|
mock_run_build.return_value = image_statuses
|
||||||
|
result = build.main()
|
||||||
|
self.assertEqual(0, result)
|
||||||
|
|
||||||
|
def test_no_images_built(self, mock_run_build):
|
||||||
|
mock_run_build.return_value = None
|
||||||
|
result = build.main()
|
||||||
|
self.assertEqual(0, result)
|
||||||
|
|
||||||
|
def test_bad_images(self, mock_run_build):
|
||||||
|
image_statuses = ({'img': 'error'}, {}, {})
|
||||||
|
mock_run_build.return_value = image_statuses
|
||||||
|
result = build.main()
|
||||||
|
self.assertEqual(1, result)
|
||||||
|
Loading…
Reference in New Issue
Block a user