From 36ec3259cf509ebd331e76ab0390e7475453a8d8 Mon Sep 17 00:00:00 2001 From: mprahl Date: Nov 01 2019 18:36:21 +0000 Subject: Add a configuration to add an optional suffix to the release of the rebuilt NVR This adds the `rebuilt_nvr_release_suffix` configuration which is useful to make the NVR unique in an environment where multiple Freshmaker instances are reacting to the same events and using the same build system. --- diff --git a/docs/configuration.rst b/docs/configuration.rst index 52bcf26..846d675 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -31,3 +31,9 @@ The following is an example of this: }, } + +Other +===== + +* ``rebuilt_nvr_release_suffix`` - a suffix to add to the ``rebuilt_nvr`` + release in addition to the timestamp. This defaults to an empty string. diff --git a/freshmaker/config.py b/freshmaker/config.py index 6244384..e581eaa 100644 --- a/freshmaker/config.py +++ b/freshmaker/config.py @@ -359,6 +359,11 @@ class Config(object): 'the keys "groups" and "users" which have values that are lists. Any roles not ' 'provided as keys, will contain defaut empty values.' }, + 'rebuilt_nvr_release_suffix': { + 'type': str, + 'default': '', + 'desc': 'A suffix to add to the rebuilt_nvr release in addition to the timestamp.', + }, } def __init__(self, conf_section_obj): diff --git a/freshmaker/utils.py b/freshmaker/utils.py index 468d64b..e057454 100644 --- a/freshmaker/utils.py +++ b/freshmaker/utils.py @@ -106,10 +106,10 @@ def get_rebuilt_nvr(artifact_type, nvr): """ rebuilt_nvr = None if artifact_type == ArtifactType.IMAGE.value: - # Set release from XX.YY to XX.$timestamp + # Set release from XX.YY to XX.$timestamp$release_suffix parsed_nvr = koji.parse_NVR(nvr) r_version = parsed_nvr["release"].split(".")[0] - release = str(r_version) + "." + str(int(time.time())) + release = f"{r_version}.{int(time.time())}{conf.rebuilt_nvr_release_suffix}" rebuilt_nvr = "%s-%s-%s" % (parsed_nvr["name"], parsed_nvr["version"], release) diff --git a/tests/test_utils.py b/tests/test_utils.py index eaa0fb2..b052863 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -20,10 +20,26 @@ # # Written by Jan Kaluza -from freshmaker.utils import sorted_by_nvr +from unittest.mock import patch + +import pytest + +from freshmaker import conf +from freshmaker.models import ArtifactType +from freshmaker.utils import get_rebuilt_nvr, sorted_by_nvr from tests import helpers +@pytest.mark.parametrize("rebuilt_nvr_release_suffix", ("", ".dev")) +@patch("freshmaker.utils.time.time", return_value=1572631468.1807485) +def test_get_rebuilt_nvr(mock_time, rebuilt_nvr_release_suffix): + nvr = "python-v3.6-201910221723" + expected = f"{nvr}.1572631468{rebuilt_nvr_release_suffix}" + with patch.object(conf, "rebuilt_nvr_release_suffix", new=rebuilt_nvr_release_suffix): + rebuilt_nvr = get_rebuilt_nvr(ArtifactType.IMAGE.value, nvr) + assert rebuilt_nvr == expected + + class TestSortedByNVR(helpers.FreshmakerTestCase): def test_simple_list(self):