From 88dbf8f849c4c525bed0f244871c6a26df2bccde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 10 Nov 2016 09:38:50 +0100 Subject: [PATCH] extra-files: Nice error message on missing RPM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a file is exported from an RPM in the compose, and there is no matching RPM in the package set, we want a nice error message. Fixes: #460 Signed-off-by: Lubomír Sedlář --- pungi/phases/extra_files.py | 9 +++++---- tests/test_extra_files_phase.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pungi/phases/extra_files.py b/pungi/phases/extra_files.py index 0aeb33ca..70284d97 100644 --- a/pungi/phases/extra_files.py +++ b/pungi/phases/extra_files.py @@ -66,13 +66,14 @@ def copy_extra_files(compose, cfg, arch, variant, package_sets, checksum_type='s # package(s) in package set if scm_dict["scm"] == "rpm" and not _is_external(scm_dict["repo"]): rpms = [] + pattern = scm_dict["repo"] % var_dict + pkg_name, pkg_arch = split_name_arch(pattern) for pkgset_file in package_sets[arch]: pkg_obj = package_sets[arch][pkgset_file] - if not pkg_is_rpm(pkg_obj): - continue - pkg_name, pkg_arch = split_name_arch(scm_dict["repo"] % var_dict) - if _pkg_matches(pkg_obj, pkg_name, pkg_arch): + if pkg_is_rpm(pkg_obj) and _pkg_matches(pkg_obj, pkg_name, pkg_arch): rpms.append(pkg_obj.file_path) + if not rpms: + raise RuntimeError('No package matching %s in the package set.' % pattern) scm_dict["repo"] = rpms getter = get_file_from_scm if 'file' in scm_dict else get_dir_from_scm diff --git a/tests/test_extra_files_phase.py b/tests/test_extra_files_phase.py index 94e443c8..54daedb3 100644 --- a/tests/test_extra_files_phase.py +++ b/tests/test_extra_files_phase.py @@ -148,6 +148,22 @@ class TestCopyFiles(helpers.PungiTestCase): helpers.touch(os.path.join(dest, scm_dict['file'])) return [scm_dict['file']] + @mock.patch('pungi.phases.extra_files.get_file_from_scm') + @mock.patch('pungi.phases.extra_files.get_dir_from_scm') + def test_copy_from_non_existing_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm): + compose = helpers.DummyCompose(self.topdir, {}) + cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': 'bad-%(variant_uid_lower)s*'} + package_sets = {'x86_64': {}} + + with self.assertRaises(RuntimeError) as ctx: + extra_files.copy_extra_files( + compose, [cfg], 'x86_64', compose.variants['Server'], package_sets) + + self.assertRegexpMatches(str(ctx.exception), 'No.*package.*matching bad-server\*.*') + + self.assertEqual(len(get_file_from_scm.call_args_list), 0) + self.assertEqual(get_dir_from_scm.call_args_list, []) + if __name__ == "__main__": unittest.main()