createiso: Report nice error when tag does not exist

Instead of failing with generic `AttributeError`, we can easily report
the actual problem.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-09-01 09:06:47 +02:00
parent a31be0a3c4
commit 1881bf740d
2 changed files with 34 additions and 0 deletions

View File

@ -219,6 +219,8 @@ class CreateIsoThread(WorkerThread):
koji_wrapper = KojiWrapper(compose.conf["koji_profile"]) koji_wrapper = KojiWrapper(compose.conf["koji_profile"])
koji_proxy = koji_wrapper.koji_proxy koji_proxy = koji_wrapper.koji_proxy
tag_info = koji_proxy.getTag(runroot_tag) tag_info = koji_proxy.getTag(runroot_tag)
if not tag_info:
raise RuntimeError('Tag "%s" does not exist.' % runroot_tag)
tag_arches = tag_info["arches"].split(" ") tag_arches = tag_info["arches"].split(" ")
build_arch = arch build_arch = arch

View File

@ -402,6 +402,38 @@ class CreateisoThreadTest(helpers.PungiTestCase):
self.assertEqual(image.type, 'dvd') self.assertEqual(image.type, 'dvd')
self.assertEqual(image.subvariant, 'Server') self.assertEqual(image.subvariant, 'Server')
@mock.patch('pungi.phases.createiso.IsoWrapper')
@mock.patch('pungi.phases.createiso.get_mtime')
@mock.patch('pungi.phases.createiso.get_file_size')
@mock.patch('pungi.phases.createiso.KojiWrapper')
def test_process_in_runroot_non_existing_tag(self, KojiWrapper, get_file_size,
get_mtime, IsoWrapper):
compose = helpers.DummyCompose(self.topdir, {
'release_short': 'test',
'release_version': '1.0',
'release_is_layered': False,
'runroot': True,
'runroot_tag': 'f25-build',
'koji_profile': 'koji',
})
cmd = {
'iso_path': '%s/compose/Server/x86_64/iso/image-name' % self.topdir,
'bootable': False,
'cmd': mock.Mock(),
'label': '',
'disc_num': 1,
'disc_count': 1,
}
getTag = KojiWrapper.return_value.koji_proxy.getTag
getTag.return_value = None
t = createiso.CreateIsoThread(mock.Mock())
with self.assertRaises(RuntimeError) as ctx:
with mock.patch('time.sleep'):
t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1)
self.assertEqual('Tag "f25-build" does not exist.', str(ctx.exception))
@mock.patch('pungi.phases.createiso.IsoWrapper') @mock.patch('pungi.phases.createiso.IsoWrapper')
@mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_mtime')
@mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.get_file_size')