From 1f987423fd4887228736f27a525a98aca36b881a Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 27 Aug 2024 11:59:10 +0200 Subject: [PATCH] Print the name of the option being deprecated (#83761) Fixes #83759 --- lib/ansible/cli/__init__.py | 14 +------------- lib/ansible/config/manager.py | 2 +- lib/ansible/constants.py | 6 ++++-- test/integration/targets/deprecations/runme.sh | 4 ++-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 67661a524f1..8b12aec17f4 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -167,19 +167,7 @@ class CLI(ABC): else: display.v(u"No config file found; using defaults") - # warn about deprecated config options - for deprecated in C.config.DEPRECATED: - name = deprecated[0] - why = deprecated[1]['why'] - if 'alternatives' in deprecated[1]: - alt = ', use %s instead' % deprecated[1]['alternatives'] - else: - alt = '' - ver = deprecated[1].get('version') - date = deprecated[1].get('date') - collection_name = deprecated[1].get('collection_name') - display.deprecated("%s option, %s%s" % (name, why, alt), - version=ver, date=date, collection_name=collection_name) + C.handle_config_noise(display) @staticmethod def split_vault_id(vault_id): diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index 5f93820548a..2336ae1f4aa 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -684,5 +684,5 @@ class ConfigManager(object): removal = f"Will be removed in: Ansible {dep_docs['removed_in']}\n\t" # TODO: choose to deprecate either singular or plural - alt = dep_docs.get('alternatives', dep_docs.get('alternative', '')) + alt = dep_docs.get('alternatives', dep_docs.get('alternative', 'none')) return f"Reason: {dep_docs['why']}\n\t{removal}Alternatives: {alt}" diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 8ab684cbe38..34f91db54ea 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -50,14 +50,16 @@ def handle_config_noise(display=None): d = _deprecated while config.WARNINGS: - warn = config.WARNINGS.pop(0) + warn = config.WARNINGS.pop() w(warn) while config.DEPRECATED: # tuple with name and options dep = config.DEPRECATED.pop(0) msg = config.get_deprecated_msg_from_config(dep[1]) - d(msg, version=dep[1]['version']) + # use tabs only for ansible-doc? + msg = msg.replace("\t", "") + d(f"{dep[0]} option. {msg}", version=dep[1]['version']) def set_constant(name, value, export=vars()): diff --git a/test/integration/targets/deprecations/runme.sh b/test/integration/targets/deprecations/runme.sh index f16d4937a7d..48a02760ad3 100755 --- a/test/integration/targets/deprecations/runme.sh +++ b/test/integration/targets/deprecations/runme.sh @@ -9,8 +9,8 @@ export ANSIBLE_DEPRECATION_WARNINGS=True # check for entry key valid, no deprecation [ "$(ANSIBLE_CONFIG='entry_key_not_deprecated.cfg' ansible -m meta -a 'noop' localhost 2>&1 | grep -c 'DEPRECATION')" -eq "0" ] -# check for entry key deprecation, must be defined to trigger -[ "$(ANSIBLE_CONFIG='entry_key_deprecated.cfg' ansible -m meta -a 'noop' localhost 2>&1 | grep -c 'DEPRECATION')" -eq "1" ] +# check for entry key deprecation including the name of the option, must be defined to trigger +[ "$(ANSIBLE_CONFIG='entry_key_deprecated.cfg' ansible -m meta -a 'noop' localhost 2>&1 | grep -c "\[DEPRECATION WARNING\]: \[testing\]deprecated option.")" -eq "1" ] # check for deprecation of entry itself, must be consumed to trigger [ "$(ANSIBLE_TEST_ENTRY2=1 ansible -m debug -a 'msg={{q("config", "_Z_TEST_ENTRY_2")}}' localhost 2>&1 | grep -c 'DEPRECATION')" -eq "1" ]