From bfd5a39ce602edb2350141fa193d834584b63328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 25 Oct 2016 15:43:19 +0200 Subject: [PATCH] checks: Check for createrepo_c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The createrepo package is needed always, but depending on configuration we should also look for createrepo_c. Signed-off-by: Lubomír Sedlář --- pungi/checks.py | 15 +++++++++++++-- tests/test_checks.py | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/pungi/checks.py b/pungi/checks.py index e385cf2f..2c112b64 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -76,6 +76,10 @@ def is_genisoimage_needed(conf): return False return True + +def is_createrepo_c_needed(conf): + return conf.get('createrepo_c', True) + # The first element in the tuple is package name expected to have the # executable (2nd element of the tuple). The last element is an optional # function that should determine if the tool is required based on @@ -87,8 +91,15 @@ tools = [ ("genisoimage", "/usr/bin/genisoimage", is_genisoimage_needed), ("gettext", "/usr/bin/msgfmt", None), ("syslinux", "/usr/bin/isohybrid", is_isohybrid_needed), - ("createrepo", "/usr/bin/createrepo", None), - ("createrepo", "/usr/bin/mergerepo", None), + # modifyrepo can always be called + ("createrepo", "/usr/bin/modifyrepo", None), + # createrepo and mergerepo are not needed by default, only when + # createrepo_c is not configured + ("createrepo", "/usr/bin/createrepo", lambda conf: not is_createrepo_c_needed(conf)), + ("createrepo", "/usr/bin/mergerepo", lambda conf: not is_createrepo_c_needed(conf)), + ("createrepo_c", "/usr/bin/createrepo_c", is_createrepo_c_needed), + ("createrepo_c", "/usr/bin/mergerepo_c", is_createrepo_c_needed), + ("yum-utils", "/usr/bin/repoquery", None), ("git", "/usr/bin/git", None), ("cvs", "/usr/bin/cvs", None), diff --git a/tests/test_checks.py b/tests/test_checks.py index d4d8a4fa..ea64577b 100755 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -147,11 +147,46 @@ class CheckDependenciesTestCase(unittest.TestCase): with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out: with mock.patch('os.path.exists') as exists: exists.side_effect = self.dont_find(['/usr/bin/genisoimage']) - result = checks.check(conf) + with mock.patch('__builtin__.__import__'): + result = checks.check(conf) self.assertIn('genisoimage', out.getvalue()) self.assertFalse(result) + def test_requires_modifyrepo(self): + with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out: + with mock.patch('os.path.exists') as exists: + exists.side_effect = self.dont_find(['/usr/bin/modifyrepo']) + with mock.patch('__builtin__.__import__'): + result = checks.check({}) + + self.assertIn('createrepo', out.getvalue()) + self.assertFalse(result) + + def test_requires_createrepo_c(self): + with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out: + with mock.patch('os.path.exists') as exists: + exists.side_effect = self.dont_find(['/usr/bin/createrepo_c']) + with mock.patch('__builtin__.__import__'): + result = checks.check({}) + + self.assertIn('createrepo_c', out.getvalue()) + self.assertFalse(result) + + def test_doesnt_require_createrepo_c_if_configured(self): + conf = { + 'createrepo_c': False, + } + + with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out: + with mock.patch('os.path.exists') as exists: + exists.side_effect = self.dont_find(['/usr/bin/createrepo_c']) + with mock.patch('__builtin__.__import__'): + result = checks.check(conf) + + self.assertNotIn('createrepo_c', out.getvalue()) + self.assertTrue(result) + class TestUmask(unittest.TestCase): def setUp(self):