Skip to content

Commit

Permalink
Make sure that an update is obsoleted if it reaches unstable karma th…
Browse files Browse the repository at this point in the history
…reshold on pending state
  • Loading branch information
trishnaguha committed Sep 20, 2016
1 parent a9e6f39 commit 197198c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bodhi/server/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,18 @@ def get_pushed_color(self):
color = '#00ff00' # green
return color

def obsolete_if_unstable(self, db):
"""
If an update with pending status(autopush enabled) reaches unstable karma
threshold, make sure it gets obsoleted.
"""
if self.autokarma and self.status is UpdateStatus.pending and self.request is UpdateRequest.testing \
and self.unstable_karma not in (0, None) and self.karma <= self.unstable_karma:
log.info("%s has reached unstable karma thresholds" % self.title)
self.obsolete(db)
flash_log("%s has been obsoleted." % self.title)
return

def comment(self, session, text, karma=0, author=None, anonymous=False,
karma_critpath=0, bug_feedback=None, testcase_feedback=None,
check_karma=True):
Expand Down Expand Up @@ -1465,6 +1477,9 @@ def comment(self, session, text, karma=0, author=None, anonymous=False,
caveats.append({
'name': 'karma', 'description': str(e),
})

# Obsolete pending update if it reaches unstable karma threshold
self.obsolete_if_unstable(session)
else:
log.debug('Ignoring duplicate %d karma from %s on %s' % (karma, author, self.title))

Expand Down
27 changes: 27 additions & 0 deletions bodhi/tests/server/functional/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,33 @@ def test_revoke_action_for_testing_request(self, publish, *args):
publish.assert_called_with(
topic='update.request.revoke', msg=mock.ANY)

@mock.patch(**mock_valid_requirements)
@mock.patch('bodhi.server.notifications.publish')
def test_obsolete_update_on_pending_state(self, publish, *args):
"""
Send update to obsolete state if it reaches unstable karma on
pending state. Make sure that it doesn't go to update-testing
This will happen only when Autopush is enabled.
"""
nvr = u'bodhi-2.0.0-2.fc17'
args = self.get_update(nvr)
args['autokarma'] = True
args['stable_karma'] = 1
args['unstable_karma'] = -1

resp = self.app.post_json('/updates/', args)

up = Update.get(nvr, self.db)
up.status = UpdateStatus.pending
up.request = UpdateRequest.testing
up.comment(self.db, u'Failed to work', author=u'ralph', karma=-1)
self.db.flush()

up = self.db.query(Update).filter_by(title=nvr).one()
self.assertEquals(up.karma, -1)
self.assertEquals(up.status, UpdateStatus.obsolete)
self.assertEquals(up.request, None)

@mock.patch(**mock_taskotron_results)
@mock.patch(**mock_valid_requirements)
@mock.patch('bodhi.server.notifications.publish')
Expand Down

0 comments on commit 197198c

Please sign in to comment.