Merge pull request #7603 from s0undt3ch/features/named-salt-versions

Add support for the future Salt named versions
This commit is contained in:
Thomas S Hatch 2013-10-04 04:32:43 -07:00
commit d75ad1fb89
25 changed files with 372 additions and 120 deletions

View File

@ -575,10 +575,10 @@ def minion_config(path,
# Showing a deprecation for 0.17.0 and 0.18.0 should be enough for any
# api calls to be updated in order to stop it's use.
salt.utils.warn_until(
(0, 19),
'Helium',
'The functionality behind the \'check_dns\' keyword argument is '
'no longer required, as such, it became unnecessary and is now '
'deprecated. \'check_dns\' will be removed in salt > 0.18.0'
'deprecated. \'check_dns\' will be removed {version}.'
)
if defaults is None:
defaults = DEFAULT_MINION_OPTS
@ -769,10 +769,10 @@ def apply_minion_config(overrides=None, defaults=None, check_dns=None):
# Showing a deprecation for 0.17.0 and 0.18.0 should be enough for any
# api calls to be updated in order to stop it's use.
salt.utils.warn_until(
(0, 19),
'Helium',
'The functionality behind the \'check_dns\' keyword argument is '
'no longer required, as such, it became unnecessary and is now '
'deprecated. \'check_dns\' will be removed in salt > 0.18.0'
'deprecated. \'check_dns\' will be removed {version}.'
)
if defaults is None:

View File

@ -144,9 +144,9 @@ def latest_version(*names, **kwargs):
if 'repo' in kwargs:
# Remember to kill _get_repo() too when removing this warning.
salt.utils.warn_until(
(0, 18),
'The \'repo\' argument to apt.latest_version is deprecated, and will be '
'removed in 0.18.0. Please use \'fromrepo\' instead.'
'Hydrogen',
'The \'repo\' argument to apt.latest_version is deprecated, and '
'will be removed in {version}. Please use \'fromrepo\' instead.'
)
fromrepo = _get_repo(**kwargs)
kwargs.pop('fromrepo', None)

View File

@ -785,7 +785,7 @@ def script(source,
if isinstance(env, string_types):
salt.utils.warn_until(
(0, 19),
'Helium',
'Passing a salt environment should be done using \'__env__\' not '
'\'env\'.'
)

View File

@ -248,9 +248,9 @@ def install(pkgs=None,
if runas is not None:
# The user is using a deprecated argument, warn!
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'The \'runas\' argument to pip.install is deprecated, and will be '
'removed in 0.18.0. Please use \'user\' instead.'
'removed in {version}. Please use \'user\' instead.'
)
# "There can only be one"
@ -559,9 +559,9 @@ def uninstall(pkgs=None,
if runas is not None:
# The user is using a deprecated argument, warn!
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'The \'runas\' argument to pip.install is deprecated, and will be '
'removed in 0.18.0. Please use \'user\' instead.'
'removed in {version}. Please use \'user\' instead.'
)
# "There can only be one"
@ -683,9 +683,9 @@ def freeze(bin_env=None,
if runas is not None:
# The user is using a deprecated argument, warn!
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'The \'runas\' argument to pip.install is deprecated, and will be '
'removed in 0.18.0. Please use \'user\' instead.'
'removed in {version}. Please use \'user\' instead.'
)
# "There can only be one"
@ -735,9 +735,9 @@ def list_(prefix=None,
if runas is not None:
# The user is using a deprecated argument, warn!
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'The \'runas\' argument to pip.install is deprecated, and will be '
'removed in 0.18.0. Please use \'user\' instead.'
'removed in {version}. Please use \'user\' instead.'
)
# "There can only be one"

View File

@ -90,7 +90,7 @@ def create(path,
if no_site_packages is not None:
# Show a deprecation warning
salt.utils.warn_until(
(0, 19),
'Helium',
'\'no_site_packages\' has been deprecated. Please start using '
'\'system_site_packages=False\' which means exactly the same '
'as \'no_site_packages=True\''

View File

@ -639,11 +639,11 @@ def script(name,
if isinstance(env, string_types):
msg = (
'Passing a salt environment should be done using \'__env__\' not '
'\'env\'. This warning will go away in salt 0.19.0 and this will '
'be the default and expected behaviour. Please update your state '
'files.'
'\'env\'. This warning will go away in salt {version} and this '
'will be the default and expected behaviour. Please update your '
'state files.'
)
salt.utils.warn_until((0, 19), msg)
salt.utils.warn_until('Helium', msg)
ret.setdefault('warnings', []).append(msg)
# Backwards compatibility
__env__ = env

View File

@ -65,7 +65,7 @@ def installed(name, # pylint: disable=C0103
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -139,7 +139,7 @@ def removed(name, ruby=None, runas=None, user=None):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -123,7 +123,7 @@ def latest(name,
return _fail(ret, '"target" option is required')
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -347,7 +347,7 @@ def present(name, bare=True, runas=None, user=None, force=False):
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -80,7 +80,7 @@ def latest(name,
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -61,7 +61,7 @@ def installed(name,
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -156,7 +156,7 @@ def removed(name,
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -230,7 +230,7 @@ def bootstrap(name,
'''
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -149,10 +149,10 @@ def installed(name,
if repo is not None:
msg = ('The \'repo\' argument to pip.installed is deprecated and will '
'be removed in 0.18.0. Please use \'name\' instead. The '
'be removed in {version}. Please use \'name\' instead. The '
'current value for name, {0!r} will be replaced by the value '
'of repo, {1!r}'.format(name, repo))
salt.utils.warn_until((0, 18), msg)
salt.utils.warn_until('Hydrogen', msg)
ret.setdefault('warnings', []).append(msg)
name = repo
@ -210,9 +210,9 @@ def installed(name,
# The user is using a deprecated argument, warn!
msg = (
'The \'runas\' argument to pip.installed is deprecated, and will '
'be removed in 0.18.0. Please use \'user\' instead.'
'be removed in {version}. Please use \'user\' instead.'
)
salt.utils.warn_until((0, 18), msg)
salt.utils.warn_until('Hydrogen', msg)
ret.setdefault('warnings', []).append(msg)
# "There can only be one"
@ -399,9 +399,9 @@ def removed(name,
# The user is using a deprecated argument, warn!
msg = (
'The \'runas\' argument to pip.installed is deprecated, and will '
'be removed in 0.18.0. Please use \'user\' instead.'
'be removed in {version}. Please use \'user\' instead.'
)
salt.utils.warn_until((0, 18), msg)
salt.utils.warn_until('Hydrogen', msg)
ret.setdefault('warnings', []).append(msg)
# "There can only be one"

View File

@ -73,7 +73,7 @@ def present(name,
'comment': 'Database {0} is already present'.format(name)}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -176,7 +176,7 @@ def absent(name, runas=None, user=None):
'result': True,
'comment': ''}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -75,7 +75,7 @@ def present(name,
'comment': 'Group {0} is already present'.format(name)}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -148,7 +148,7 @@ def absent(name, runas=None, user=None):
'comment': ''}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -75,7 +75,7 @@ def present(name,
'comment': 'User {0} is already present'.format(name)}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -148,7 +148,7 @@ def absent(name, runas=None, user=None):
'comment': ''}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -62,7 +62,7 @@ def present(name,
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please start deprecating \'runas\' at this stage. Ping s0undt3ch for '
'additional information or see #6961.',
_dont_call_warnings=True

View File

@ -121,7 +121,7 @@ def installed(name, default=False, runas=None, user=None):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -210,7 +210,7 @@ def absent(name, runas=None, user=None):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -193,7 +193,7 @@ def installed(name, default=False, runas=None, user=None):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -254,7 +254,7 @@ def gemset_present(name, ruby='default', runas=None, user=None):
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -79,7 +79,7 @@ def running(name,
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
@ -267,7 +267,7 @@ def dead(name,
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
salt.utils.warn_until(
(0, 18),
'Hydrogen',
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True

View File

@ -10,6 +10,9 @@ import logging
import os
import salt.utils
# Import salt libs
import salt.version
log = logging.getLogger(__name__)
@ -64,9 +67,11 @@ def managed(name,
return ret
salt.utils.warn_until(
(0, 18),
'Let\'s support \'runas\' until salt 0.19.0 is out, after which '
'it will stop being supported',
'Hydrogen',
'Let\'s support \'runas\' until salt {0} is out, after which it will'
'stop being supported'.format(
salt.version.SaltStackVersion.from_name('Helium').formatted_version
),
_dont_call_warnings=True
)
if runas:

View File

@ -762,7 +762,7 @@ def format_call(fun,
# We'll be showing errors to the users until salt 0.20 comes out, after
# which, errors will be raised instead.
warn_until(
(0, 20),
'Lithium',
'It\'s time to start raising `SaltInvocationError` instead of '
'returning warnings',
# Let's not show the deprecation warning on the console, there's no
@ -1426,7 +1426,7 @@ def date_format(date=None, format="%Y-%m-%d"):
return date_cast(date).strftime(format)
def warn_until(version_info,
def warn_until(version,
message,
category=DeprecationWarning,
stacklevel=None,
@ -1434,12 +1434,13 @@ def warn_until(version_info,
_dont_call_warnings=False):
'''
Helper function to raise a warning, by default, a ``DeprecationWarning``,
until the provided ``version_info``, after which, a ``RuntimeError`` will
until the provided ``version``, after which, a ``RuntimeError`` will
be raised to remind the developers to remove the warning because the
target version has been reached.
:param version_info: The version info after which the warning becomes a
``RuntimeError``. For example ``(0, 17)``.
:param version: The version info or name after which the warning becomes a
``RuntimeError``. For example ``(0, 17)`` or ``Hydrogen``
or an instance of :class:`salt.version.SaltStackVersion`.
:param message: The warning message to be displayed.
:param category: The warning class to be thrown, by default
``DeprecationWarning``
@ -1453,10 +1454,17 @@ def warn_until(version_info,
issued. When we're only after the salt version
checks to raise a ``RuntimeError``.
'''
if not isinstance(version_info, tuple):
if not isinstance(version, (tuple,
salt._compat.string_types,
salt.version.SaltStackVersion)):
raise RuntimeError(
'The \'version_info\' argument should be passed as a tuple.'
'The \'version\' argument should be passed as a tuple, string or '
'an instance of \'salt.version.SaltStackVersion\'.'
)
elif isinstance(version, tuple):
version = salt.version.SaltStackVersion(*version)
elif isinstance(version, salt._compat.string_types):
version = salt.version.SaltStackVersion.from_name(version)
if stacklevel is None:
# Attribute the warning to the calling function, not to warn_until()
@ -1465,7 +1473,9 @@ def warn_until(version_info,
if _version_info_ is None:
_version_info_ = salt.version.__version_info__
if _version_info_ >= version_info:
_version_ = salt.version.SaltStackVersion(*_version_info_)
if _version_ >= version:
caller = inspect.getframeinfo(sys._getframe(stacklevel - 1))
raise RuntimeError(
'The warning triggered on filename {filename!r}, line number '
@ -1474,21 +1484,25 @@ def warn_until(version_info,
'{salt_version!r}. Please remove the warning.'.format(
filename=caller.filename,
lineno=caller.lineno,
until_version='.'.join(map(str, version_info)),
salt_version='.'.join(map(str, _version_info_))
until_version=version.formatted_version,
salt_version=_version_.formatted_version
),
)
if _dont_call_warnings is False:
warnings.warn(message, category, stacklevel=stacklevel)
warnings.warn(
message.format(version=version.formatted_version),
category,
stacklevel=stacklevel
)
def kwargs_warn_until(kwargs,
version_info,
category=DeprecationWarning,
stacklevel=None,
_version_info_=None,
_dont_call_warnings=False):
version,
category=DeprecationWarning,
stacklevel=None,
_version_info_=None,
_dont_call_warnings=False):
'''
Helper function to raise a warning (by default, a ``DeprecationWarning``)
when unhandled keyword arguments are passed to function, until the
@ -1502,8 +1516,9 @@ def kwargs_warn_until(kwargs,
for the modern strategy for deprecating a function parameter.
:param kwargs: The caller's ``**kwargs`` argument value (a ``dict``).
:param version_info: The version info after which the warning becomes a
``RuntimeError``. For example ``(0, 17)``.
:param version: The version info or name after which the warning becomes a
``RuntimeError``. For example ``(0, 17)`` or ``Hydrogen``
or an instance of :class:`salt.version.SaltStackVersion`.
:param category: The warning class to be thrown, by default
``DeprecationWarning``
:param stacklevel: There should be no need to set the value of
@ -1516,10 +1531,17 @@ def kwargs_warn_until(kwargs,
issued. When we're only after the salt version
checks to raise a ``RuntimeError``.
'''
if not isinstance(version_info, tuple):
if not isinstance(version, (tuple,
salt._compat.string_types,
salt.version.SaltStackVersion)):
raise RuntimeError(
'The \'version_info\' argument should be passed as a tuple.'
'The \'version\' argument should be passed as a tuple, string or '
'an instance of \'salt.version.SaltStackVersion\'.'
)
elif isinstance(version, tuple):
version = salt.version.SaltStackVersion(*version)
elif isinstance(version, salt._compat.string_types):
version = salt.version.SaltStackVersion.from_name(version)
if stacklevel is None:
# Attribute the warning to the calling function,
@ -1529,16 +1551,19 @@ def kwargs_warn_until(kwargs,
if _version_info_ is None:
_version_info_ = salt.version.__version_info__
if kwargs or _version_info_ >= version_info:
removal_version = '.'.join(str(component) for component in version_info)
arg_names = ', '.join('\'{0}\''.format(key) for key in kwargs)
warn_until(version_info,
message='The following parameter(s) have been deprecated and '
'will be removed in {0}: {1}.'.format(removal_version, arg_names),
category=category,
stacklevel=stacklevel,
_version_info_=_version_info_,
_dont_call_warnings=_dont_call_warnings
_version_ = salt.version.SaltStackVersion(*_version_info_)
if kwargs or _version_.info >= version.info:
arg_names = ', '.join('{0!r}'.format(key) for key in kwargs)
warn_until(
version,
message='The following parameter(s) have been deprecated and '
'will be removed in {0!r}: {1}.'.format(version.string,
arg_names),
category=category,
stacklevel=stacklevel,
_version_info_=_version_.info,
_dont_call_warnings=_dont_call_warnings
)
@ -1630,10 +1655,10 @@ def memoize(func):
Deprecation warning wrapper since memoize is now on salt.utils.decorators
'''
warn_until(
(0, 19),
'Helium',
'The \'memoize\' decorator was moved to \'salt.utils.decorators\', '
'please start importing it from there. This warning and wrapper '
'will be removed on salt > 0.19.0.',
'will be removed on salt > {version}.',
stacklevel=3
)

View File

@ -868,7 +868,7 @@ class OutputOptionsWithTextMixIn(OutputOptionsMixIn):
cls, *args, **kwargs
)
utils.warn_until(
(0, 19),
'Helium',
'\'OutputOptionsWithTextMixIn\' has been deprecated. Please '
'start using \'OutputOptionsMixIn\'; your code should not need '
'any further changes.'
@ -1167,7 +1167,11 @@ class SaltKeyOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
def _mixin_setup(self):
# XXX: Remove '--key-logfile' support in 0.18.0
utils.warn_until((0, 18), '', _dont_call_warnings=True)
utils.warn_until(
'Hydrogen',
'Remove \'--key-logfile\' support',
_dont_call_warnings=True
)
self.logging_options_group.add_option(
'--key-logfile',
default=None,
@ -1352,7 +1356,11 @@ class SaltKeyOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
if self.options.key_logfile:
# XXX: Remove '--key-logfile' support in 0.18.0
# In < 0.18.0 error out
utils.warn_until((0, 18), '', _dont_call_warnings=True)
utils.warn_until(
'Hydrogen',
'Remove \'--key-logfile\' support',
_dont_call_warnings=True
)
self.error(
'The \'--key-logfile\' option has been deprecated in favour '
'of \'--log-file\''

View File

@ -31,7 +31,7 @@ class SaltStackVersion(object):
and also supports version comparison.
'''
__slots__ = ('major', 'minor', 'bugfix', 'rc', 'noc', 'sha')
__slots__ = ('name', 'major', 'minor', 'bugfix', 'rc', 'noc', 'sha')
git_describe_regex = re.compile(
r'(?:[^\d]+)?(?P<major>[\d]{1,2})\.(?P<minor>[\d]{1,2})'
@ -39,6 +39,136 @@ class SaltStackVersion(object):
r'(?:(?:.*)-(?P<noc>[\d]+)-(?P<sha>[a-z0-9]{8}))?'
)
# Salt versions after 0.17.0 will be numbered like:
# <2-digit-year>.<month>.<bugfix>
#
# Since the actual version numbers will only be know on release dates, the
# periodic table element names will be what's going to be used to name
# versions and to be able to mention them.
NAMES = {
# Let's keep at least 3 version names uncommented counting from the
# latest release so we can map deprecation warnings to versions.
# ----- Please refrain from fixing PEP-8 E203 ----------------------->
# The idea is keep this readable
# --------------------------------------------------------------------
'Hydrogen' : (sys.maxint - 108, 0, 0, 0),
'Helium' : (sys.maxint - 107, 0, 0, 0),
'Lithium' : (sys.maxint - 106, 0, 0, 0),
#'Beryllium' : (sys.maxint - 105, 0, 0, 0),
#'Boron' : (sys.maxint - 104, 0, 0, 0),
#'Carbon' : (sys.maxint - 103, 0, 0, 0),
#'Nitrogen' : (sys.maxint - 102, 0, 0, 0),
#'Oxygen' : (sys.maxint - 101, 0, 0, 0),
#'Fluorine' : (sys.maxint - 100, 0, 0, 0),
#'Neon' : (sys.maxint - 99 , 0, 0, 0),
#'Sodium' : (sys.maxint - 98 , 0, 0, 0),
#'Magnesium' : (sys.maxint - 97 , 0, 0, 0),
#'Aluminium' : (sys.maxint - 96 , 0, 0, 0),
#'Silicon' : (sys.maxint - 95 , 0, 0, 0),
#'Phosphorus' : (sys.maxint - 94 , 0, 0, 0),
#'Sulfur' : (sys.maxint - 93 , 0, 0, 0),
#'Chlorine' : (sys.maxint - 92 , 0, 0, 0),
#'Argon' : (sys.maxint - 91 , 0, 0, 0),
#'Potassium' : (sys.maxint - 90 , 0, 0, 0),
#'Calcium' : (sys.maxint - 89 , 0, 0, 0),
#'Scandium' : (sys.maxint - 88 , 0, 0, 0),
#'Titanium' : (sys.maxint - 87 , 0, 0, 0),
#'Vanadium' : (sys.maxint - 86 , 0, 0, 0),
#'Chromium' : (sys.maxint - 85 , 0, 0, 0),
#'Manganese' : (sys.maxint - 84 , 0, 0, 0),
#'Iron' : (sys.maxint - 83 , 0, 0, 0),
#'Cobalt' : (sys.maxint - 82 , 0, 0, 0),
#'Nickel' : (sys.maxint - 81 , 0, 0, 0),
#'Copper' : (sys.maxint - 80 , 0, 0, 0),
#'Zinc' : (sys.maxint - 79 , 0, 0, 0),
#'Gallium' : (sys.maxint - 78 , 0, 0, 0),
#'Germanium' : (sys.maxint - 77 , 0, 0, 0),
#'Arsenic' : (sys.maxint - 76 , 0, 0, 0),
#'Selenium' : (sys.maxint - 75 , 0, 0, 0),
#'Bromine' : (sys.maxint - 74 , 0, 0, 0),
#'Krypton' : (sys.maxint - 73 , 0, 0, 0),
#'Rubidium' : (sys.maxint - 72 , 0, 0, 0),
#'Strontium' : (sys.maxint - 71 , 0, 0, 0),
#'Yttrium' : (sys.maxint - 70 , 0, 0, 0),
#'Zirconium' : (sys.maxint - 69 , 0, 0, 0),
#'Niobium' : (sys.maxint - 68 , 0, 0, 0),
#'Molybdenum' : (sys.maxint - 67 , 0, 0, 0),
#'Technetium' : (sys.maxint - 66 , 0, 0, 0),
#'Ruthenium' : (sys.maxint - 65 , 0, 0, 0),
#'Rhodium' : (sys.maxint - 64 , 0, 0, 0),
#'Palladium' : (sys.maxint - 63 , 0, 0, 0),
#'Silver' : (sys.maxint - 62 , 0, 0, 0),
#'Cadmium' : (sys.maxint - 61 , 0, 0, 0),
#'Indium' : (sys.maxint - 60 , 0, 0, 0),
#'Tin' : (sys.maxint - 59 , 0, 0, 0),
#'Antimony' : (sys.maxint - 58 , 0, 0, 0),
#'Tellurium' : (sys.maxint - 57 , 0, 0, 0),
#'Iodine' : (sys.maxint - 56 , 0, 0, 0),
#'Xenon' : (sys.maxint - 55 , 0, 0, 0),
#'Caesium' : (sys.maxint - 54 , 0, 0, 0),
#'Barium' : (sys.maxint - 53 , 0, 0, 0),
#'Lanthanum' : (sys.maxint - 52 , 0, 0, 0),
#'Cerium' : (sys.maxint - 51 , 0, 0, 0),
#'Praseodymium' : (sys.maxint - 50 , 0, 0, 0),
#'Neodymium' : (sys.maxint - 49 , 0, 0, 0),
#'Promethium' : (sys.maxint - 48 , 0, 0, 0),
#'Samarium' : (sys.maxint - 47 , 0, 0, 0),
#'Europium' : (sys.maxint - 46 , 0, 0, 0),
#'Gadolinium' : (sys.maxint - 45 , 0, 0, 0),
#'Terbium' : (sys.maxint - 44 , 0, 0, 0),
#'Dysprosium' : (sys.maxint - 43 , 0, 0, 0),
#'Holmium' : (sys.maxint - 42 , 0, 0, 0),
#'Erbium' : (sys.maxint - 41 , 0, 0, 0),
#'Thulium' : (sys.maxint - 40 , 0, 0, 0),
#'Ytterbium' : (sys.maxint - 39 , 0, 0, 0),
#'Lutetium' : (sys.maxint - 38 , 0, 0, 0),
#'Hafnium' : (sys.maxint - 37 , 0, 0, 0),
#'Tantalum' : (sys.maxint - 36 , 0, 0, 0),
#'Tungsten' : (sys.maxint - 35 , 0, 0, 0),
#'Rhenium' : (sys.maxint - 34 , 0, 0, 0),
#'Osmium' : (sys.maxint - 33 , 0, 0, 0),
#'Iridium' : (sys.maxint - 32 , 0, 0, 0),
#'Platinum' : (sys.maxint - 31 , 0, 0, 0),
#'Gold' : (sys.maxint - 30 , 0, 0, 0),
#'Mercury' : (sys.maxint - 29 , 0, 0, 0),
#'Thallium' : (sys.maxint - 28 , 0, 0, 0),
#'Lead' : (sys.maxint - 27 , 0, 0, 0),
#'Bismuth' : (sys.maxint - 26 , 0, 0, 0),
#'Polonium' : (sys.maxint - 25 , 0, 0, 0),
#'Astatine' : (sys.maxint - 24 , 0, 0, 0),
#'Radon' : (sys.maxint - 23 , 0, 0, 0),
#'Francium' : (sys.maxint - 22 , 0, 0, 0),
#'Radium' : (sys.maxint - 21 , 0, 0, 0),
#'Actinium' : (sys.maxint - 20 , 0, 0, 0),
#'Thorium' : (sys.maxint - 19 , 0, 0, 0),
#'Protactinium' : (sys.maxint - 18 , 0, 0, 0),
#'Uranium' : (sys.maxint - 17 , 0, 0, 0),
#'Neptunium' : (sys.maxint - 16 , 0, 0, 0),
#'Plutonium' : (sys.maxint - 15 , 0, 0, 0),
#'Americium' : (sys.maxint - 14 , 0, 0, 0),
#'Curium' : (sys.maxint - 13 , 0, 0, 0),
#'Berkelium' : (sys.maxint - 12 , 0, 0, 0),
#'Californium' : (sys.maxint - 11 , 0, 0, 0),
#'Einsteinium' : (sys.maxint - 10 , 0, 0, 0),
#'Fermium' : (sys.maxint - 9 , 0, 0, 0),
#'Mendelevium' : (sys.maxint - 8 , 0, 0, 0),
#'Nobelium' : (sys.maxint - 7 , 0, 0, 0),
#'Lawrencium' : (sys.maxint - 6 , 0, 0, 0),
#'Rutherfordium': (sys.maxint - 5 , 0, 0, 0),
#'Dubnium' : (sys.maxint - 4 , 0, 0, 0),
#'Seaborgium' : (sys.maxint - 3 , 0, 0, 0),
#'Bohrium' : (sys.maxint - 2 , 0, 0, 0),
#'Hassium' : (sys.maxint - 1 , 0, 0, 0),
#'Meitnerium' : (sys.maxint - 0 , 0, 0, 0),
# <---- Please refrain from fixing PEP-8 E203 ------------------------
}
LNAMES = dict((k.lower(), v) for (k, v) in NAMES.iteritems())
VNAMES = dict((v, k) for (k, v) in NAMES.iteritems())
def __init__(self, # pylint: disable=C0103
major,
minor,
@ -72,11 +202,14 @@ class SaltStackVersion(object):
self.minor = minor
self.bugfix = bugfix
self.rc = rc # pylint: disable=C0103
self.name = self.VNAMES.get((major, minor, bugfix, rc), None)
self.noc = noc
self.sha = sha
@classmethod
def parse(cls, version_string):
if version_string.lower() in cls.LNAMES:
return cls.from_name(version_string)
match = cls.git_describe_regex.match(version_string)
if not match:
raise ValueError(
@ -84,6 +217,14 @@ class SaltStackVersion(object):
)
return cls(*match.groups())
@classmethod
def from_name(cls, name):
if name.lower() not in cls.LNAMES:
raise ValueError(
'Named version {0!r} is not know'.format(name)
)
return cls(*cls.LNAMES[name.lower()])
@property
def info(self):
return (
@ -135,6 +276,14 @@ class SaltStackVersion(object):
version_string += '-{0}-{1}'.format(self.noc, self.sha)
return version_string
@property
def formatted_version(self):
if self.name and self.major > 10000:
return '{0} (Unreleased)'.format(self.name)
elif self.name:
return '{0} ({1})'.format(self.name, self.string)
return self.string
def __str__(self):
return self.string
@ -166,6 +315,19 @@ class SaltStackVersion(object):
other_noc_info[3] = -1
return cmp(self.noc_info, tuple(other_noc_info))
def __repr__(self):
parts = []
if self.name:
parts.append('name={0!r}'.format(self.name))
parts.extend([
'major={0}'.format(self.major),
'minor={0}'.format(self.minor),
'bugfix={0}'.format(self.bugfix)
])
if self.rc:
parts.append('rc={0}'.format(self.rc))
return '<{0} {1}>'.format(self.__class__.__name__, ' '.join(parts))
# ----- Hardcoded Salt Version Information ---------------------------------->
#

View File

@ -298,7 +298,7 @@ class ConfigTestCase(TestCase):
self.assertEquals(syndic_opts['_minion_conf_file'], syndic_conf_path)
def test_check_dns_deprecation_warning(self):
if salt_version.__version_info__ >= (0, 19):
if salt_version.__version_info__ >= 'Helium':
raise AssertionError(
'Failing this test on purpose! Please delete this test case, '
'the \'check_dns\' keyword argument and the deprecation '

View File

@ -12,31 +12,36 @@
'''
# Import python libs
import sys
import warnings
# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting import TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch
ensure_in_syspath('../../')
# Import salt libs
from salt.utils import warn_until, kwargs_warn_until
from salt.version import SaltStackVersion
@skipIf(NO_MOCK, NO_MOCK_REASON)
class WarnUntilTestCase(TestCase):
@patch('salt.version')
def test_warn_until_warning_raised(self, salt_version_mock):
def test_warn_until_warning_raised(self):
# We *always* want *all* warnings thrown on this module
warnings.filterwarnings('always', '', DeprecationWarning, __name__)
# Define a salt version info
salt_version_mock.__version_info__ = (0, 16)
def raise_warning():
def raise_warning(_version_info_=(0, 16, 0)):
warn_until(
(0, 17), 'Deprecation Message!'
(0, 17), 'Deprecation Message!',
_version_info_=_version_info_
)
def raise_named_version_warning(_version_info_=(0, 16, 0)):
warn_until(
'Hydrogen', 'Deprecation Message!',
_version_info_=_version_info_
)
# raise_warning should show warning until version info is >= (0, 17)
@ -46,23 +51,39 @@ class WarnUntilTestCase(TestCase):
'Deprecation Message!', str(recorded_warnings[0].message)
)
# raise_warning should show warning until version info is >= (0, 17)
with warnings.catch_warnings(record=True) as recorded_warnings:
raise_named_version_warning()
self.assertEqual(
'Deprecation Message!', str(recorded_warnings[0].message)
)
# the deprecation warning is not issued because we passed
# _dont_call_warning
with warnings.catch_warnings(record=True) as recorded_warnings:
warn_until(
(0, 17), 'Foo', _dont_call_warnings=True
(0, 17), 'Foo', _dont_call_warnings=True,
_version_info_=(0, 16)
)
self.assertEqual(0, len(recorded_warnings))
# Let's set version info to (0, 17), a RuntimeError should be raised
salt_version_mock.__version_info__ = (0, 17)
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17\' is released. Current version is now \'0.17\'. Please '
r'remove the warning.'):
raise_warning()
r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
r'Please remove the warning.'):
raise_warning(_version_info_=(0, 17, 0))
# Let's set version info to (0, 17), a RuntimeError should be raised
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'Hydrogen((.*))\' is released. Current version is now '
r'\'([\d.]+)\'. Please remove the warning.'):
raise_named_version_warning(_version_info_=(sys.maxint, 16, 0))
# Even though we're calling warn_until, we pass _dont_call_warnings
# because we're only after the RuntimeError
@ -70,32 +91,53 @@ class WarnUntilTestCase(TestCase):
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17\' is released. Current version is now \'0.17\'. Please '
r'remove the warning.'):
r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
r'Please remove the warning.'):
warn_until(
(0, 17), 'Foo', _dont_call_warnings=True
)
@patch('salt.version')
def test_kwargs_warn_until_warning_raised(self, salt_version_mock):
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'Hydrogen((.*))\' is released. Current version is now '
r'\'([\d.]+)\'. Please remove the warning.'):
warn_until(
'Hydrogen', 'Foo', _dont_call_warnings=True,
_version_info_=(sys.maxint, 16, 0)
)
# version on the deprecation message gets properly formatted
with warnings.catch_warnings(record=True) as recorded_warnings:
vrs = SaltStackVersion.from_name('Helium')
warn_until(
'Helium', 'Deprecation Message until {version}!',
_version_info_=(vrs.major - 1, 0)
)
self.assertEqual(
'Deprecation Message until {0}!'.format(vrs.formatted_version),
str(recorded_warnings[0].message)
)
def test_kwargs_warn_until_warning_raised(self):
# We *always* want *all* warnings thrown on this module
warnings.filterwarnings('always', '', DeprecationWarning, __name__)
# Define a salt version info
salt_version_mock.__version_info__ = (0, 16)
def raise_warning(**kwargs):
_version_info_ = kwargs.pop('_version_info_', (0, 16, 0))
kwargs_warn_until(
kwargs,
(0, 17),
_version_info_=_version_info_
)
# raise_warning({...}) should show warning until version info is >= (0, 17)
with warnings.catch_warnings(record=True) as recorded_warnings:
raise_warning(foo=42) # with a kwarg
raise_warning(foo=42) # with a kwarg
self.assertEqual(
'The following parameter(s) have been deprecated and '
'will be removed in 0.17: \'foo\'.',
'will be removed in \'0.17.0\': \'foo\'.',
str(recorded_warnings[0].message)
)
# With no **kwargs, should not show warning until version info is >= (0, 17)
@ -103,26 +145,27 @@ class WarnUntilTestCase(TestCase):
kwargs_warn_until(
{}, # no kwargs
(0, 17),
_version_info_=(0, 16, 0)
)
self.assertEqual(0, len(recorded_warnings))
# Let's set version info to (0, 17), a RuntimeError should be raised
# regardless of whether or not we pass any **kwargs.
salt_version_mock.__version_info__ = (0, 17)
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17\' is released. Current version is now \'0.17\'. Please '
r'remove the warning.'):
raise_warning() # no kwargs
r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
r'Please remove the warning.'):
raise_warning(_version_info_=(0, 17)) # no kwargs
with self.assertRaisesRegexp(
RuntimeError,
r'The warning triggered on filename \'(.*)warnings_test.py\', '
r'line number ([\d]+), is supposed to be shown until version '
r'\'0.17\' is released. Current version is now \'0.17\'. Please '
r'remove the warning.'):
raise_warning(bar='baz', qux='quux') # some kwargs
r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
r'Please remove the warning.'):
raise_warning(bar='baz', qux='quux', _version_info_=(0, 17)) # some kwargs
if __name__ == '__main__':

View File

@ -54,12 +54,21 @@ class VersionTestCase(TestCase):
('debian/0.11.1+ds-1-3-ga0afcbd', '0.11.1+ds-2'),
('v0.12.0-85-g2880105', 'v0.12.0-19-g767d4f9'),
('v0.17.0rc1-1-g52ebdfd', '0.17.0rc1'),
('v0.17.0', 'v0.17.0rc1')
('v0.17.0', 'v0.17.0rc1'),
('Hydrogen', '0.17.0'),
('Helium', 'Hydrogen'),
)
for v1, v2 in examples:
self.assertTrue(SaltStackVersion.parse(v1) > v2)
self.assertTrue(SaltStackVersion.parse(v2) < v1)
def test_unparsable_version(self):
with self.assertRaises(ValueError):
SaltStackVersion.from_name('Drunk')
with self.assertRaises(ValueError):
SaltStackVersion.parse('Drunk')
if __name__ == '__main__':
from integration import run_tests