Skip to content

Commit

Permalink
Publish UpdateReadyForTesting whenever an update is created
Browse files Browse the repository at this point in the history
See https://pagure.io/fedora-ci/general/issue/436 . This is the
behaviour test systems want, based on real-world experience.
We do not want test systems to wait for updates to reach the
updates-testing repo before they test; we want them to test as
soon as the update is created. All the test systems that exist
pull the builds to be tested from Koji, they do not rely on them
being present in updates-testing.

Waiting for the update to reach updates-testing before tests run
can mean a wait of up to 24 hours, which is obviously not ideal
when people want test results fast. It also means we can't gate
push to updates-testing on tests that trigger on this message.

openQA currently listens out for other messages to use as a
proxy for 'update was created' in order to mitigate this problem,
but Fedora CI does not do so, and consequently its tests often
trigger late. This change, along with the earlier change to
publish this message when an update's builds are changed, will
allow us to simplify openQA's logic considerably (it can just
trigger any time it sees this message) and improve CI's
scheduling considerably without any need to make changes to the
trigger logic on the CI side.

Signed-off-by: Adam Williamson <[email protected]>
  • Loading branch information
AdamWill committed Nov 24, 2023
1 parent 08e3907 commit 14322d3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 91 deletions.
34 changes: 10 additions & 24 deletions bodhi-server/bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,8 +2014,8 @@ def __init__(self, *args, **kwargs):

log.debug('Set alias for %s to %s' % (self.get_title(), alias))

if self.status == UpdateStatus.testing:
self._ready_for_testing(self, self.status, None, None)
if self.content_type == ContentType.rpm:
self._ready_for_testing(self, None)

@property
def version_hash(self):
Expand Down Expand Up @@ -4223,10 +4223,10 @@ def _build_group_test_message(self, agent="bodhi", retrigger=False):
"""
Build the dictionary sent when an update is ready to be tested.
This is used in bodhi.server.models.Update._ready_for_testing and in
bodhi.server.services.updates.trigger_tests which are the two places
where we send notifications about an update being ready to be tested
by any CI system.
This is used when we send notifications about an update being
ready to be tested by any CI system - on update creation, any
time the update is edited and its builds change, and if someone
hits the Re-Trigger Tests button in the web UI.
Args:
agent (str): For the case where the message is sent as a test
Expand Down Expand Up @@ -4258,23 +4258,17 @@ def _build_group_test_message(self, agent="bodhi", retrigger=False):
}

@staticmethod
def _ready_for_testing(target, value, old, initiator):
def _ready_for_testing(target, old):
"""
Signal that the update has been moved to testing.
Signal that the update is ready for testing.
This happens in the following cases:
This happens when the update is created.
- for stable releases: the update lands in the testing repository
- for rawhide: all packages in an update have been built by koji
Args:
target (Update): The update that has had a change to its status attribute.
value (EnumSymbol): The new value of Update.status.
old (EnumSymbol): The old value of the Update.status
initiator (sqlalchemy.orm.attributes.Event): The event object that is initiating this
transition.
target (Update): The update that has been created.
"""
if value != UpdateStatus.testing or value == old:
return
if old == NEVER_SET:
# This is the object initialization phase. This instance is not ready, don't create
# the message now. This method will be called again at the end of __init__
Expand All @@ -4297,14 +4291,6 @@ def _ready_for_testing(target, value, old, initiator):
)


event.listen(
Update.status,
'set',
Update._ready_for_testing,
active_history=True,
)


class Compose(Base):
"""
Express the status of an in-progress compose job.
Expand Down
17 changes: 10 additions & 7 deletions bodhi-server/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ def create_update(session, build_nvrs, release_name='F17'):
expiration_date=expiration_date)
session.add(override)

update = models.Update(
builds=builds, user=user, request=models.UpdateRequest.testing,
notes='Useful details!', type=models.UpdateType.bugfix,
date_submitted=datetime(1984, 11, 2),
requirements='rpmlint', stable_karma=3, unstable_karma=-3, release=release)
with mock.patch('bodhi.server.models.notifications'):
update = models.Update(
builds=builds, user=user, request=models.UpdateRequest.testing,
notes='Useful details!', type=models.UpdateType.bugfix,
date_submitted=datetime(1984, 11, 2),
requirements='rpmlint', stable_karma=3, unstable_karma=-3, release=release)
session.add(update)
return update

