Skip to content

Commit

Permalink
Insert utcnow for issued_date if not yet pushed
Browse files Browse the repository at this point in the history
This works around a silly bug in Satellite/Spacewalk where it really wants
an issued date and will crash if not there.

Signed-off-by: Patrick Uiterwijk <[email protected]>
Signed-off-by: Randy Barlow <[email protected]>
  • Loading branch information
puiterwijk authored and bowlofeggs committed Feb 16, 2018
1 parent ec512fb commit 8e1aded
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
11 changes: 10 additions & 1 deletion bodhi/server/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2007-2017 Red Hat, Inc. and others.
# Copyright 2007-2018 Red Hat, Inc. and others.
#
# This file is part of Bodhi.
#
Expand All @@ -17,6 +17,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Create metadata files when mashing repositories."""
from datetime import datetime
import logging
import os
import shelve
Expand Down Expand Up @@ -194,8 +195,16 @@ def add_update(self, update):

if update.date_pushed:
rec.issued_date = update.date_pushed
else:
# Sometimes we only set the date_pushed after it's pushed out, however,
# it seems that Satellite does not like update entries without issued_date.
# Since we know that we are pushing it now, and the next push will get the data
# correctly, let's just insert utcnow().
rec.issued_date = datetime.utcnow()
if update.date_modified:
rec.updated_date = update.date_modified
else:
rec.updated_date = datetime.utcnow()

col = cr.UpdateCollection()
col.name = to_bytes(update.release.long_name)
Expand Down
31 changes: 30 additions & 1 deletion bodhi/tests/server/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2007-2017 Red Hat, Inc. and others.
# Copyright 2007-2018 Red Hat, Inc. and others.
#
# This file is part of Bodhi.
#
Expand Down Expand Up @@ -64,6 +64,9 @@ def test_build_not_in_builds(self):
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)

Expand Down Expand Up @@ -120,6 +123,32 @@ def test_build_not_in_builds(self):
self.assertEquals(pkg.arch, 'noarch')
self.assertEquals(pkg.filename, 'TurboGears-1.0.2.2-2.fc17.noarch.rpm')

def test_date_modified_none(self):
"""The metadata should use utcnow() if an update's date_modified is None."""
update = self.db.query(Update).one()
update.date_modified = 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].updated_date).seconds) < 1)

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) < 1)


class TestUpdateInfoMetadata(base.BaseTestCase):

Expand Down

0 comments on commit 8e1aded

Please sign in to comment.