def test_get_header_field_src(self): srpm = os.path.join(self.rpmdir, 'test-src-1-1.fc24.src.rpm') # without src_arch, should return the build arch (x86_64) data = koji.get_header_fields(srpm, ['arch']) self.assertEqual(data['arch'], 'x86_64') # with src_arch, should return src data = koji.get_header_fields(srpm, ['arch'], src_arch=True) self.assertEqual(data['arch'], 'src')
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') srpm2 = os.path.join(self.rpmdir, 'test-nopatch-1-1.fc24.nosrc.rpm') # should still work even with rpm constants set to None self.assertEqual([0], koji.get_header_fields(srpm1, ['nosource'])['nosource']) self.assertEqual([0], koji.get_header_fields(srpm2, ['nopatch'])['nopatch']) # should return [] with optional dep support off self.assertEqual([], koji.get_header_fields(srpm0, ['suggestname'])['suggestname'])
def test_get_header_fields(self): # incorrect self.assertRaises(IOError, koji.get_header_fields, 'nonexistent_path', []) self.assertRaises(koji.GenericError, koji.get_header_fields, self.rpm_path, 'nonexistent_header') self.assertEqual(koji.get_header_fields(self.rpm_path, []), {}) # correct self.assertEqual(['REQUIRES'], list(koji.get_header_fields(self.rpm_path, ['REQUIRES']).keys())) self.assertEqual(['PROVIDES', 'REQUIRES'], sorted(koji.get_header_fields(self.rpm_path, ['REQUIRES', 'PROVIDES']))) hdr = koji.get_rpm_header(self.rpm_path) self.assertEqual(['REQUIRES'], list(koji.get_header_fields(hdr, ['REQUIRES']).keys()))
def test_get_header_field_nosrc(self): srpm1 = os.path.join(self.rpmdir, 'test-nosrc-1-1.fc24.nosrc.rpm') srpm2 = os.path.join(self.rpmdir, 'test-nopatch-1-1.fc24.nosrc.rpm') # without src_arch, should return the build arch (x86_64) for srpm in srpm1, srpm2: data = koji.get_header_fields(srpm, ['arch']) self.assertEqual(data['arch'], 'x86_64') # with src_arch, should return nosrc for srpm in srpm1, srpm2: data = koji.get_header_fields(srpm, ['arch'], src_arch=True) self.assertEqual(data['arch'], 'nosrc')
def __get_sighdr(self, signed_rpm_path, rpm_path, rpm_info): try: header_fields = koji.get_header_fields(signed_rpm_path, ('siggpg', 'sigpgp')) except rpm.error: raise SigningError("Signing server returned corrupt RPM for %s" % rpm_path) if header_fields['siggpg'] is not None: sigkey = header_fields['siggpg'] elif header_fields['sigpgp'] is not None: sigkey = header_fields['sigpgp'] else: raise SigningError("Signing server returned unsigned RPM for %s" % rpm_path) sigkey = koji.get_sigpacket_key_id(sigkey) sigs = context.handlers.call("queryRPMSigs", rpm_id=rpm_info['id'], sigkey=sigkey) if len(sigs) > 0: raise AlreadySignedError() return koji.rip_rpm_sighdr(signed_rpm_path), sigkey
def download_rpm(build, rpm, topurl, sigkey=None, quiet=False, noprogress=False): "Wrapper around download_file, do additional checks for rpm files" pi = koji.PathInfo(topdir=topurl) if sigkey: fname = pi.signed(rpm, sigkey) filesize = None else: fname = pi.rpm(rpm) filesize = rpm['size'] url = os.path.join(pi.build(build), fname) path = os.path.basename(fname) download_file(url, path, quiet=quiet, noprogress=noprogress, filesize=filesize) # size - we have stored size only for unsigned copies if not sigkey: size = os.path.getsize(path) if size != rpm['size']: os.unlink(path) error("Downloaded rpm %s size %d does not match db size %d, deleting" % (path, size, rpm['size'])) # basic sanity try: koji.check_rpm_file(path) except koji.GenericError as ex: os.unlink(path) warn(str(ex)) error("Downloaded rpm %s is not valid rpm file, deleting" % path) # payload hash sigmd5 = koji.get_header_fields(path, ['sigmd5'])['sigmd5'] if rpm['payloadhash'] != koji.hex_string(sigmd5): os.unlink(path) error("Downloaded rpm %s doesn't match db, deleting" % path)
def test_get_header_fields_nosize(self): # not sure if this is a sane header case, but let's make sure we don't # error anyway hdr = FakeHeader(size=None) self.assertEqual({'SIZE': None}, koji.get_header_fields(hdr, ['SIZE']))
def test_get_header_fields_largefile(self): size = 4294967295 hdr = FakeHeader(longsize=size, size=None) self.assertEqual({'SIZE': size}, koji.get_header_fields(hdr, ['SIZE']))
def test_get_header_fields_largefile(self): size = 4294967295 hdr = FakeHeader(longsize=size,size=None) self.assertEqual({'SIZE': size}, koji.get_header_fields(hdr, ['SIZE']))