From 7304e21d12bdebd4dbabd2d471eee9e54cb3deca Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 06 2018 13:21:37 +0000 Subject: [PATCH 1/2] check rpm headers support directly --- diff --git a/koji/__init__.py b/koji/__init__.py index 9d44488..215f026 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -110,13 +110,17 @@ RPM_FILEDIGESTALGO_IDS = { 11: 'SHA224' } -# rpm 4.12 introduces optional deps -try: - RPM_SUPPORTS_OPTIONAL_DEPS = int(rpm.__version_info__[0]) > 4 or \ - (int(rpm.__version_info__[0]) == 4 and int(rpm.__version_info__[1]) >= 12) -except AttributeError: - # older versions don't even have __version_info__ - RPM_SUPPORTS_OPTIONAL_DEPS = False +# rpm 4.12 introduces optional deps, but they can also be backported in some +# rpm installations. So, we need to check their real support, not only rpm +# version. +SUPPORTED_OPT_DEP_HDRS = {} +for h in ( + 'SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS', + 'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS', + 'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS', + 'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS'): + SUPPORTED_OPT_DEP_HDRS[h] = hasattr(rpm, 'RPMTAG_%s' % h) + class Enum(dict): """A simple class to track our enumerated constants @@ -892,12 +896,8 @@ def get_rpm_header(f, ts=None): def get_header_field(hdr, name, src_arch=False): """Extract named field from an rpm header""" name = name.upper() - opt_dep_hdrs = ( - 'SUGGESTNAME', 'SUGGESTVERSION', 'SUGGESTFLAGS', - 'ENHANCENAME', 'ENHANCEVERSION', 'ENHANCEFLAGS', - 'SUPPLEMENTNAME', 'SUPPLEMENTVERSION', 'SUPPLEMENTFLAGS', - 'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS') - if not RPM_SUPPORTS_OPTIONAL_DEPS and name in opt_dep_hdrs: + # if field is not supported by host's rpm (>4.12), return empty list + if not SUPPORTED_OPT_DEP_HDRS.get(name, True): return [] if (src_arch and name == "ARCH" diff --git a/tests/test_hub/test_getRPMDeps.py b/tests/test_hub/test_getRPMDeps.py index f4931a4..49fa1ab 100644 --- a/tests/test_hub/test_getRPMDeps.py +++ b/tests/test_hub/test_getRPMDeps.py @@ -17,7 +17,7 @@ class TestGetRPMDeps(unittest.TestCase): getRPMDeps = kojihub.RootExports().getRPMDeps res = getRPMDeps('') # limit test for rpm < 4.12 - if koji.RPM_SUPPORTS_OPTIONAL_DEPS: + if any(koji.SUPPORTED_OPT_DEP_HDRS.values()): self.assertEqual(len(res), 22) types = set([x['type'] for x in res]) self.assertEqual(set([koji.DEP_REQUIRE, diff --git a/tests/test_lib/test_parsers.py b/tests/test_lib/test_parsers.py index fc3b164..44d0560 100644 --- a/tests/test_lib/test_parsers.py +++ b/tests/test_lib/test_parsers.py @@ -197,7 +197,7 @@ class HeaderTestCase(unittest.TestCase): @mock.patch('rpm.RPMTAG_NOSOURCE', new=None) @mock.patch('rpm.RPMTAG_NOPATCH', new=None) - @mock.patch('koji.RPM_SUPPORTS_OPTIONAL_DEPS', new=False) + @mock.patch('koji.SUPPORTED_OPT_DEP_HDRS', new={}) def test_get_header_field_workarounds(self): srpm0 = os.path.join(self.rpmdir, 'test-src-1-1.fc24.src.rpm') srpm1 = os.path.join(self.rpmdir, 'test-nosrc-1-1.fc24.nosrc.rpm') From 23c55ea2fc90b2627d8273b763c7d6212ee6549a Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 06 2018 15:27:12 +0000 Subject: [PATCH 2/2] fix test --- diff --git a/tests/test_lib/test_parsers.py b/tests/test_lib/test_parsers.py index 44d0560..e49217a 100644 --- a/tests/test_lib/test_parsers.py +++ b/tests/test_lib/test_parsers.py @@ -197,7 +197,7 @@ class HeaderTestCase(unittest.TestCase): @mock.patch('rpm.RPMTAG_NOSOURCE', new=None) @mock.patch('rpm.RPMTAG_NOPATCH', new=None) - @mock.patch('koji.SUPPORTED_OPT_DEP_HDRS', new={}) + @mock.patch('koji.SUPPORTED_OPT_DEP_HDRS', new={'SUGGESTNAME': False}) def test_get_header_field_workarounds(self): srpm0 = os.path.join(self.rpmdir, 'test-src-1-1.fc24.src.rpm') srpm1 = os.path.join(self.rpmdir, 'test-nosrc-1-1.fc24.nosrc.rpm')