From f3ef4ed076552b7ae560fd7b7e071f34ae70c222 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Tue, 7 Jul 2020 18:41:19 -0500 Subject: [PATCH] Remove some constants.py deprecated items (#70466) Change: - Remove mk_boolean - Remove BECOME_METHODS - Remove get_config Test Plan: - CI, removed mk_boolean unit tests Tickets: - Fixes #69678 Signed-off-by: Rick Elrod --- .../fragments/constants-deprecation.yml | 4 +++ lib/ansible/constants.py | 35 ------------------- test/units/test_constants.py | 28 --------------- 3 files changed, 4 insertions(+), 63 deletions(-) create mode 100644 changelogs/fragments/constants-deprecation.yml diff --git a/changelogs/fragments/constants-deprecation.yml b/changelogs/fragments/constants-deprecation.yml new file mode 100644 index 00000000000..ee79b7724ee --- /dev/null +++ b/changelogs/fragments/constants-deprecation.yml @@ -0,0 +1,4 @@ +removed_features: + - The deprecated ``ansible.constants.mk_boolean()`` has been removed. + - The deprecated ``ansible.constants.get_config()`` has been removed. + - The deprecated ``ansible.constants.BECOME_METHODS`` has been removed. diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 5e9270b910e..38ae5c8f19b 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -39,32 +39,6 @@ def _deprecated(msg, version='2.8'): sys.stderr.write(' [DEPRECATED] %s, to be removed in %s\n' % (msg, version)) -def mk_boolean(value): - ''' moved to module_utils''' - _deprecated('ansible.constants.mk_boolean() is deprecated. Use ansible.module_utils.parsing.convert_bool.boolean() instead') - return boolean(value, strict=False) - - -def get_config(parser, section, key, env_var, default_value, value_type=None, expand_relative_paths=False): - ''' kept for backwarsd compatibility, but deprecated ''' - _deprecated('ansible.constants.get_config() is deprecated. There is new config API, see porting docs.') - - value = None - # small reconstruction of the old code env/ini/default - value = os.environ.get(env_var, None) - if value is None: - try: - value = get_ini_config_value(parser, {'key': key, 'section': section}) - except Exception: - pass - if value is None: - value = default_value - - value = ensure_type(value, value_type) - - return value - - def set_constant(name, value, export=vars()): ''' sets constants and returns resolved options dict ''' export[name] = value @@ -85,15 +59,6 @@ class _DeprecatedSequenceConstant(Sequence): return self._value[y] -# Deprecated constants -BECOME_METHODS = _DeprecatedSequenceConstant( - ['sudo', 'su', 'pbrun', 'pfexec', 'doas', 'dzdo', 'ksu', 'runas', 'pmrun', 'enable', 'machinectl'], - ('ansible.constants.BECOME_METHODS is deprecated, please use ' - 'ansible.plugins.loader.become_loader. This list is statically ' - 'defined and may not include all become methods'), - '2.10' -) - # CONSTANTS ### yes, actual ones BLACKLIST_EXTS = ('.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt', '.rst') BOOL_TRUE = BOOLEANS_TRUE diff --git a/test/units/test_constants.py b/test/units/test_constants.py index 4cf2f7f9a55..a206d2310fe 100644 --- a/test/units/test_constants.py +++ b/test/units/test_constants.py @@ -92,31 +92,3 @@ def cwd(): os.getcwd = old_cwd if hasattr(os, 'getcwdu'): os.getcwdu = old_cwdu - - -class TestMkBoolean: - def test_bools(self): - assert constants.mk_boolean(True) is True - assert constants.mk_boolean(False) is False - - def test_none(self): - assert constants.mk_boolean(None) is False - - def test_numbers(self): - assert constants.mk_boolean(1) is True - assert constants.mk_boolean(0) is False - assert constants.mk_boolean(0.0) is False - -# Current mk_boolean doesn't consider these to be true values -# def test_other_numbers(self): -# assert constants.mk_boolean(2) is True -# assert constants.mk_boolean(-1) is True -# assert constants.mk_boolean(0.1) is True - - def test_strings(self): - assert constants.mk_boolean("true") is True - assert constants.mk_boolean("TRUE") is True - assert constants.mk_boolean("t") is True - assert constants.mk_boolean("yes") is True - assert constants.mk_boolean("y") is True - assert constants.mk_boolean("on") is True