mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Do not crash when passing numbers to 'salt_version.get_release_number'
This commit is contained in:
parent
8540a3fdd4
commit
3693a0db42
2 changed files with 16 additions and 0 deletions
|
@ -35,6 +35,7 @@ import logging
|
|||
|
||||
import salt.utils.versions
|
||||
import salt.version
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
@ -241,6 +244,15 @@ def test_less_than_success_new_version_with_dot():
|
|||
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.
|
||||
|
|
Loading…
Add table
Reference in a new issue