extra-files: Nice error message on missing RPM

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-11-10 09:38:50 +01:00
parent 4427769f6a
commit 88dbf8f849
2 changed files with 21 additions and 4 deletions

View File

@ -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

View File

@ -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()