From a7272bb497a6163edae356b5653125640291f8e5 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 2 Oct 2023 12:50:59 -0400 Subject: [PATCH] Improve detection of Container and Flatpak updates 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 (cherry picked from commit b32286e5094a6064450fb12962a17602359e62a0) --- bodhi-server/bodhi/server/buildsys.py | 1 - bodhi-server/bodhi/server/models.py | 12 +++++++-- bodhi-server/tests/services/test_updates.py | 28 ++++++++++++++++++++- news/PR5496.bug | 1 + 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 news/PR5496.bug diff --git a/bodhi-server/bodhi/server/buildsys.py b/bodhi-server/bodhi/server/buildsys.py index 4cc6b9fe14..ef55b077a1 100644 --- a/bodhi-server/bodhi/server/buildsys.py +++ b/bodhi-server/bodhi/server/buildsys.py @@ -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': { diff --git a/bodhi-server/bodhi/server/models.py b/bodhi-server/bodhi/server/models.py index 08ffaa7def..1439b09b26 100644 --- a/bodhi-server/bodhi/server/models.py +++ b/bodhi-server/bodhi/server/models.py @@ -586,6 +586,8 @@ 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 @@ -593,8 +595,14 @@ def infer_content_class(cls, base, build): 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 diff --git a/bodhi-server/tests/services/test_updates.py b/bodhi-server/tests/services/test_updates.py index ef8eaa6b48..4d3118d6a3 100644 --- a/bodhi-server/tests/services/test_updates.py +++ b/bodhi-server/tests/services/test_updates.py @@ -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 ( @@ -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): diff --git a/news/PR5496.bug b/news/PR5496.bug new file mode 100644 index 0000000000..a5bfc33024 --- /dev/null +++ b/news/PR5496.bug @@ -0,0 +1 @@ +Fixed the detection of Flatpak update type