Return the stdout of the kolla-build run

Now that kolla bugs #1694888 and #1694593 are fixed, some kolla-build
invocations return parsable results.

This change returns stdout to the caller so it can be used.

Change-Id: I523a52c2acaaa5acc377a41dc52edaccedd0151a
This commit is contained in:
Steve Baker 2017-06-22 09:14:59 +12:00
parent dc0b057f6e
commit 04adbb573d
2 changed files with 12 additions and 8 deletions

View File

@ -105,7 +105,8 @@ class KollaImageBuilder(base.BaseImageManager):
self.logger.info('Running %s' % ' '.join(cmd))
env = os.environ.copy()
process = subprocess.Popen(cmd, env=env)
process.wait()
process = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
out, err = process.communicate()
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, cmd)
raise subprocess.CalledProcessError(process.returncode, cmd, err)
return out

View File

@ -87,10 +87,11 @@ class TestKollaImageBuilder(base.TestCase):
def test_build_images(self, mock_popen, mock_path):
process = mock.Mock()
process.returncode = 0
process.communicate.return_value = 'done', ''
mock_popen.return_value = process
builder = kb.KollaImageBuilder(self.filelist)
builder.build_images(['kolla-config.conf'])
self.assertEqual('done', builder.build_images(['kolla-config.conf']))
env = os.environ.copy()
mock_popen.assert_called_once_with([
'kolla-build',
@ -100,25 +101,27 @@ class TestKollaImageBuilder(base.TestCase):
'nova-libvirt',
'heat-docker-agents-centos',
'image-with-missing-tag',
], env=env)
], env=env, stdout=-1)
@mock.patch('subprocess.Popen')
def test_build_images_no_conf(self, mock_popen):
process = mock.Mock()
process.returncode = 0
process.communicate.return_value = 'done', ''
mock_popen.return_value = process
builder = kb.KollaImageBuilder([])
builder.build_images([])
self.assertEqual('done', builder.build_images([]))
env = os.environ.copy()
mock_popen.assert_called_once_with([
'kolla-build',
], env=env)
], env=env, stdout=-1)
@mock.patch('subprocess.Popen')
def test_build_images_fail(self, mock_popen):
process = mock.Mock()
process.returncode = 1
process.communicate.return_value = '', 'ouch'
mock_popen.return_value = process
builder = kb.KollaImageBuilder([])
@ -128,7 +131,7 @@ class TestKollaImageBuilder(base.TestCase):
env = os.environ.copy()
mock_popen.assert_called_once_with([
'kolla-build',
], env=env)
], env=env, stdout=-1)
class TestKollaImageBuilderTemplate(base.TestCase):