Include phase name in log for some phases

Phases createiso, liveimages, image_build, ostree_installer and osbs are
done in parallel, logs from these phases are mixed and and it's not
obvious which log message belongs to which phase. This change adds phase
name in log message for these phases.

The new mixin 'PhaseLoggerMixin' is added to extend a Pungi phase with a
logging logger which copy handlers from compose's logger but with
formatter changed.

Fixes: #58
Signed-off-by: Qixiang Wan <qwan@redhat.com>
This commit is contained in:
Qixiang Wan 2016-11-18 14:33:03 -06:00
parent 9e52c68c82
commit 80fa723b1d
20 changed files with 134 additions and 91 deletions

View file

@ -60,6 +60,11 @@ class DummyCompose(object):
type='variant', is_empty=False),
}
self.all_variants = self.variants.copy()
# for PhaseLoggerMixin
self._logger = mock.Mock()
self._logger.handlers = [mock.Mock()]
self.log_info = mock.Mock()
self.log_error = mock.Mock()
self.log_debug = mock.Mock()

View file

@ -563,7 +563,7 @@ class BuildinstallThreadTestCase(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, 'x86_64', None, cmd), 0)
compose.log_info.assert_has_calls([
compose._logger.info.assert_has_calls([
mock.call('[FAIL] Buildinstall (variant None, arch x86_64) failed, but going on anyway.'),
mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall.x86_64.log for more details.'
% self.topdir)
@ -599,7 +599,7 @@ class BuildinstallThreadTestCase(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, 'x86_64', compose.variants['Server'], cmd), 0)
compose.log_info.assert_has_calls([
compose._logger.info.assert_has_calls([
mock.call('[FAIL] Buildinstall (variant Server, arch x86_64) failed, but going on anyway.'),
mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall-Server.x86_64.log for more details.' % self.topdir)
])

View file

@ -49,12 +49,13 @@ class CreateisoPhaseTest(helpers.PungiTestCase):
pool = ThreadPool.return_value
phase = createiso.CreateisoPhase(compose)
phase.logger = mock.Mock()
phase.run()
self.assertEqual(len(pool.add.call_args_list), 0)
self.assertEqual(pool.queue_put.call_args_list, [])
self.assertItemsEqual(
compose.log_warning.call_args_list,
phase.logger.warn.call_args_list,
[mock.call('No RPMs found for Everything.x86_64, skipping ISO'),
mock.call('No RPMs found for Everything.amd64, skipping ISO'),
mock.call('No RPMs found for Everything.src, skipping ISO'),
@ -93,7 +94,7 @@ class CreateisoPhaseTest(helpers.PungiTestCase):
[mock.call(compose, 'x86_64', compose.variants['Server'],
disc_count=1, disc_num=1, split_iso_data=disc_data)])
self.assertEqual(split_iso.call_args_list,
[mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False)])
[mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False, logger=phase.logger)])
self.assertEqual(len(pool.add.call_args_list), 1)
self.maxDiff = None
self.assertItemsEqual(
@ -160,8 +161,8 @@ class CreateisoPhaseTest(helpers.PungiTestCase):
disc_count=1, disc_num=1, split_iso_data=disc_data)])
self.assertItemsEqual(
split_iso.call_args_list,
[mock.call(compose, 'x86_64', compose.variants['Server'], no_split=True),
mock.call(compose, 'src', compose.variants['Server'], no_split=False)])
[mock.call(compose, 'x86_64', compose.variants['Server'], no_split=True, logger=phase.logger),
mock.call(compose, 'src', compose.variants['Server'], no_split=False, logger=phase.logger)])
self.assertEqual(len(pool.add.call_args_list), 2)
self.maxDiff = None
self.assertItemsEqual(
@ -463,11 +464,12 @@ class CreateisoThreadTest(helpers.PungiTestCase):
run_runroot = KojiWrapper.return_value.run_runroot_cmd
run_runroot.side_effect = helpers.boom
t = createiso.CreateIsoThread(mock.Mock())
pool = mock.Mock()
t = createiso.CreateIsoThread(pool)
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'),
mock.call('BOOM')
])
@ -505,11 +507,12 @@ class CreateisoThreadTest(helpers.PungiTestCase):
'task_id': '1234',
}
t = createiso.CreateIsoThread(mock.Mock())
pool = mock.Mock()
t = createiso.CreateIsoThread(pool)
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'),
mock.call('Runroot task failed: 1234. See %s for more details.'
% (self.topdir + '/logs/x86_64/createiso-image-name.x86_64.log'))
@ -585,11 +588,12 @@ class CreateisoThreadTest(helpers.PungiTestCase):
}
run.side_effect = helpers.boom
t = createiso.CreateIsoThread(mock.Mock())
pool = mock.Mock()
t = createiso.CreateIsoThread(pool)
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'),
mock.call('BOOM')
])
@ -718,7 +722,7 @@ class SplitIsoTest(helpers.PungiTestCase):
os.path.join(base_path, 'Packages/b/bash.rpm')],
'size': 5400166400}])
self.assertEqual(
compose.log_warning.call_args_list,
compose._logger.warn.call_args_list,
[mock.call('ISO for Server.x86_64 does not fit on single media! '
'It is 710652160 bytes too big. (Total size: 5400166400 B)')]
)

