#965 check rpm headers support directly
Merged 5 years ago by mikem. Opened 5 years ago by tkopecek.
tkopecek/koji issue931  into  master

file modified
+13 -13
@@ -110,13 +110,17 @@ 

      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_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"

@@ -17,7 +17,7 @@ 

          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,

@@ -197,7 +197,7 @@ 

  

      @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={'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')

no initial comment

1 new commit added

  • fix test
5 years ago

Commit ef998c6 fixes this pull-request

Pull-Request has been merged by mikem

5 years ago