Expand Down Expand Up @@ -185,7 +186,8 @@ def populate(db):
db.flush()
# This mock will help us generate a consistent update alias.
with mock.patch(target='uuid.uuid4', return_value='wat'):
update = create_update(db, ['bodhi-2.0-1.fc17'])
with mock.patch('bodhi.server.models.notifications'):
update = create_update(db, ['bodhi-2.0-1.fc17'])
update.type = models.UpdateType.bugfix
update.severity = models.UpdateSeverity.medium
bug = models.Bug(bug_id=12345)
Expand Down Expand Up @@ -247,11 +249,12 @@ def _setup_method(self):
self.db = Session()
self.db.begin_nested()

buildsys.setup_buildsystem({'buildsystem': 'dev'})

if self._populate_db:
populate(self.db)

bugs.set_bugtracker()
buildsys.setup_buildsystem({'buildsystem': 'dev'})

self._request_sesh = mock.patch('bodhi.server.webapp._complete_database_session',
webapp._rollback_or_commit)
Expand Down
1 change: 1 addition & 0 deletions bodhi-server/tests/consumers/test_automatic_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@


@mock.patch('bodhi.server.consumers.automatic_updates.work_on_bugs_task', mock.Mock())
@mock.patch('bodhi.server.models.notifications', mock.Mock())
class TestAutomaticUpdateHandler(base.BasePyTestCase):
"""Test the automatic update handler."""

Expand Down
9 changes: 5 additions & 4 deletions bodhi-server/tests/tasks/test_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,11 @@ def test_tag_ordering(self, *args):
build = RpmBuild(nvr=otherbuild, package=firstupdate.builds[0].package,
release=firstupdate.release, signed=True)
session.add(build)
update = Update(
builds=[build], type=UpdateType.bugfix,
request=UpdateRequest.testing, notes='second update', user=firstupdate.user,
stable_karma=3, unstable_karma=-3, release=firstupdate.release)
with mock_sends(update_schemas.UpdateReadyForTestingV3):
update = Update(
builds=[build], type=UpdateType.bugfix,
request=UpdateRequest.testing, notes='second update', user=firstupdate.user,
stable_karma=3, unstable_karma=-3, release=firstupdate.release)
session.add(update)
session.flush()

Expand Down
41 changes: 7 additions & 34 deletions bodhi-server/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,17 +1937,19 @@ def test_add_bugs_bodhi_not_configured(self, warning):
package = model.RpmPackage.query.filter_by(name='bodhi').one()
build = model.RpmBuild(nvr='bodhi-6.0.0-1.fc36', release=release,
package=package, signed=False)
user = model.User(name='lmacken')
self.db.add(build)
data = {'release': release, 'builds': [build], 'from_tag': 'f36-build-side-1234',
'bugs': [], 'requirements': '', 'edited': '', 'autotime': True,
'stable_days': 3, 'stable_karma': 3, 'unstable_karma': -1,
'stable_days': 3, 'stable_karma': 3, 'unstable_karma': -1, user: user,
'notes': 'simple update', 'type': 'unspecified'}
request = mock.MagicMock()
request.db = self.db
request.identity.name = 'tester'
self.db.flush()

model.Update.new(request, data)
with mock_sends(update_schemas.UpdateReadyForTestingV3):
model.Update.new(request, data)

warning.assert_called_with('Not configured to handle bugs')

Expand Down Expand Up @@ -2090,7 +2092,7 @@ def test_rawhide_update_edit_move_to_testing(self):
request.db = self.db
request.identity.name = 'tester'

with mock_sends(update_schemas.UpdateEditV2, update_schemas.UpdateReadyForTestingV3):
with mock_sends(update_schemas.UpdateEditV2):
with mock.patch('bodhi.server.models.util.greenwave_api_post') as mock_greenwave:
greenwave_response = {
'policies_satisfied': False,
Expand Down Expand Up @@ -2640,7 +2642,7 @@ def test_autokarma_update_reaching_stable_karma(self):
update.status = UpdateStatus.testing
update.stable_karma = 1
# Now let's add some karma to get it to the required threshold
with mock_sends(Message, Message):
with mock_sends(Message):
update.comment(self.db, 'testing', author='hunter2', karma=1)

# meets_testing_requirement() should return True since the karma threshold has been reached
Expand Down Expand Up @@ -2870,6 +2872,7 @@ class TestUpdate(ModelTest):
suggest=UpdateSuggestion.reboot,
stable_karma=3,
unstable_karma=-3,
user=model.User(name='lmacken'),
close_bugs=True,
notes='foobar')

