From 1759c1ba80156a8ec466e4ad31802930ade4ba8e Mon Sep 17 00:00:00 2001 From: Sinny Kumari Date: Wed, 4 Jul 2018 20:25:16 +0530 Subject: [PATCH] Expand version field during image_build using version_generator We can specify !VERSION_FROM_VERSION in version field during image_build to expand it to correct release number without any label information. Also implemented !RELEASE_FROM_DATE_RESPIN to provide correct release number. This helps to keep Atomic Host media files name produced by image_build during bodhi updates compose run consistent with nightly run. Fixes: https://pagure.io/pungi/issue/987 Merges: https://pagure.io/pungi/pull-request/995 Signed-off-by: Sinny Kumari --- doc/configuration.rst | 8 ++++++++ pungi/phases/base.py | 6 +++++- pungi/util.py | 4 ++++ tests/test_util.py | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/configuration.rst b/doc/configuration.rst index 2365db19..b956b797 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1165,6 +1165,14 @@ Image Build Settings ``!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN``, it will be replaced with a value generated as described in :ref:`automatic versioning `. + If you explicitly set ``release`` to + ``!RELEASE_FROM_DATE_RESPIN``, it will be replaced with a value + generated as described in :ref:`automatic versioning `. + + If you explicitly set ``version`` to + ``!VERSION_FROM_VERSION``, it will be replaced with a value + generated as described in :ref:`automatic versioning `. + Please don't set ``install_tree``. This gets automatically set by *pungi* based on current variant. You can use ``install_tree_from`` key to use install tree from another variant. diff --git a/pungi/phases/base.py b/pungi/phases/base.py index 42fc2613..9b0600a8 100644 --- a/pungi/phases/base.py +++ b/pungi/phases/base.py @@ -150,7 +150,11 @@ class ImageConfigMixin(object): Get version from configuration hierarchy or fall back to release version. """ - return self.get_config(cfg, 'version') or self.compose.image_version + return ( + util.version_generator(self.compose, self.get_config(cfg, "version")) + or self.get_config(cfg, "version") + or self.compose.image_version + ) def get_release(self, cfg): """ diff --git a/pungi/util.py b/pungi/util.py index 8bb33ebe..78a9c9be 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -797,10 +797,14 @@ def version_generator(compose, gen): return '%s.%s' % (compose.image_version, compose.image_release) elif gen == '!RELEASE_FROM_LABEL_DATE_TYPE_RESPIN': return compose.image_release + elif gen == '!RELEASE_FROM_DATE_RESPIN': + return '%s.%s' % (compose.compose_date, compose.compose_respin) elif gen == '!VERSION_FROM_VERSION_DATE_RESPIN': return '%s.%s.%s' % (compose.ci_base.release.version, compose.compose_date, compose.compose_respin) + elif gen == '!VERSION_FROM_VERSION': + return '%s' % (compose.ci_base.release.version) elif gen and gen[0] == '!': raise RuntimeError("Unknown version generator '%s'" % gen) return gen diff --git a/tests/test_util.py b/tests/test_util.py index 3fa34804..739ea9e1 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -655,6 +655,18 @@ class TestVersionGenerator(unittest.TestCase): self.assertEqual(util.version_generator(self.compose, '!VERSION_FROM_VERSION_DATE_RESPIN'), '8.20160101.0') + def test_release_from_date_respin(self): + self.assertEqual( + util.version_generator(self.compose, "!RELEASE_FROM_DATE_RESPIN"), + "20160101.0", + ) + + def test_version_from_version(self): + self.assertEqual( + util.version_generator(self.compose, "!VERSION_FROM_VERSION"), + "8", + ) + class TestTZOffset(unittest.TestCase): @mock.patch('time.daylight', new=False)