Skip to content

Commit

Permalink
bodhi-check-policies now also operates on pushed updates.
Browse files Browse the repository at this point in the history
fixes #2085

Signed-off-by: Randy Barlow <[email protected]>
  • Loading branch information
bowlofeggs committed Jan 16, 2018
1 parent 6f5618c commit ca4320c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 2 additions & 4 deletions bodhi/server/scripts/check_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
messages in the message bus yet.
"""
import click
from sqlalchemy.sql.expression import false

from bodhi.server import config, initialize_db, models, Session
from bodhi.server.util import greenwave_api_post
Expand All @@ -37,9 +36,8 @@ def check():
initialize_db(config.config)
session = Session()

updates = models.Update.query.filter(models.Update.pushed == false())\
.filter(models.Update.status.in_(
[models.UpdateStatus.pending, models.UpdateStatus.testing]))
updates = models.Update.query.filter(models.Update.status.in_(
[models.UpdateStatus.pending, models.UpdateStatus.testing]))
for update in updates:
# We retrieve updates going to testing (status=pending) and updates
# (status=testing) going to stable.
Expand Down
31 changes: 31 additions & 0 deletions bodhi/tests/server/scripts/test_check_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,37 @@ def test_no_policies_enforced(self):
mock_greenwave.assert_called_once_with(config['greenwave_api_url'] + '/decision',
expected_query)

@patch.dict(config, [('greenwave_api_url', 'http://domain.local')])
def test_pushed_update(self):
"""Assert that check() operates on pushed updates."""
runner = testing.CliRunner()
update = self.db.query(models.Update).all()[0]
update.status = models.UpdateStatus.testing
update.pushed = True
self.db.commit()
with patch('bodhi.server.scripts.check_policies.greenwave_api_post') as mock_greenwave:
greenwave_response = {
'policies_satisfied': False,
'summary': 'it broke',
'applicable_policies': ['bodhi-unrestricted'],
}
mock_greenwave.return_value = greenwave_response

result = runner.invoke(check_policies.check, [])

self.assertEqual(result.exit_code, 0)
update = self.db.query(models.Update).filter(models.Update.id == update.id).one()
self.assertEqual(update.test_gating_status, models.TestGatingStatus.failed)
self.assertEqual(update.greenwave_summary_string, 'it broke')
expected_query = {
'product_version': 'fedora-17', 'decision_context': 'bodhi_update_push_stable',
'subject': [{'item': u'bodhi-2.0-1.fc17', 'type': 'koji_build'},
{'original_spec_nvr': u'bodhi-2.0-1.fc17'},
{'item': u'FEDORA-{}-a3bbe1a8f2'.format(datetime.datetime.utcnow().year),
'type': 'bodhi_update'}]}
mock_greenwave.assert_called_once_with(config['greenwave_api_url'] + '/decision',
expected_query)

@patch.dict(config, [('greenwave_api_url', 'http://domain.local')])
def test_unrestricted_policy(self):
"""Assert correct behavior when an unrestricted policy is applied"""
Expand Down

0 comments on commit ca4320c

Please sign in to comment.