def test_rpm_with_epoch(self): """Ensure that an RPM with an Epoch gets handled correctly.""" update = self.db.query(Update).one() md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) # We'll fake the return of get_rpms so we can inject an epoch of 42. fake_rpms = [{ 'nvr': 'TurboGears-1.0.2.2-2.fc17', 'buildtime': 1178868422, 'arch': 'src', 'id': 62330, 'size': 761742, 'build_id': 6475, 'name': 'TurboGears', 'epoch': 42, 'version': '1.0.2.2', 'release': '2.fc17', 'buildroot_id': 1883, 'payloadhash': '6787febe92434a9be2a8f309d0e2014e' }] with mock.patch.object(md, 'get_rpms', mock.MagicMock(return_value=fake_rpms)): md.add_update(update) md.shelf.close() col = md.uinfo.updates[0].collections[0] assert len(col.packages) == 1 pkg = col.packages[0] assert pkg.epoch == '42'
def _test_extended_metadata(self, has_alias): update = self.db.query(Update).one() # Pretend it's pushed to testing update.status = UpdateStatus.testing update.request = None if not has_alias: update.alias = None update.date_pushed = datetime.utcnow() DevBuildsys.__tagged__[update.title] = ['f17-updates-testing'] # Generate the XML md = UpdateInfoMetadata(update.release, update.request, self.db, self.tempcompdir) # Insert the updateinfo.xml into the repository md.insert_updateinfo(self.tempcompdir) updateinfo = self._verify_updateinfo(self.repodata) # Read an verify the updateinfo.xml.gz uinfo = createrepo_c.UpdateInfo(updateinfo) notice = self.get_notice(uinfo, 'mutt-1.5.14-1.fc13') self.assertIsNone(notice) self.assertEquals(len(uinfo.updates), 1) notice = uinfo.updates[0] self.assertIsNotNone(notice) self.assertEquals(notice.title, update.title) self.assertEquals(notice.release, update.release.long_name) self.assertEquals(notice.status, update.status.value) if update.date_modified: self.assertEquals(notice.updated_date, update.date_modified) self.assertEquals(notice.fromstr, config.get('bodhi_email')) self.assertEquals(notice.rights, config.get('updateinfo_rights')) self.assertEquals(notice.description, update.notes) self.assertEquals(notice.id, update.alias) bug = notice.references[0] self.assertEquals(bug.href, update.bugs[0].url) self.assertEquals(bug.id, '12345') self.assertEquals(bug.type, 'bugzilla') cve = notice.references[1] self.assertEquals(cve.type, 'cve') self.assertEquals(cve.href, update.cves[0].url) self.assertEquals(cve.id, update.cves[0].cve_id) col = notice.collections[0] self.assertEquals(col.name, update.release.long_name) self.assertEquals(col.shortname, update.release.name) pkg = col.packages[0] self.assertEquals(pkg.epoch, '0') self.assertEquals(pkg.name, 'TurboGears') self.assertEquals(pkg.src, ( 'https://download.fedoraproject.org/pub/fedora/linux/updates/testing/17/SRPMS/T/' 'TurboGears-1.0.2.2-2.fc17.src.rpm')) self.assertEquals(pkg.version, '1.0.2.2') self.assertFalse(pkg.reboot_suggested) self.assertEquals(pkg.arch, 'src') self.assertEquals(pkg.filename, 'TurboGears-1.0.2.2-2.fc17.src.rpm')
def test_rpm_with_arch(self): """Ensure that an RPM with a non 386 arch gets handled correctly.""" update = self.db.query(Update).one() md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) # Set the arch to aarch64 fake_rpms = [{ 'nvr': 'TurboGears-1.0.2.2-2.fc17', 'buildtime': 1178868422, 'arch': 'aarch64', 'id': 62330, 'size': 761742, 'build_id': 6475, 'name': 'TurboGears', 'epoch': None, 'version': '1.0.2.2', 'release': '2.fc17', 'buildroot_id': 1883, 'payloadhash': '6787febe92434a9be2a8f309d0e2014e' }] with mock.patch.object(md, 'get_rpms', mock.MagicMock(return_value=fake_rpms)): md.add_update(update) md.shelf.close() col = md.uinfo.updates[0].collections[0] assert len(col.packages) == 1 pkg = col.packages[0] assert pkg.src == \ ('https://download.fedoraproject.org/pub/fedora/linux/updates/17/aarch64/T/' 'TurboGears-1.0.2.2-2.fc17.aarch64.rpm')
def test_build_not_in_builds(self): """ Test correct behavior when a build in update.builds isn't found in self.builds() and koji.getBuild() is called instead. """ update = self.db.query(Update).one() now = datetime(year=2018, month=2, day=8, hour=12, minute=41, second=4) update.date_pushed = now update.date_modified = now md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) md.add_update(update) md.shelf.close() assert len(md.uinfo.updates) == 1 assert md.uinfo.updates[0].title == update.title assert md.uinfo.updates[0].release == update.release.long_name assert md.uinfo.updates[0].status == update.status.value assert md.uinfo.updates[0].updated_date == update.date_modified assert md.uinfo.updates[0].fromstr == config.get('bodhi_email') assert md.uinfo.updates[0].rights == config.get('updateinfo_rights') assert md.uinfo.updates[0].description == update.notes assert md.uinfo.updates[0].id == update.alias assert md.uinfo.updates[0].severity == 'Moderate' assert len(md.uinfo.updates[0].references) == 1 bug = md.uinfo.updates[0].references[0] assert bug.href == update.bugs[0].url assert bug.id == '12345' assert bug.type == 'bugzilla' assert len(md.uinfo.updates[0].collections) == 1 col = md.uinfo.updates[0].collections[0] assert col.name == update.release.long_name assert col.shortname == update.release.name assert len(col.packages) == 2 pkg = col.packages[0] assert pkg.epoch == '0' # It's a little goofy, but the DevBuildsys is going to return TurboGears rpms when its # listBuildRPMs() method is called, so let's just roll with it. assert pkg.name == 'TurboGears' assert pkg.src == \ ('https://download.fedoraproject.org/pub/fedora/linux/updates/17/SRPMS/T/' 'TurboGears-1.0.2.2-2.fc17.src.rpm') assert pkg.version == '1.0.2.2' assert not pkg.reboot_suggested assert pkg.arch == 'src' assert pkg.filename == 'TurboGears-1.0.2.2-2.fc17.src.rpm' pkg = col.packages[1] assert pkg.epoch == '0' assert pkg.name == 'TurboGears' assert pkg.src == \ ('https://download.fedoraproject.org/pub/fedora/linux/updates/17/i386/T/' 'TurboGears-1.0.2.2-2.fc17.noarch.rpm') assert pkg.version == '1.0.2.2' assert not pkg.reboot_suggested assert pkg.arch == 'noarch' assert pkg.filename == 'TurboGears-1.0.2.2-2.fc17.noarch.rpm'
def _test_extended_metadata(self): update = self.db.query(Update).one() # Pretend it's pushed to testing update.status = UpdateStatus.testing update.request = None update.date_pushed = datetime.utcnow() DevBuildsys.__tagged__[update.title] = ['f17-updates-testing'] # Generate the XML md = UpdateInfoMetadata(update.release, update.request, self.db, self.tempcompdir) # Insert the updateinfo.xml into the repository md.insert_updateinfo(self.tempcompdir) updateinfos = self._verify_updateinfos(self.repodata) for updateinfo in updateinfos: # Read an verify the updateinfo.xml.gz uinfo = createrepo_c.UpdateInfo(updateinfo) notice = self.get_notice(uinfo, 'mutt-1.5.14-1.fc13') assert notice is None assert len(uinfo.updates) == 1 notice = uinfo.updates[0] assert notice is not None assert notice.title == update.title assert notice.release == update.release.long_name assert notice.status == update.status.value if update.date_modified: assert notice.updated_date == update.date_modified assert notice.fromstr == config.get('bodhi_email') assert notice.rights == config.get('updateinfo_rights') assert notice.description == update.notes assert notice.id == update.alias assert notice.severity == 'Moderate' bug = notice.references[0] assert bug.href == update.bugs[0].url assert bug.id == '12345' assert bug.type == 'bugzilla' col = notice.collections[0] assert col.name == update.release.long_name assert col.shortname == update.release.name pkg = col.packages[0] assert pkg.epoch == '0' assert pkg.name == 'TurboGears' assert pkg.src == \ ('https://download.fedoraproject.org/pub/fedora/linux/updates/testing/17/SRPMS/T/' 'TurboGears-1.0.2.2-2.fc17.src.rpm') assert pkg.version == '1.0.2.2' assert not pkg.reboot_suggested assert not pkg.relogin_suggested assert pkg.arch == 'src' assert pkg.filename == 'TurboGears-1.0.2.2-2.fc17.src.rpm'
def test_date_pushed_none(self): """The metadata should use utcnow() if an update's date_pushed is None.""" update = self.db.query(Update).one() update.date_pushed = None md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) md.add_update(update) md.shelf.close() self.assertEqual(len(md.uinfo.updates), 1) self.assertTrue(abs((datetime.utcnow() - md.uinfo.updates[0].issued_date).seconds) < 2)
def test_date_pushed_none(self): """The metadata should use date_submitted if an update's date_pushed is None.""" update = self.db.query(Update).one() update.date_pushed = None md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) md.add_update(update) md.shelf.close() assert len(md.uinfo.updates) == 1 assert md.uinfo.updates[0].issued_date == update.date_submitted
def test___init___uses_xz_for_fedore(self): """Assert that the __init__() method sets the comp_type attribute to cr.XZ for Fedora.""" fedora = Release.query.one() md = UpdateInfoMetadata(fedora, UpdateRequest.stable, self.db, self.tempdir) self.assertEqual(md.comp_type, createrepo_c.XZ)
def test___init___uses_bz2_for_epel(self): """Assert that the __init__() method sets the comp_type attribute to cr.BZ2 for EPEL.""" epel_7 = Release(id_prefix="FEDORA-EPEL", stable_tag='epel7') md = UpdateInfoMetadata(epel_7, UpdateRequest.stable, self.db, self.tempdir) self.assertEqual(md.comp_type, createrepo_c.BZ2)
def test_date_pushed_none(self): """The metadata should use utcnow() if an update's date_pushed is None.""" test_start_time = datetime.utcnow() # The UpdateRecord's updated_date attribute strips microseconds, so let's force them to 0 # so our assertions at the end of this test will pass. test_start_time = test_start_time - timedelta(microseconds=test_start_time.microsecond) update = self.db.query(Update).one() update.date_pushed = None md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) md.add_update(update) md.shelf.close() assert len(md.uinfo.updates) == 1 assert test_start_time <= md.uinfo.updates[0].issued_date <= datetime.utcnow()
def test_build_unassociated(self, warning): """A warning should be logged if the Bodhi Build object is not associated with an Update.""" update = self.db.query(Update).one() update.date_pushed = None u = create_update(self.db, [u'TurboGears-1.0.2.2-4.fc17']) u.builds[0].update = None self.db.flush() # _fetch_updates() is called as part of UpdateInfoMetadata.__init__() so we'll just # instantiate one. md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) warning.assert_called_once_with( 'TurboGears-1.0.2.2-4.fc17 does not have a corresponding update') # Since the Build didn't have an Update, no Update should have been added to md.updates. self.assertEqual(md.updates, set([]))
def test_build_not_in_builds(self): """ Test correct behavior when a build in update.builds isn't found in self.builds() and koji.getBuild() is called instead. """ update = self.db.query(Update).one() now = datetime(year=2018, month=2, day=8, hour=12, minute=41, second=4) update.date_pushed = now update.date_modified = now md = UpdateInfoMetadata(update.release, update.request, self.db, self.temprepo, close_shelf=False) md.add_update(update) md.shelf.close() self.assertEqual(len(md.uinfo.updates), 1) self.assertEquals(md.uinfo.updates[0].title, update.title) self.assertEquals(md.uinfo.updates[0].release, update.release.long_name) self.assertEquals(md.uinfo.updates[0].status, update.status.value) self.assertEquals(md.uinfo.updates[0].updated_date, update.date_modified) self.assertEquals(md.uinfo.updates[0].fromstr, config.get('bodhi_email')) self.assertEquals(md.uinfo.updates[0].rights, config.get('updateinfo_rights')) self.assertEquals(md.uinfo.updates[0].description, update.notes) self.assertEquals(md.uinfo.updates[0].id, update.alias) self.assertEquals(md.uinfo.updates[0].severity, 'Moderate') self.assertEqual(len(md.uinfo.updates[0].references), 2) bug = md.uinfo.updates[0].references[0] self.assertEquals(bug.href, update.bugs[0].url) self.assertEquals(bug.id, '12345') self.assertEquals(bug.type, 'bugzilla') cve = md.uinfo.updates[0].references[1] self.assertEquals(cve.type, 'cve') self.assertEquals(cve.href, update.cves[0].url) self.assertEquals(cve.id, update.cves[0].cve_id) self.assertEqual(len(md.uinfo.updates[0].collections), 1) col = md.uinfo.updates[0].collections[0] self.assertEquals(col.name, update.release.long_name) self.assertEquals(col.shortname, update.release.name) self.assertEqual(len(col.packages), 2) pkg = col.packages[0] self.assertEquals(pkg.epoch, '0') # It's a little goofy, but the DevBuildsys is going to return TurboGears rpms when its # listBuildRPMs() method is called, so let's just roll with it. self.assertEquals(pkg.name, 'TurboGears') self.assertEquals(pkg.src, ( 'https://download.fedoraproject.org/pub/fedora/linux/updates/17/SRPMS/T/' 'TurboGears-1.0.2.2-2.fc17.src.rpm')) self.assertEquals(pkg.version, '1.0.2.2') self.assertFalse(pkg.reboot_suggested) self.assertEquals(pkg.arch, 'src') self.assertEquals(pkg.filename, 'TurboGears-1.0.2.2-2.fc17.src.rpm') pkg = col.packages[1] self.assertEquals(pkg.epoch, '0') self.assertEquals(pkg.name, 'TurboGears') self.assertEquals(pkg.src, ( 'https://download.fedoraproject.org/pub/fedora/linux/updates/17/i386/T/' 'TurboGears-1.0.2.2-2.fc17.noarch.rpm')) self.assertEquals(pkg.version, '1.0.2.2') self.assertFalse(pkg.reboot_suggested) self.assertEquals(pkg.arch, 'noarch') self.assertEquals(pkg.filename, 'TurboGears-1.0.2.2-2.fc17.noarch.rpm')
def generate_updateinfo(self): self.log.info('Generating updateinfo for %s' % self.release.name) uinfo = UpdateInfoMetadata(self.release, self.request, self.db, self.mash_dir) self.log.info('Updateinfo generation for %s complete' % self.release.name) return uinfo