From a81c44c897cc2ffedf7d062259b3bac3c2bb3f33 Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Wed, 7 Mar 2018 11:31:19 +0100 Subject: [PATCH] Allow version-specific repomd url override Signed-off-by: Patrick Uiterwijk --- bodhi/server/consumers/masher.py | 20 ++++++++---- bodhi/tests/server/consumers/test_masher.py | 36 +++++++++++++++++++-- production.ini | 8 +++-- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/bodhi/server/consumers/masher.py b/bodhi/server/consumers/masher.py index 149160955e..a0b4dfb88c 100644 --- a/bodhi/server/consumers/masher.py +++ b/bodhi/server/consumers/masher.py @@ -995,24 +995,30 @@ def _get_master_repomd_url(self, arch): basestring: A URL on the master mirror where the repomd.xml file should be synchronized. """ release = self.compose.release.id_prefix.lower().replace('-', '_') + version = self.compose.release.version request = self.compose.request.value + # First check to see if there's an override for the current version, if not, fall back. + # This will first try fedora_28_stable_(suffix), and then fedora_stable_(suffix). + key_prefixes = ['%s_%s_%s' % (release, version, request), + '%s_%s' % (release, request)] # If the release has primary_arches defined in the config, we need to consider whether to # use the release's *alt_master_repomd setting. primary_arches = config.get( '{release}_{version}_primary_arches'.format( release=release, version=self.compose.release.version)) if primary_arches and arch not in primary_arches.split(): - key = '%s_%s_alt_master_repomd' + suffix = '_alt_master_repomd' else: - key = '%s_%s_master_repomd' - key = key % (release, request) + suffix = '_master_repomd' - master_repomd = config.get(key) - if not master_repomd: - raise ValueError("Could not find %s in the config file" % key) + keys = [key_prefix + suffix for key_prefix in key_prefixes] - return master_repomd % (self.compose.release.version, arch) + for key in keys: + val = config.get(key) + if val: + return val % (version, arch) + raise ValueError("Could not find any of %s in the config file" % ','.join(keys)) def _punge(self): """ diff --git a/bodhi/tests/server/consumers/test_masher.py b/bodhi/tests/server/consumers/test_masher.py index e01d5b98b1..18ce4fa808 100644 --- a/bodhi/tests/server/consumers/test_masher.py +++ b/bodhi/tests/server/consumers/test_masher.py @@ -1789,7 +1789,8 @@ def test_master_repomd_undefined(self): t._get_master_repomd_url('aarch64') self.assertEqual(six.text_type(exc.exception), - 'Could not find fedora_testing_alt_master_repomd in the config file') + 'Could not find any of fedora_17_testing_alt_master_repomd,' + 'fedora_testing_alt_master_repomd in the config file') @mock.patch.dict( 'bodhi.server.consumers.masher.config', @@ -1815,6 +1816,36 @@ def test_primary_arch(self): 'http://example.com/pub/fedora/linux/updates/testing/17/x86_64/repodata.repomd.xml' ) + @mock.patch.dict( + 'bodhi.server.consumers.masher.config', + {'fedora_17_primary_arches': 'armhfp x86_64', + 'fedora_testing_master_repomd': + 'http://example.com/pub/fedora/linux/updates/testing/%s/%s/repodata.repomd.xml', + 'fedora_testing_alt_master_repomd': + 'http://example.com/pub/fedora-secondary/updates/testing/%s/%s/repodata.repomd.xml', + 'fedora_17_testing_master_repomd': + 'http://example.com/pub/fedora/linux/updates/testing/%s/Everything/' + '%s/repodata.repomd.xml'}) + def test_primary_arch_version_override(self): + """ + Assert that if a release_version_request setting exists, that overrides release_request. + """ + msg = self._make_msg() + + t = PungiComposerThread(self.semmock, msg['body']['msg']['composes'][0], + 'bowlofeggs', log, self.Session, self.tempdir) + t.compose = Compose.from_dict(self.db, msg['body']['msg']['composes'][0]) + + url = t._get_master_repomd_url('x86_64') + + self.assertEqual( + url, + 'http://example.com/pub/fedora/linux/updates/testing/17/Everything/' + 'x86_64/repodata.repomd.xml' + ) + + self.assert_sems(0) + @mock.patch.dict( 'bodhi.server.consumers.masher.config', {'fedora_testing_master_repomd': @@ -2204,7 +2235,8 @@ def test_missing_config_key(self, publish): t._wait_for_sync() self.assertEqual(six.text_type(exc.exception), - 'Could not find fedora_testing_master_repomd in the config file') + 'Could not find any of fedora_17_testing_master_repomd,' + 'fedora_testing_master_repomd in the config file') publish.assert_called_once_with(topic='mashtask.sync.wait', msg={'repo': t.id, 'agent': 'bowlofeggs'}, force=True) diff --git a/production.ini b/production.ini index 605ac2fbc2..09553c05c6 100644 --- a/production.ini +++ b/production.ini @@ -160,7 +160,7 @@ use = egg:bodhi-server # file_url: Used in the repo metadata to set RPM URLs. # file_url = https://download.fedoraproject.org/pub/fedora/linux/updates -# {release}_{request}_master_repomd: This is used by the masher to determine when a +# {release}_({version}_){request}_master_repomd: This is used by the masher to determine when a # primary architecture push has been synchronized to the master mirror for a given release and # request. The masher will verify that the checksum of repomd.xml at the master URL matches the # expected value, and will poll the URL until this test passes. Substitute release and request @@ -168,13 +168,15 @@ use = egg:bodhi-server # arches listed in {release}_{version}_primary_arches when it is defined, else used for all # arches. You must put two %s's in this setting - the first will be replaced with the release # version and the second will be replaced with the architecture. +# If a version of the option exists with a matching version, it has priority over one without. # examples (these settings do not have defaults): # fedora_stable_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora/linux/updates/%s/%s/repodata/repomd.xml +# fedora_28_stable_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora/linux/updates/%s/Everything/%s/repodata/repomd.xml # fedora_testing_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora/linux/updates/testing/%s/%s/repodata/repomd.xml # fedora_epel_stable_master_repomd = http://download01.phx2.fedoraproject.org/pub/epel/%s/%s/repodata/repomd.xml # fedora_epel_testing_master_repomd = http://download01.phx2.fedoraproject.org/pub/epel/testing/%s/%s/repodata/repomd.xml -# {release}_{request}_alt_master_repomd: This is used by the masher to determine when a +# {release}_({version}_){request}_alt_master_repomd: This is used by the masher to determine when a # secondary architecture push has been synchronized to the master mirror for a given release and # request. The masher will verify that the checksum of repomd.xml at the master URL matches the # expected value, and will poll the URL until this test passes. Substitute release and request @@ -182,8 +184,10 @@ use = egg:bodhi-server # arches not listed in {release}_{version}_primary_arches if it is defined. You must put two # %s's in this setting - the first will be replaced with the release version and the second will # be replaced with the architecture. +# If a version of the option exists with a matching version, it has priority over one without. # examples (these settings do not have defaults): # fedora_stable_alt_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora-secondary/updates/%s/%s/repodata/repomd.xml +# fedora_28_stable_alt_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora-secondary/updates/%s/Everything/%s/repodata/repomd.xml # fedora_testing_alt_master_repomd = http://download01.phx2.fedoraproject.org/pub/fedora-secondary/updates/testing/%s/%s/repodata/repomd.xml