Skip to content

Commit

Permalink
Improve detection of Container and Flatpak updates
Browse files Browse the repository at this point in the history
Instead of looking for container_koji_task_id in the build extra,
look for typeinfo.image. If we see typeinfo.image without pull specs
(e.g., an ISO image), error out cleanly up front.

Previously the code would assume an RPM update if you passed it the
build NVR of an ISO image.

Signed-off-by: Owen W. Taylor <[email protected]>
  • Loading branch information
owtaylor authored and mattiaverga committed Oct 3, 2023
1 parent 88d77df commit 3c135c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 0 additions & 1 deletion bodhi-server/bodhi/server/buildsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def getBuild(self, build='TurboGears-1.0.2.2-2.fc17', other=False, testing=False
format_data['repository'] = "{}/{}".format(fedora_release, name)

data['extra'] = {
'container_koji_task_id': 19708268,
'typeinfo': {
'image': {
'index': {
Expand Down
12 changes: 10 additions & 2 deletions bodhi-server/bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,23 @@ def infer_content_class(cls, base, build):
Returns:
BodhiBase: The type-specific child class of base that is appropriate to use with the
given koji build.
Raises:
ValueError: If there is no appropriate child class
"""
# Default value. Overridden below if we find markers in the build info
identity = cls.rpm

extra = build.get('extra') or {}
if 'module' in extra.get('typeinfo', {}):
identity = cls.module
elif 'container_koji_task_id' in extra:
if 'flatpak' in extra['typeinfo']['image']:
elif 'image' in extra.get('typeinfo', {}):
image_info = extra['typeinfo']['image']
if 'pull' not in image_info.get('index', {}):
raise ValueError(
(f"Image build {build['nvr']} cannot be used for update, "
"it has no pull specs")
)
if 'flatpak' in image_info:
identity = cls.flatpak
else:
identity = cls.container
Expand Down
28 changes: 27 additions & 1 deletion bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from bodhi.messages.schemas import base as base_schemas
from bodhi.messages.schemas import update as update_schemas
from bodhi.server import main
from bodhi.server import buildsys, main
from bodhi.server.config import config
from bodhi.server.exceptions import BodhiException, LockedUpdateException
from bodhi.server.models import (
Expand Down Expand Up @@ -678,6 +678,32 @@ def test_new_flatpak_update(self, *args):
assert up['karma'] == 0
assert up['requirements'] == 'rpmlint'

@mock.patch(**mock_uuid4_version1)
@mock.patch(**mock_valid_requirements)
def test_new_image_update_no_pull(self, *args):
self.create_release('28F')
data = self.get_update('mariadb-10.1-10.f28flatpak')

build = buildsys.get_session().getBuild('mariadb-10.1-10.f28flatpak')
del build['extra']['typeinfo']['image']['index']['pull']

with mock.patch("bodhi.server.buildsys.DevBuildsys.getBuild", return_value=build):
r = self.app.post_json('/updates/', data, status=500)

assert r.json_body == {
'errors': [
{
'description': (
'Image build mariadb-10.1-10.f28flatpak cannot be used for update, '
'it has no pull specs'
),
'location': 'body',
'name': 'ValueError',
}
],
'status': 'error',
}

@mock.patch.dict('bodhi.server.validators.config', {'acl_system': 'dummy'})
@mock.patch(**mock_valid_requirements)
def test_new_update_with_multiple_bugs(self, *args):
Expand Down
1 change: 1 addition & 0 deletions news/PR5496.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the detection of Flatpak update type

0 comments on commit 3c135c2

Please sign in to comment.