From 1881bf740d1587154c3b7861db9e262e2ef2500b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 1 Sep 2016 09:06:47 +0200 Subject: [PATCH] createiso: Report nice error when tag does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of failing with generic `AttributeError`, we can easily report the actual problem. Signed-off-by: Lubomír Sedlář --- pungi/phases/createiso.py | 2 ++ tests/test_createiso_phase.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 13e02e7e..eae5e5f9 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -219,6 +219,8 @@ class CreateIsoThread(WorkerThread): koji_wrapper = KojiWrapper(compose.conf["koji_profile"]) koji_proxy = koji_wrapper.koji_proxy 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(" ") build_arch = arch diff --git a/tests/test_createiso_phase.py b/tests/test_createiso_phase.py index ebe1f5af..a45a0983 100755 --- a/tests/test_createiso_phase.py +++ b/tests/test_createiso_phase.py @@ -402,6 +402,38 @@ class CreateisoThreadTest(helpers.PungiTestCase): self.assertEqual(image.type, 'dvd') 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.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size')