Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:tulip
salt
mark-salt-3006-as-released-586.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File mark-salt-3006-as-released-586.patch of Package salt
From c1408333364ac25ff5d316afa9674f7687217b0c Mon Sep 17 00:00:00 2001 From: Dominik Gedon <dgedon@suse.de> Date: Thu, 3 Aug 2023 11:08:21 +0200 Subject: [PATCH] Mark Salt 3006 as released (#586) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mark Salt 3006 as released Without this, commands like ``` salt '*' salt_version.equal 'Sulfur' ``` will not work properly and return False although Salt 3006 is used. Signed-off-by: Dominik Gedon <dominik.gedon@suse.com> * Fix detection of Salt codename by salt_version module * Fix mess with version detection bad version definition * Add some new and fix unit tests * Fix SaltStackVersion string for new versions format * Do not crash when passing numbers to 'salt_version.get_release_number' * Fix salt_version execution module documentation --------- Signed-off-by: Dominik Gedon <dominik.gedon@suse.com> Co-authored-by: Pablo Suárez Hernández <psuarezhernandez@suse.com> --- salt/modules/salt_version.py | 8 +- salt/version.py | 218 +++++++++--------- .../pytests/unit/modules/test_salt_version.py | 55 ++++- tests/pytests/unit/test_version.py | 10 +- 4 files changed, 176 insertions(+), 115 deletions(-) diff --git a/salt/modules/salt_version.py b/salt/modules/salt_version.py index 1b5421fee4..99dae5f61a 100644 --- a/salt/modules/salt_version.py +++ b/salt/modules/salt_version.py @@ -20,7 +20,7 @@ A simple example might be something like the following: .. code-block:: jinja {# a boolean check #} - {% set option_deprecated = salt['salt_version.less_than']("3001") %} + {% set option_deprecated = salt['salt_version.less_than']("Sodium") %} {% if option_deprecated %} <use old syntax> @@ -35,6 +35,7 @@ import logging import salt.utils.versions import salt.version +from salt.exceptions import CommandExecutionError log = logging.getLogger(__name__) @@ -51,7 +52,7 @@ def __virtual__(): def get_release_number(name): """ Returns the release number of a given release code name in a - ``MAJOR.PATCH`` format. + ``MAJOR.PATCH`` format (for Salt versions < 3000) or ``MAJOR`` for newer Salt versions. If the release name has not been given an assigned release number, the function returns a string. If the release cannot be found, it returns @@ -66,6 +67,9 @@ def get_release_number(name): salt '*' salt_version.get_release_number 'Oxygen' """ + if not isinstance(name, str): + raise CommandExecutionError("'name' argument must be a string") + name = name.lower() version_map = salt.version.SaltStackVersion.LNAMES version = version_map.get(name) diff --git a/salt/version.py b/salt/version.py index 67719bd020..44372830b2 100644 --- a/salt/version.py +++ b/salt/version.py @@ -77,109 +77,109 @@ class SaltVersionsInfo(type): ALUMINIUM = SaltVersion("Aluminium" , info=3003, released=True) SILICON = SaltVersion("Silicon" , info=3004, released=True) PHOSPHORUS = SaltVersion("Phosphorus" , info=3005, released=True) - SULFUR = SaltVersion("Sulfur" , info=(3006, 0)) - CHLORINE = SaltVersion("Chlorine" , info=(3007, 0)) - ARGON = SaltVersion("Argon" , info=(3008, 0)) - POTASSIUM = SaltVersion("Potassium" , info=(3009, 0)) - CALCIUM = SaltVersion("Calcium" , info=(3010, 0)) - SCANDIUM = SaltVersion("Scandium" , info=(3011, 0)) - TITANIUM = SaltVersion("Titanium" , info=(3012, 0)) - VANADIUM = SaltVersion("Vanadium" , info=(3013, 0)) - CHROMIUM = SaltVersion("Chromium" , info=(3014, 0)) - MANGANESE = SaltVersion("Manganese" , info=(3015, 0)) - IRON = SaltVersion("Iron" , info=(3016, 0)) - COBALT = SaltVersion("Cobalt" , info=(3017, 0)) - NICKEL = SaltVersion("Nickel" , info=(3018, 0)) - COPPER = SaltVersion("Copper" , info=(3019, 0)) - ZINC = SaltVersion("Zinc" , info=(3020, 0)) - GALLIUM = SaltVersion("Gallium" , info=(3021, 0)) - GERMANIUM = SaltVersion("Germanium" , info=(3022, 0)) - ARSENIC = SaltVersion("Arsenic" , info=(3023, 0)) - SELENIUM = SaltVersion("Selenium" , info=(3024, 0)) - BROMINE = SaltVersion("Bromine" , info=(3025, 0)) - KRYPTON = SaltVersion("Krypton" , info=(3026, 0)) - RUBIDIUM = SaltVersion("Rubidium" , info=(3027, 0)) - STRONTIUM = SaltVersion("Strontium" , info=(3028, 0)) - YTTRIUM = SaltVersion("Yttrium" , info=(3029, 0)) - ZIRCONIUM = SaltVersion("Zirconium" , info=(3030, 0)) - NIOBIUM = SaltVersion("Niobium" , info=(3031, 0)) - MOLYBDENUM = SaltVersion("Molybdenum" , info=(3032, 0)) - TECHNETIUM = SaltVersion("Technetium" , info=(3033, 0)) - RUTHENIUM = SaltVersion("Ruthenium" , info=(3034, 0)) - RHODIUM = SaltVersion("Rhodium" , info=(3035, 0)) - PALLADIUM = SaltVersion("Palladium" , info=(3036, 0)) - SILVER = SaltVersion("Silver" , info=(3037, 0)) - CADMIUM = SaltVersion("Cadmium" , info=(3038, 0)) - INDIUM = SaltVersion("Indium" , info=(3039, 0)) - TIN = SaltVersion("Tin" , info=(3040, 0)) - ANTIMONY = SaltVersion("Antimony" , info=(3041, 0)) - TELLURIUM = SaltVersion("Tellurium" , info=(3042, 0)) - IODINE = SaltVersion("Iodine" , info=(3043, 0)) - XENON = SaltVersion("Xenon" , info=(3044, 0)) - CESIUM = SaltVersion("Cesium" , info=(3045, 0)) - BARIUM = SaltVersion("Barium" , info=(3046, 0)) - LANTHANUM = SaltVersion("Lanthanum" , info=(3047, 0)) - CERIUM = SaltVersion("Cerium" , info=(3048, 0)) - PRASEODYMIUM = SaltVersion("Praseodymium" , info=(3049, 0)) - NEODYMIUM = SaltVersion("Neodymium" , info=(3050, 0)) - PROMETHIUM = SaltVersion("Promethium" , info=(3051, 0)) - SAMARIUM = SaltVersion("Samarium" , info=(3052, 0)) - EUROPIUM = SaltVersion("Europium" , info=(3053, 0)) - GADOLINIUM = SaltVersion("Gadolinium" , info=(3054, 0)) - TERBIUM = SaltVersion("Terbium" , info=(3055, 0)) - DYSPROSIUM = SaltVersion("Dysprosium" , info=(3056, 0)) - HOLMIUM = SaltVersion("Holmium" , info=(3057, 0)) - ERBIUM = SaltVersion("Erbium" , info=(3058, 0)) - THULIUM = SaltVersion("Thulium" , info=(3059, 0)) - YTTERBIUM = SaltVersion("Ytterbium" , info=(3060, 0)) - LUTETIUM = SaltVersion("Lutetium" , info=(3061, 0)) - HAFNIUM = SaltVersion("Hafnium" , info=(3062, 0)) - TANTALUM = SaltVersion("Tantalum" , info=(3063, 0)) - TUNGSTEN = SaltVersion("Tungsten" , info=(3064, 0)) - RHENIUM = SaltVersion("Rhenium" , info=(3065, 0)) - OSMIUM = SaltVersion("Osmium" , info=(3066, 0)) - IRIDIUM = SaltVersion("Iridium" , info=(3067, 0)) - PLATINUM = SaltVersion("Platinum" , info=(3068, 0)) - GOLD = SaltVersion("Gold" , info=(3069, 0)) - MERCURY = SaltVersion("Mercury" , info=(3070, 0)) - THALLIUM = SaltVersion("Thallium" , info=(3071, 0)) - LEAD = SaltVersion("Lead" , info=(3072, 0)) - BISMUTH = SaltVersion("Bismuth" , info=(3073, 0)) - POLONIUM = SaltVersion("Polonium" , info=(3074, 0)) - ASTATINE = SaltVersion("Astatine" , info=(3075, 0)) - RADON = SaltVersion("Radon" , info=(3076, 0)) - FRANCIUM = SaltVersion("Francium" , info=(3077, 0)) - RADIUM = SaltVersion("Radium" , info=(3078, 0)) - ACTINIUM = SaltVersion("Actinium" , info=(3079, 0)) - THORIUM = SaltVersion("Thorium" , info=(3080, 0)) - PROTACTINIUM = SaltVersion("Protactinium" , info=(3081, 0)) - URANIUM = SaltVersion("Uranium" , info=(3082, 0)) - NEPTUNIUM = SaltVersion("Neptunium" , info=(3083, 0)) - PLUTONIUM = SaltVersion("Plutonium" , info=(3084, 0)) - AMERICIUM = SaltVersion("Americium" , info=(3085, 0)) - CURIUM = SaltVersion("Curium" , info=(3086, 0)) - BERKELIUM = SaltVersion("Berkelium" , info=(3087, 0)) - CALIFORNIUM = SaltVersion("Californium" , info=(3088, 0)) - EINSTEINIUM = SaltVersion("Einsteinium" , info=(3089, 0)) - FERMIUM = SaltVersion("Fermium" , info=(3090, 0)) - MENDELEVIUM = SaltVersion("Mendelevium" , info=(3091, 0)) - NOBELIUM = SaltVersion("Nobelium" , info=(3092, 0)) - LAWRENCIUM = SaltVersion("Lawrencium" , info=(3093, 0)) - RUTHERFORDIUM = SaltVersion("Rutherfordium", info=(3094, 0)) - DUBNIUM = SaltVersion("Dubnium" , info=(3095, 0)) - SEABORGIUM = SaltVersion("Seaborgium" , info=(3096, 0)) - BOHRIUM = SaltVersion("Bohrium" , info=(3097, 0)) - HASSIUM = SaltVersion("Hassium" , info=(3098, 0)) - MEITNERIUM = SaltVersion("Meitnerium" , info=(3099, 0)) - DARMSTADTIUM = SaltVersion("Darmstadtium" , info=(3100, 0)) - ROENTGENIUM = SaltVersion("Roentgenium" , info=(3101, 0)) - COPERNICIUM = SaltVersion("Copernicium" , info=(3102, 0)) - NIHONIUM = SaltVersion("Nihonium" , info=(3103, 0)) - FLEROVIUM = SaltVersion("Flerovium" , info=(3104, 0)) - MOSCOVIUM = SaltVersion("Moscovium" , info=(3105, 0)) - LIVERMORIUM = SaltVersion("Livermorium" , info=(3106, 0)) - TENNESSINE = SaltVersion("Tennessine" , info=(3107, 0)) - OGANESSON = SaltVersion("Oganesson" , info=(3108, 0)) + SULFUR = SaltVersion("Sulfur" , info=3006, released=True) + CHLORINE = SaltVersion("Chlorine" , info=3007) + ARGON = SaltVersion("Argon" , info=3008) + POTASSIUM = SaltVersion("Potassium" , info=3009) + CALCIUM = SaltVersion("Calcium" , info=3010) + SCANDIUM = SaltVersion("Scandium" , info=3011) + TITANIUM = SaltVersion("Titanium" , info=3012) + VANADIUM = SaltVersion("Vanadium" , info=3013) + CHROMIUM = SaltVersion("Chromium" , info=3014) + MANGANESE = SaltVersion("Manganese" , info=3015) + IRON = SaltVersion("Iron" , info=3016) + COBALT = SaltVersion("Cobalt" , info=3017) + NICKEL = SaltVersion("Nickel" , info=3018) + COPPER = SaltVersion("Copper" , info=3019) + ZINC = SaltVersion("Zinc" , info=3020) + GALLIUM = SaltVersion("Gallium" , info=3021) + GERMANIUM = SaltVersion("Germanium" , info=3022) + ARSENIC = SaltVersion("Arsenic" , info=3023) + SELENIUM = SaltVersion("Selenium" , info=3024) + BROMINE = SaltVersion("Bromine" , info=3025) + KRYPTON = SaltVersion("Krypton" , info=3026) + RUBIDIUM = SaltVersion("Rubidium" , info=3027) + STRONTIUM = SaltVersion("Strontium" , info=3028) + YTTRIUM = SaltVersion("Yttrium" , info=3029) + ZIRCONIUM = SaltVersion("Zirconium" , info=3030) + NIOBIUM = SaltVersion("Niobium" , info=3031) + MOLYBDENUM = SaltVersion("Molybdenum" , info=3032) + TECHNETIUM = SaltVersion("Technetium" , info=3033) + RUTHENIUM = SaltVersion("Ruthenium" , info=3034) + RHODIUM = SaltVersion("Rhodium" , info=3035) + PALLADIUM = SaltVersion("Palladium" , info=3036) + SILVER = SaltVersion("Silver" , info=3037) + CADMIUM = SaltVersion("Cadmium" , info=3038) + INDIUM = SaltVersion("Indium" , info=3039) + TIN = SaltVersion("Tin" , info=3040) + ANTIMONY = SaltVersion("Antimony" , info=3041) + TELLURIUM = SaltVersion("Tellurium" , info=3042) + IODINE = SaltVersion("Iodine" , info=3043) + XENON = SaltVersion("Xenon" , info=3044) + CESIUM = SaltVersion("Cesium" , info=3045) + BARIUM = SaltVersion("Barium" , info=3046) + LANTHANUM = SaltVersion("Lanthanum" , info=3047) + CERIUM = SaltVersion("Cerium" , info=3048) + PRASEODYMIUM = SaltVersion("Praseodymium" , info=3049) + NEODYMIUM = SaltVersion("Neodymium" , info=3050) + PROMETHIUM = SaltVersion("Promethium" , info=3051) + SAMARIUM = SaltVersion("Samarium" , info=3052) + EUROPIUM = SaltVersion("Europium" , info=3053) + GADOLINIUM = SaltVersion("Gadolinium" , info=3054) + TERBIUM = SaltVersion("Terbium" , info=3055) + DYSPROSIUM = SaltVersion("Dysprosium" , info=3056) + HOLMIUM = SaltVersion("Holmium" , info=3057) + ERBIUM = SaltVersion("Erbium" , info=3058) + THULIUM = SaltVersion("Thulium" , info=3059) + YTTERBIUM = SaltVersion("Ytterbium" , info=3060) + LUTETIUM = SaltVersion("Lutetium" , info=3061) + HAFNIUM = SaltVersion("Hafnium" , info=3062) + TANTALUM = SaltVersion("Tantalum" , info=3063) + TUNGSTEN = SaltVersion("Tungsten" , info=3064) + RHENIUM = SaltVersion("Rhenium" , info=3065) + OSMIUM = SaltVersion("Osmium" , info=3066) + IRIDIUM = SaltVersion("Iridium" , info=3067) + PLATINUM = SaltVersion("Platinum" , info=3068) + GOLD = SaltVersion("Gold" , info=3069) + MERCURY = SaltVersion("Mercury" , info=3070) + THALLIUM = SaltVersion("Thallium" , info=3071) + LEAD = SaltVersion("Lead" , info=3072) + BISMUTH = SaltVersion("Bismuth" , info=3073) + POLONIUM = SaltVersion("Polonium" , info=3074) + ASTATINE = SaltVersion("Astatine" , info=3075) + RADON = SaltVersion("Radon" , info=3076) + FRANCIUM = SaltVersion("Francium" , info=3077) + RADIUM = SaltVersion("Radium" , info=3078) + ACTINIUM = SaltVersion("Actinium" , info=3079) + THORIUM = SaltVersion("Thorium" , info=3080) + PROTACTINIUM = SaltVersion("Protactinium" , info=3081) + URANIUM = SaltVersion("Uranium" , info=3082) + NEPTUNIUM = SaltVersion("Neptunium" , info=3083) + PLUTONIUM = SaltVersion("Plutonium" , info=3084) + AMERICIUM = SaltVersion("Americium" , info=3085) + CURIUM = SaltVersion("Curium" , info=3086) + BERKELIUM = SaltVersion("Berkelium" , info=3087) + CALIFORNIUM = SaltVersion("Californium" , info=3088) + EINSTEINIUM = SaltVersion("Einsteinium" , info=3089) + FERMIUM = SaltVersion("Fermium" , info=3090) + MENDELEVIUM = SaltVersion("Mendelevium" , info=3091) + NOBELIUM = SaltVersion("Nobelium" , info=3092) + LAWRENCIUM = SaltVersion("Lawrencium" , info=3093) + RUTHERFORDIUM = SaltVersion("Rutherfordium", info=3094) + DUBNIUM = SaltVersion("Dubnium" , info=3095) + SEABORGIUM = SaltVersion("Seaborgium" , info=3096) + BOHRIUM = SaltVersion("Bohrium" , info=3097) + HASSIUM = SaltVersion("Hassium" , info=3098) + MEITNERIUM = SaltVersion("Meitnerium" , info=3099) + DARMSTADTIUM = SaltVersion("Darmstadtium" , info=3100) + ROENTGENIUM = SaltVersion("Roentgenium" , info=3101) + COPERNICIUM = SaltVersion("Copernicium" , info=3102) + NIHONIUM = SaltVersion("Nihonium" , info=3103) + FLEROVIUM = SaltVersion("Flerovium" , info=3104) + MOSCOVIUM = SaltVersion("Moscovium" , info=3105) + LIVERMORIUM = SaltVersion("Livermorium" , info=3106) + TENNESSINE = SaltVersion("Tennessine" , info=3107) + OGANESSON = SaltVersion("Oganesson" , info=3108) # <---- Please refrain from fixing whitespace ----------------------------------- # The idea is to keep this readable. # ------------------------------------------------------------------------------- @@ -323,9 +323,7 @@ class SaltStackVersion: self.mbugfix = mbugfix self.pre_type = pre_type self.pre_num = pre_num - if self.can_have_dot_zero(major): - vnames_key = (major, 0) - elif self.new_version(major): + if self.new_version(major): vnames_key = (major,) else: vnames_key = (major, minor) @@ -476,8 +474,12 @@ class SaltStackVersion: version_string = self.string if self.sse: version_string += " Enterprise" - if (self.major, self.minor) in self.RMATCH: - version_string += " ({})".format(self.RMATCH[(self.major, self.minor)]) + if self.new_version(self.major): + rmatch_key = (self.major,) + else: + rmatch_key = (self.major, self.minor) + if rmatch_key in self.RMATCH: + version_string += " ({})".format(self.RMATCH[rmatch_key]) return version_string @property diff --git a/tests/pytests/unit/modules/test_salt_version.py b/tests/pytests/unit/modules/test_salt_version.py index 6d734f6a76..4b7a7cd073 100644 --- a/tests/pytests/unit/modules/test_salt_version.py +++ b/tests/pytests/unit/modules/test_salt_version.py @@ -2,8 +2,11 @@ Unit tests for salt/modules/salt_version.py """ +import pytest + import salt.modules.salt_version as salt_version import salt.version +from salt.exceptions import CommandExecutionError from tests.support.mock import MagicMock, patch @@ -21,7 +24,7 @@ def test_mocked_objects(): for k, v in salt.version.SaltStackVersion.LNAMES.items(): assert k == k.lower() assert isinstance(v, tuple) - if sv.new_version(major=v[0]) and not sv.can_have_dot_zero(major=v[0]): + if sv.new_version(major=v[0]): assert len(v) == 1 else: assert len(v) == 2 @@ -64,6 +67,13 @@ def test_get_release_number_success_new_version(): assert salt_version.get_release_number("Neon") == "3000" +def test_get_release_number_success_new_version_with_dot(): + """ + Test that a version is returned for new versioning (3006) + """ + assert salt_version.get_release_number("Sulfur") == "3006" + + def test_equal_success(): """ Test that the current version is equal to the codename @@ -83,6 +93,16 @@ def test_equal_success_new_version(): assert salt_version.equal("foo") is True +def test_equal_success_new_version_with_dot(): + """ + Test that the current version is equal to the codename + while using the new versioning + """ + with patch("salt.version.SaltStackVersion", MagicMock(return_value="3006.1")): + with patch("salt.version.SaltStackVersion.LNAMES", {"foo": (3006,)}): + assert salt_version.equal("foo") is True + + def test_equal_older_codename(): """ Test that when an older codename is passed in, the function returns False. @@ -142,6 +162,17 @@ def test_greater_than_success_new_version(): assert salt_version.greater_than("Nitrogen") is True +def test_greater_than_success_new_version_with_dot(): + """ + Test that the current version is newer than the codename + """ + with patch( + "salt.modules.salt_version.get_release_number", MagicMock(return_value="3000") + ): + with patch("salt.version.SaltStackVersion", MagicMock(return_value="3006.0")): + assert salt_version.greater_than("Neon") is True + + def test_greater_than_with_equal_codename(): """ Test that when an equal codename is passed in, the function returns False. @@ -200,6 +231,28 @@ def test_less_than_success_new_version(): assert salt_version.less_than("Fluorine") is True +def test_less_than_success_new_version_with_dot(): + """ + Test that when a newer codename is passed in, the function returns True + using new version + """ + with patch("salt.version.SaltStackVersion", MagicMock(return_value="2018.3.2")): + with patch( + "salt.modules.salt_version.get_release_number", + MagicMock(return_value="3006"), + ): + assert salt_version.less_than("Fluorine") is True + + +def test_less_than_do_not_crash_when_input_is_a_number(): + """ + Test that less_than do not crash when unexpected inputs + """ + with patch("salt.version.SaltStackVersion", MagicMock(return_value="2018.3.2")): + with pytest.raises(CommandExecutionError): + salt_version.less_than(1234) + + def test_less_than_with_equal_codename(): """ Test that when an equal codename is passed in, the function returns False. diff --git a/tests/pytests/unit/test_version.py b/tests/pytests/unit/test_version.py index 73befea4cf..1cb94c619c 100644 --- a/tests/pytests/unit/test_version.py +++ b/tests/pytests/unit/test_version.py @@ -187,7 +187,7 @@ def test_string_new_version_minor(): ver = SaltStackVersion(major=maj_ver, minor=min_ver) assert ver.minor == min_ver assert not ver.bugfix - assert ver.string == "{}.{}".format(maj_ver, min_ver) + assert ver.string == f"{maj_ver}.{min_ver}" def test_string_new_version_minor_as_string(): @@ -201,13 +201,13 @@ def test_string_new_version_minor_as_string(): ver = SaltStackVersion(major=maj_ver, minor=min_ver) assert ver.minor == int(min_ver) assert not ver.bugfix - assert ver.string == "{}.{}".format(maj_ver, min_ver) + assert ver.string == f"{maj_ver}.{min_ver}" # This only seems to happen on a cloned repo without its tags maj_ver = "3000" min_ver = "" ver = SaltStackVersion(major=maj_ver, minor=min_ver) - assert ver.minor is None, "{!r} is not {!r}".format(ver.minor, min_ver) + assert ver.minor is None, f"{ver.minor!r} is not {min_ver!r}" assert not ver.bugfix assert ver.string == maj_ver @@ -222,7 +222,7 @@ def test_string_old_version(): min_ver = "2" ver = SaltStackVersion(major=maj_ver, minor=min_ver) assert ver.bugfix == 0 - assert ver.string == "{}.{}.0".format(maj_ver, min_ver) + assert ver.string == f"{maj_ver}.{min_ver}.0" @pytest.mark.parametrize( @@ -537,6 +537,8 @@ def test_versions_report_no_extensions_available(): ("3000.1", "3000.1", "Neon"), ("3005", "3005", "Phosphorus"), ("3006", "3006.0", "Sulfur"), + ("3006.0", "3006.0", "Sulfur"), + ("3006.1", "3006.1", "Sulfur"), ("3015.1", "3015.1", "Manganese"), ("3109.3", "3109.3", None), ], -- 2.41.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor