From daf162503cbc1915517c386a24b876e25339f223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 21 Sep 2017 09:41:43 +0200 Subject: [PATCH] Reject yum gather backend on Python 3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It will not run, and having a nice error message is better than a cryptic crash. Signed-off-by: Lubomír Sedlář --- doc/configuration.rst | 10 ++++++---- pungi/checks.py | 14 ++++++++++++-- tests/test_config.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index d0caacbc..8c65b906 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -575,10 +575,12 @@ Options * With ``greedy_method = "build" ``pkg-b-provider-1`` and ``pkg-b-provider-2`` will be pulled in. -**gather_backend** = ``yum`` - (*str*) -- Either ``yum`` or ``dnf``. This changes the entire codebase - doing dependency solving, so it can change the result in unpredictable - ways. +**gather_backend** + (*str*) --This changes the entire codebase doing dependency solving, so it + can change the result in unpredictable ways. + + On Python 2, the choice is between ``yum`` or ``dnf`` and defaults to + ``yum``. On Python 3 ``dnf`` is the only option and default. Particularly the multilib work is performed differently by using ``python-multilib`` library. Please refer to ``multilib`` option to see the diff --git a/pungi/checks.py b/pungi/checks.py index 50938582..5d7c1b90 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -581,8 +581,8 @@ def make_schema(): "gather_source_mapping": {"type": "string"}, "gather_backend": { "type": "string", - "enum": ["yum", "dnf"], - "default": "yum", + "enum": _get_gather_backends(), + "default": _get_default_gather_backend(), }, "gather_profiler": { "type": "boolean", @@ -1203,3 +1203,13 @@ CONFIG_DEPS = { ], }, } + + +def _get_gather_backends(): + if six.PY2: + return ['yum', 'dnf'] + return ['dnf'] + + +def _get_default_gather_backend(): + return 'yum' if six.PY2 else 'dnf' diff --git a/tests/test_config.py b/tests/test_config.py index 6da84d31..4cc09389 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,6 +10,7 @@ except ImportError: import os import six import sys +import mock sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) @@ -250,6 +251,38 @@ class GatherConfigTestCase(ConfigTestCase): cfg, [checks.REQUIRES.format('gather_source', 'json', 'gather_source_mapping')]) + def test_dnf_backend_is_default_on_py3(self): + cfg = load_config( + pkgset_source='koji', + pkgset_koji_tag='f27', + ) + + with mock.patch('six.PY2', new=False): + self.assertValidation(cfg, []) + self.assertEqual(cfg['gather_backend'], 'dnf') + + def test_yum_backend_is_default_on_py2(self): + cfg = load_config( + pkgset_source='koji', + pkgset_koji_tag='f27', + ) + + with mock.patch('six.PY2', new=True): + self.assertValidation(cfg, []) + self.assertEqual(cfg['gather_backend'], 'yum') + + def test_yum_backend_is_rejected_on_py3(self): + cfg = load_config( + pkgset_source='koji', + pkgset_koji_tag='f27', + gather_backend='yum', + ) + + with mock.patch('six.PY2', new=False): + self.assertValidation( + cfg, + ["Failed validation in gather_backend: 'yum' is not one of ['dnf']"]) + class OSBSConfigTestCase(ConfigTestCase): def test_validate(self):