pyramid/bodhi/bodhi/models/models.py | 90 +++++++++---------------
pyramid/bodhi/bodhi/tests/models/test_models.py | 30 +++++++-
pyramid/bodhi/bodhi/util.py | 5 +
3 files changed, 70 insertions(+), 55 deletions(-)
New commits:
commit 6f9a376bee1f92a5b4bffa4dfe71cd2a0374410d
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:11:15 2011 -0400
Refactor and clean up our Update.set_request method.
Remove a lot of unnecessary code that [poorly] checks for broken
upgrade paths, now that we can rely on AutoQA for that.
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index 4f6ceb8..b5dccbc 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -379,23 +379,19 @@ class Update(Base):
DBSession.flush()
- def set_request(self, action, pathcheck=True):
+ def set_request(self, action):
""" Attempt to request an action for this update.
This method either sets the given request on this update, or raises
an InvalidRequest exception.
At the moment, this method cannot be called outside of a request.
-
- @param pathcheck: Check for broken update paths for stable requests
"""
if not authorized_user(self, identity):
raise InvalidRequest("Unauthorized to perform action on %s" %
self.title)
action = UpdateRequest.from_string(action)
- #if action not in ('testing', 'stable', 'obsolete',
'unpush'):
- # raise InvalidRequest("Unknown request: %s" % action)
- if action.description == self.status.description:
+ if action is self.status:
raise InvalidRequest("%s already %s" % (self.title,
action.description))
if action is self.request:
@@ -411,30 +407,17 @@ class Update(Base):
self.obsolete()
flash_log("%s has been obsoleted" % self.title)
return
- elif self.type is UpdateType.security and not self.approved:
- flash_log("%s is awaiting approval of the Security Team" %
- self.title)
- self.request = action
- return
- elif action is UpdateRequest.stable and pathcheck:
- # Make sure we don't break update paths by trying to push out
- # an update that is older than than the latest.
- koji = buildsys.get_session()
- for build in self.builds:
- mybuild = koji.getBuild(build.nvr)
- mybuild['nvr'] = "%s-%s-%s" %
(mybuild['name'],
- mybuild['version'],
- mybuild['release'])
- kojiBuilds = koji.listTagged(self.release.dist_tag + '-updates',
- package=build.package.name,
- latest=True)
- for oldBuild in kojiBuilds:
- if rpm.labelCompare(build_evr(mybuild),
- build_evr(oldBuild)) < 0:
- raise InvalidRequest("Broken update path: %s is "
- "already released, and is newer "
- "than %s" %
(oldBuild['nvr'],
- mybuild['nvr']))
+ # TODO:
+ # Make it so that we can optionally configure bodhi to require mandatory
+ # signoff from a specific group before an update can hit stable:
+ # eg: Security Team (for security updates)
+ # or
+ # AutoQA (for all updates)
+ #elif self.type is UpdateType.security and not self.date_approved:
+ # flash_log("%s is awaiting approval of the Security Team" %
+ # self.title)
+ # self.request = action
+ # return
self.request = action
self.pushed = False
self.date_pushed = None
@@ -449,19 +432,13 @@ class Update(Base):
Perform post-request actions.
"""
if self.request is UpdateRequest.testing:
- self.pushed = True
- self.date_pushed = datetime.utcnow()
- self.status = UpdateType.testing
- self.assign_alias()
- elif self.request is UpdateRequest.obsolete:
- self.pushed = False
- self.status = UpdateStatus.obsolete
+ self.status = UpdateStatus.testing
elif self.request is UpdateRequest.stable:
- self.pushed = True
- self.date_pushed = datetime.utcnow()
self.status = UpdateStatus.stable
- self.assign_alias()
self.request = None
+ self.pushed = True
+ self.date_pushed = datetime.utcnow()
+ self.assign_alias()
def modify_bugs(self):
"""
commit 3daa1164c6430f887f60317ebff93e1b6086da29
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:10:45 2011 -0400
More porting fixes and hacks
diff --git a/pyramid/bodhi/bodhi/models/models.py b/pyramid/bodhi/bodhi/models/models.py
index feec273..4f6ceb8 100644
--- a/pyramid/bodhi/bodhi/models/models.py
+++ b/pyramid/bodhi/bodhi/models/models.py
@@ -1,6 +1,7 @@
import os
import time
import logging
+import bugzilla
import xmlrpclib
import transaction
@@ -17,13 +18,17 @@ from sqlalchemy.ext.declarative import declarative_base, synonym_for
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound
-from bodhi.util import header, build_evr
from bodhi import buildsys, mail
+from bodhi.util import header, build_evr, authorized_user, rpm_fileheader, get_nvr,
flash_log, get_age
+from bodhi.util import get_age_in_days # TODO: move these methods into the model
from bodhi.models.enum import DeclEnum
+from bodhi.exceptions import InvalidRequest, RPMNotFound
log = logging.getLogger(__name__)
config = {} # FIXME!
+from bunch import Bunch
+identity = Bunch(current=Bunch(user_name=u'Bob'))
class BodhiBase(object):
""" Our custom model base class """
@@ -39,6 +44,8 @@ DBSession = scoped_session(sessionmaker())
##
## Enumerated type declarations
+## Note: We're using single-letter names at the moment for compatiblity with
+## sqlite dbs
##
class UpdateStatus(DeclEnum):
@@ -292,8 +299,8 @@ class Update(Base):
@synonym_for('_title')
@property
- def title(self, delim=' '):
- title = ', '.join([build.package.name for build in self.builds])
+ def title(self, show_nvrs=True, delim=' '):
+ title = ', '.join([build.nvr for build in self.builds])
return title + ' %s update' % self.type.description
def get_title(self, delim=' '):
@@ -477,7 +484,7 @@ class Update(Base):
# Now, close our parents bugs as long as nothing else
# depends on them, and they are not in a NEW state
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
for bug in self.bugs:
if bug.parent:
parent = bz.getbug(bug.bug_id)
@@ -653,11 +660,11 @@ class Update(Base):
Create any new CVES, and remove any missing ones. Destroy removed CVES
that are no longer referenced anymore.
"""
+ Session = DBSession()
for cve in self.cves:
if cve.cve_id not in cves and len(cve.updates) == 0:
log.debug("Destroying stray CVE #%s" % cve.cve_id)
- session.delete(cve)
- session.flush()
+ Session.delete(cve)
for cve_id in cves:
try:
cve = CVE.query.filter_by(cve_id=cve_id).one()
@@ -666,9 +673,9 @@ class Update(Base):
except: # TODO: catch sqlalchemy's not found exception!
log.debug("Creating new CVE: %s" % cve_id)
cve = CVE(cve_id=cve_id)
- session.save(cve)
+ ession.save(cve)
self.cves.append(cve)
- session.flush()
+ Session.commit()
def get_pushed_age(self):
return get_age(self.date_pushed)
@@ -759,7 +766,7 @@ class Update(Base):
self.pushed = False
self.status = UpdateStatus.unpushed
mail.send_admin('unpushed', self)
- session.flush()
+ #DBSession.flush()
def untag(self):
""" Untag all of the builds in this update """
@@ -887,7 +894,7 @@ class Bug(Base):
def fetch_details(self, bug=None):
if not bug:
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
try:
bug = bz.getbug(self.bug_id)
except xmlrpclib.Fault, f:
@@ -919,7 +926,7 @@ class Bug(Base):
if not config.get('bodhi_email'):
log.warning("No bodhi_email defined; skipping bug comment")
return
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
if not comment:
comment = self._default_message(update)
log.debug("Adding comment to Bug #%d: %s" % (self.bug_id, comment))
@@ -935,7 +942,7 @@ class Bug(Base):
Change the status of this bug to ON_QA, and comment on the bug with
some details on how to test and provide feedback for this update.
"""
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
comment = self._default_message(update)
log.debug("Setting Bug #%d to ON_QA" % self.bug_id)
try:
@@ -945,7 +952,7 @@ class Bug(Base):
log.error("Unable to alter bug #%d\n%s" % (self.bug_id, str(e)))
def close_bug(self, update):
- bz = Bugzilla.get_bz()
+ bz = Bug.get_bz()
try:
ver = '-'.join(get_nvr(update.builds[0].nvr)[-2:])
bug = bz.getbug(self.bug_id)
diff --git a/pyramid/bodhi/bodhi/util.py b/pyramid/bodhi/bodhi/util.py
index 77d2ac2..ba18d05 100644
--- a/pyramid/bodhi/bodhi/util.py
+++ b/pyramid/bodhi/bodhi/util.py
@@ -123,6 +123,8 @@ def synchronized(lock):
return wrap
def authorized_user(update, identity):
+ # FIXME: port to pyramid auth
+ return True
return 'releng' in identity.current.groups or \
'cvsadmin' in identity.current.groups or \
'security_respons' in identity.current.groups or \
@@ -183,7 +185,8 @@ def get_age_in_days(date):
def flash_log(msg):
""" Flash and log a given message """
- flash(msg)
+ # FIXME: request.session.flash()
+ #flash(msg)
log.debug(msg)
def get_release_names():
commit 0c1babe14513dbf5fa44fdd68c7890864b31b119
Author: Luke Macken <lmacken(a)redhat.com>
Date: Thu May 12 02:09:53 2011 -0400
More model tests
diff --git a/pyramid/bodhi/bodhi/tests/models/test_models.py
b/pyramid/bodhi/bodhi/tests/models/test_models.py
index 7d694b0..359695f 100644
--- a/pyramid/bodhi/bodhi/tests/models/test_models.py
+++ b/pyramid/bodhi/bodhi/tests/models/test_models.py
@@ -11,6 +11,7 @@ from sqlalchemy.exc import IntegrityError
from bodhi import models as model
from bodhi.models import UpdateStatus, UpdateType, UpdateRequest
from bodhi.tests.models import ModelTest
+from bodhi.exceptions import InvalidRequest
class TestRelease(ModelTest):
"""Unit test case for the ``Release`` model."""
@@ -140,7 +141,7 @@ class TestUpdate(ModelTest):
eq_(self.obj.builds[0].package.name, u'TurboGears')
def test_title(self):
- eq_(self.obj.title, u'TurboGears security update')
+ eq_(self.obj.title, u'TurboGears-1.0.8-3.fc11 security update')
def test_pkg_str(self):
""" Ensure str(pkg) is correct """
@@ -277,4 +278,31 @@ class TestUpdate(ModelTest):
assert update.bugs[0].bug_id == 4321
eq_(model.DBSession.query(model.Bug).filter_by(bug_id=1234).first(), None)
+ def test_set_request_unpush(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.status = UpdateStatus.testing
+ self.obj.set_request('U')
+ eq_(self.obj.status, UpdateStatus.unpushed)
+
+ @raises(InvalidRequest)
+ def test_set_request_testing(self):
+ self.obj.set_request('T')
+
+ def test_set_request_stable(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.set_request('S')
+ eq_(self.obj.status, UpdateStatus.pending)
+ # TODO: verify results (via session flash?)
+
+ def test_set_request_obsolete(self):
+ eq_(self.obj.status, UpdateStatus.pending)
+ self.obj.set_request('O')
+ eq_(self.obj.status, UpdateStatus.obsolete)
+
+ def test_request_complete(self):
+ eq_(self.obj.pushed, False)
+ eq_(self.obj.date_pushed, None)
+ eq_(self.obj.pushed, True)
+ assert self.obj.date_pushed
+
# test multibuild update