Expand Down Expand Up @@ -4918,36 +4921,6 @@ def test_comment_on_test_gating_status_change_email(self, mail):
# We should have two comments, one for each test_gating_status change
assert len(self.obj.comments) == 2

def test_set_status_testing(self):
"""Test that setting an update's status to testing sends a message."""
self.db.info['messages'] = []
with mock_sends(update_schemas.UpdateReadyForTestingV3):
self.obj.status = UpdateStatus.testing
msg = self.db.info['messages'][0]
self.db.commit()
assert msg.body["artifact"]["builds"][0]["nvr"] == "TurboGears-1.0.8-3.fc11"
assert msg.body["artifact"]["builds"][0]["task_id"] == 127621
assert msg.body["artifact"]["builds"][0]["id"] == 16058
assert msg.body["artifact"]["type"] == "koji-build-group"
assert msg.packages == ['TurboGears']

def test_create_with_status_testing(self):
"""Test that creating an update with the status set to testing sends a message."""
self.db.info['messages'] = []
with mock_sends(update_schemas.UpdateReadyForTestingV3):
self.get_update(name="TurboGears-1.0.8-4.fc11", override_args={
"status": UpdateStatus.testing,
"user": self.db.query(model.User).filter_by(name='lmacken').one()
})
assert len(self.db.info['messages']) == 1
msg = self.db.info['messages'][0]
self.db.commit()
assert msg.body["artifact"]["builds"][0]["nvr"] == "TurboGears-1.0.8-4.fc11"
assert msg.body["artifact"]["builds"][0]["task_id"] == 127621
assert msg.body["artifact"]["builds"][0]["id"] == 16058
assert msg.body["artifact"]["type"] == "koji-build-group"
assert msg.packages == ['TurboGears']

@mock.patch('bodhi.server.models.Update.obsolete')
@mock.patch('bodhi.server.models.Update.comment')
def test_obsolete_older_updates(self, comment, obsolete):
Expand Down
49 changes: 27 additions & 22 deletions bodhi-server/tests/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ def setup_method(self, method):
self.db.add(build)

# And an Update with the RpmBuild.
self.archived_release_update = models.Update(
builds=[build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=archived_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
with mock.patch('bodhi.server.models.notifications'):
self.archived_release_update = models.Update(
builds=[build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=archived_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
self.db.add(self.archived_release_update)
self.db.commit()

Expand Down Expand Up @@ -119,16 +120,18 @@ def test_defaults_to_filtering_correct_releases(self):
self.db.add(disabled_build)
self.db.add(pending_build)
# Now let's create updates for both packages.
disabled_release_update = models.Update(
builds=[disabled_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=disabled_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
pending_release_update = models.Update(
builds=[pending_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=pending_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
with mock.patch('bodhi.server.models.notifications'):
disabled_release_update = models.Update(
builds=[disabled_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=disabled_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
with mock.patch('bodhi.server.models.notifications'):
pending_release_update = models.Update(
builds=[pending_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=pending_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
self.db.add(disabled_release_update)
self.db.add(pending_release_update)
self.db.commit()
Expand Down Expand Up @@ -162,11 +165,12 @@ def test_two_releases(self):
current_build = models.RpmBuild(nvr='bodhi-2.3.2-1.fc18', release=current_release,
package=pkg)
self.db.add(current_build)
current_release_update = models.Update(
builds=[current_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=current_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
with mock.patch('bodhi.server.models.notifications'):
current_release_update = models.Update(
builds=[current_build], user=self.user,
request=models.UpdateRequest.stable, notes='Useful details!', release=current_release,
date_submitted=datetime(2016, 10, 28), requirements='', stable_karma=3,
unstable_karma=-3, type=models.UpdateType.bugfix)
self.db.add(current_release_update)
self.db.commit()

Expand Down Expand Up @@ -432,8 +436,9 @@ def setup_method(self, method):
Make some updates that can be pushed.
"""
super().setup_method(method)
python_nose = self.create_update(['python-nose-1.3.7-11.fc17'])
python_paste_deploy = self.create_update(['python-paste-deploy-1.5.2-8.fc17'])
with mock.patch('bodhi.server.models.notifications'):
python_nose = self.create_update(['python-nose-1.3.7-11.fc17'])
python_paste_deploy = self.create_update(['python-paste-deploy-1.5.2-8.fc17'])
# Make it so we have two builds to push out
python_nose.builds[0].signed = True
python_paste_deploy.builds[0].signed = True
Expand Down

0 comments on commit 14322d3

Please sign in to comment.