From fd470d0fb01378f59859d623f346109e66b5e043 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Oct 13 2017 08:11:42 +0000 Subject: Tweak lightblue queries to account for schema change rpm manifest is being moved to a new entity. Fortunately containerImage contains reference in "rpm_manifest" top level field. So we can just use it instead of parsed_data.rpm_manifest in the same way. The reference is an array though and should have one object with "rpms" key which is where our list of rpm objects actually is. This change tweaks the queries to use the new reference field instead of parsed data. --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index 27c55b2..9a3f576 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -180,8 +180,9 @@ class ContainerImage(dict): image is rebuilt. """ srpm_nevra = None - if "parsed_data" in self and "rpm_manifest" in self["parsed_data"]: - for rpm in self["parsed_data"]["rpm_manifest"]: + if ("rpm_manifest" in self and len(self['rpm_manifest']) > 0 and + "rpms" in self["rpm_manifest"]): + for rpm in self["rpm_manifest"]['rpms']: if "srpm_name" in rpm and rpm["srpm_name"] == srpm_name: srpm_nevra = rpm['srpm_nevra'] break @@ -467,8 +468,8 @@ class LightBlue(object): return [ {"field": "brew", "include": True, "recursive": True}, {"field": "parsed_data.files", "include": True, "recursive": True}, - {"field": "parsed_data.rpm_manifest.*.srpm_nevra", "include": True, "recursive": True}, - {"field": "parsed_data.rpm_manifest.*.srpm_name", "include": True, "recursive": True}, + {"field": "rpm_manifest.*.rpms.*.srpm_nevra", "include": True, "recursive": True}, + {"field": "rpm_manifest.*.rpms.*.srpm_name", "include": True, "recursive": True}, {"field": "parsed_data.layers.*", "include": True, "recursive": True}, {"field": "repositories.*.published", "include": True, "recursive": True}, {"field": "repositories.*.repository", "include": True, "recursive": True}, @@ -508,7 +509,7 @@ class LightBlue(object): "rvalue": "latest" }, { - "field": "parsed_data.rpm_manifest.*.srpm_name", + "field": "rpm_manifest.*.rpms.*.srpm_name", "op": "=", "rvalue": srpm_name }, @@ -599,7 +600,7 @@ class LightBlue(object): } if srpm_name: query['query']['$and'].append({ - "field": "parsed_data.rpm_manifest.*.srpm_name", + "field": "rpm_manifest.*.rpms.*.srpm_name", "op": "=", "rvalue": srpm_name }) diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index 719e227..2b46006 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -142,8 +142,8 @@ class TestContainerImageObject(unittest.TestCase): 'build': 'package-name-1-4-12.10', 'package': 'package-name-1' }, - 'parsed_data': { - 'rpm_manifest': [ + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-0:1.2.3-1.src" @@ -176,8 +176,8 @@ class TestContainerImageObject(unittest.TestCase): 'build': 'package-name-1-4-12.10', 'package': 'package-name-1' }, - 'parsed_data': { - 'rpm_manifest': [ + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-0:1.2.3-1.src" @@ -211,8 +211,8 @@ class TestContainerImageObject(unittest.TestCase): 'build': 'package-name-1-4-12.10', 'package': 'package-name-1' }, - 'parsed_data': { - 'rpm_manifest': [ + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-0:1.2.3-1.src" @@ -319,7 +319,9 @@ class TestQueryEntityFromLightBlue(unittest.TestCase): 'filename': u'Dockerfile' } ], - 'rpm_manifest': [ + }, + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-0:1.2.3-1.src" @@ -353,7 +355,9 @@ class TestQueryEntityFromLightBlue(unittest.TestCase): 'filename': 'bogus.file' } ], - 'rpm_manifest': [ + }, + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-1:1.2.3-1.src" @@ -626,7 +630,7 @@ class TestQueryEntityFromLightBlue(unittest.TestCase): "rvalue": "latest" }, { - "field": "parsed_data.rpm_manifest.*.srpm_name", + "field": "rpm_manifest.*.rpms.*.srpm_name", "op": "=", "rvalue": "openssl" }, @@ -692,8 +696,10 @@ class TestQueryEntityFromLightBlue(unittest.TestCase): 'content_url': 'http://git.repo.com/cgit/rpms/repo-1/plain/Dockerfile?id=commit_hash1', 'filename': u'Dockerfile' } - ], - 'rpm_manifest': [ + ] + }, + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-0:1.2.3-1.src" @@ -731,8 +737,10 @@ class TestQueryEntityFromLightBlue(unittest.TestCase): 'content_url': 'bogus_test_url', 'filename': 'bogus.file' } - ], - 'rpm_manifest': [ + ] + }, + 'rpm_manifest': { + 'rpms': [ { "srpm_name": "openssl", "srpm_nevra": "openssl-1:1.2.3-1.src"