View file

@ -747,7 +747,7 @@ class TestCreateImageBuildThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, cmd), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'),
mock.call('ImageBuild task failed: 1234. See %s for more details.'
% (os.path.join(self.topdir,
@ -792,7 +792,7 @@ class TestCreateImageBuildThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, cmd), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'),
mock.call('BOOM'),
])

View file

@ -727,7 +727,7 @@ class TestCreateLiveImageThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'),
mock.call('LiveImage task failed: 123. See %s/logs/amd64/liveimage-None-None-xyz.amd64.log for more details.'
% self.topdir)
@ -766,7 +766,7 @@ class TestCreateLiveImageThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'),
mock.call('BOOM')
])

View file

@ -516,7 +516,7 @@ class TestLiveMediaThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, compose.variants['Server'], config), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'),
mock.call('Live media task failed: 1234. See %s for more details.'
% (os.path.join(self.topdir, 'logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log')))
@ -559,7 +559,7 @@ class TestLiveMediaThread(PungiTestCase):
with mock.patch('time.sleep'):
t.process((compose, compose.variants['Server'], config), 1)
compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'),
mock.call('BOOM')
])

View file

@ -65,14 +65,14 @@ class MediaSplitterTestCase(unittest.TestCase):
def assertFreeSpace(self, free, total):
self.assertEqual(
self.compose.mock_calls,
[mock.call.log_debug('MediaSplitter: free space on single media would be %s. '
'Total size of single medium: %s.' % (free, total))])
self.compose._logger.debug.mock_calls,
[mock.call('MediaSplitter: free space on single media would be %s. '
'Total size of single medium: %s.' % (free, total))])
def assertUnlimited(self, total):
self.assertEqual(
self.compose.mock_calls,
[mock.call.log_debug('MediaSplitter: Total size of single medium: %s.' % total)])
self.compose._logger.debug.mock_calls,
[mock.call('MediaSplitter: Total size of single medium: %s.' % total)])
def test_sum_size(self):
ms = media_split.MediaSplitter(bl(100))

View file

@ -340,7 +340,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
t = ostree.OstreeInstallerThread(pool)
t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)
self.compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'),
mock.call('BOOM')
])
@ -370,7 +370,7 @@ class OstreeThreadTest(helpers.PungiTestCase):
t = ostree.OstreeInstallerThread(pool)
t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1)
self.compose.log_info.assert_has_calls([
pool._logger.info.assert_has_calls([
mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'),
mock.call('Runroot task failed: 1234. See %s/logs/x86_64/ostree_installer/runroot.log for more details.'
% self.topdir)

View file

@ -147,7 +147,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1)
self.compose.log_info.assert_has_calls([
self.compose._logger.info.assert_has_calls([
mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'),
mock.call('Runroot task failed: 1234. See %s for more details.'
% (self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log'))
@ -166,7 +166,7 @@ class OSTreeThreadTest(helpers.PungiTestCase):
t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1)
self.compose.log_info.assert_has_calls([
self.compose._logger.info.assert_has_calls([
mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'),
mock.call('BOOM')
])