Properly deprecate check_dns.

Instead of having to leave `**kwargs` "forever" in `salt.config.minion_config` and `salt.config.apply_minion_config` in order to support API access to those which still passes `check_dns`. Support the argument but show a deprecation warning once. Leave the deprecation warning for 2 major releases. Then, finally, and properly, remove `check_dns` for good.
This commit is contained in:
Pedro Algarvio 2013-07-20 01:39:23 +01:00
parent b03a5fcee3
commit 40c5512bfb
2 changed files with 95 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import re
import socket
import logging
import urlparse
import warnings
# import third party libs
import yaml
@ -25,6 +26,11 @@ import salt.utils
import salt.utils.network
import salt.pillar
# check_dns warnings filter to force deprecation warning exhibition once
warnings.filterwarnings(
'once', '(.*)check_dns(.*)', DeprecationWarning, __name__
)
log = logging.getLogger(__name__)
_DFLT_LOG_DATEFMT = '%H:%M:%S'
@ -531,10 +537,25 @@ def prepend_root_dir(opts, path_options):
def minion_config(path,
env_var='SALT_MINION_CONFIG',
defaults=None,
**kwargs):
check_dns=None):
'''
Reads in the minion configuration file and sets up special options
'''
if check_dns is not None:
# All use of the `check_dns` arg was removed in `598d715`. The keyword
# argument was then removed in `9d893e4` and `**kwargs` was then added
# in `5d60f77` in order not to break backwards compatibility.
#
# 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.
#
# XXX: Remove deprecation warning message on 0.19.0
warnings.warn(
'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',
DeprecationWarning
)
if defaults is None:
defaults = DEFAULT_MINION_OPTS
@ -672,10 +693,26 @@ def get_id():
return 'localhost', False
def apply_minion_config(overrides=None, defaults=None, **kwargs):
def apply_minion_config(overrides=None, defaults=None, check_dns=None):
'''
Returns minion configurations dict.
'''
if check_dns is not None:
# All use of the `check_dns` arg was removed in `598d715`. The keyword
# argument was then removed in `9d893e4` and `**kwargs` was then added
# in `5d60f77` in order not to break backwards compatibility.
#
# 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.
#
# XXX: Remove deprecation warning message on 0.19.0
warnings.warn(
'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',
DeprecationWarning
)
if defaults is None:
defaults = DEFAULT_MINION_OPTS

View File

@ -12,6 +12,7 @@
import os
import shutil
import tempfile
import warnings
# Import Salt Testing libs
from salttesting import TestCase
@ -23,7 +24,7 @@ ensure_in_syspath('../')
import salt.minion
import salt.utils
import integration
from salt import config as sconfig
from salt import config as sconfig, version as salt_version
class ConfigTestCase(TestCase):
@ -295,6 +296,60 @@ class ConfigTestCase(TestCase):
self.assertEquals(syndic_opts['_master_conf_file'], minion_config_path)
self.assertEquals(syndic_opts['_minion_conf_file'], syndic_conf_path)
def test_check_dns_deprecation_warning(self):
if salt_version.__version_info__ >= (0, 19):
raise AssertionError(
'Failing this test on purpose! Please delete this test case, '
'the \'check_dns\' keyword argument and the deprecation '
'warnings in `salt.config.minion_config` and '
'salt.config.apply_minion_config`'
)
# Let's force the warning to always be thrown
warnings.resetwarnings()
warnings.filterwarnings(
'always', '(.*)check_dns(.*)', DeprecationWarning, 'salt.config'
)
with warnings.catch_warnings(record=True) as w:
sconfig.minion_config(None, None, check_dns=True)
self.assertEqual(
'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', str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.apply_minion_config(
overrides=None, defaults=None, check_dns=True
)
self.assertEqual(
'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', str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.minion_config(None, None, check_dns=False)
self.assertEqual(
'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', str(w[-1].message)
)
with warnings.catch_warnings(record=True) as w:
sconfig.apply_minion_config(
overrides=None, defaults=None, check_dns=False
)
self.assertEqual(
'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', str(w[-1].message)
)
if __name__ == '__main__':
from integration import run_tests