From 63ead90ab9d81f9b5ac3cdc08a6a3a932c1a81d7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 8 Feb 2021 00:52:29 +0100 Subject: [PATCH] Always mention the name of the deprecated plugin in routing deprecation messages (#73059) (#73237) (cherry picked from commit df9cf368c0bb5ff2f7152402b30a0f27a5571389) --- .../fragments/73059-improve-deprecation-texts.yml | 2 ++ lib/ansible/plugins/loader.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/73059-improve-deprecation-texts.yml diff --git a/changelogs/fragments/73059-improve-deprecation-texts.yml b/changelogs/fragments/73059-improve-deprecation-texts.yml new file mode 100644 index 00000000000..b1ca876858d --- /dev/null +++ b/changelogs/fragments/73059-improve-deprecation-texts.yml @@ -0,0 +1,2 @@ +bugfixes: +- "Always mention the name of the deprecated or tombstoned plugin in routing deprecation/tombstone messages (https://github.com/ansible/ansible/pull/73059)." diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py index 957fa725b35..3c241274e09 100644 --- a/lib/ansible/plugins/loader.py +++ b/lib/ansible/plugins/loader.py @@ -140,14 +140,15 @@ class PluginLoadContext(object): if not deprecation: return self - warning_text = deprecation.get('warning_text', None) + # The `or ''` instead of using `.get(..., '')` makes sure that even if the user explicitly + # sets `warning_text` to `~` (None) or `false`, we still get an empty string. + warning_text = deprecation.get('warning_text', None) or '' removal_date = deprecation.get('removal_date', None) removal_version = deprecation.get('removal_version', None) # If both removal_date and removal_version are specified, use removal_date if removal_date is not None: removal_version = None - if not warning_text: - warning_text = '{0} has been deprecated'.format(name) + warning_text = '{0} has been deprecated.{1}{2}'.format(name, ' ' if warning_text else '', warning_text) display.deprecated(warning_text, date=removal_date, version=removal_version, collection_name=collection_name) @@ -462,7 +463,8 @@ class PluginLoader: if tombstone: removal_date = tombstone.get('removal_date') removal_version = tombstone.get('removal_version') - warning_text = tombstone.get('warning_text') or '{0} has been removed.'.format(fq_name) + warning_text = tombstone.get('warning_text') or '' + warning_text = '{0} has been removed.{1}{2}'.format(fq_name, ' ' if warning_text else '', warning_text) removed_msg = display.get_deprecation_message(msg=warning_text, version=removal_version, date=removal_date, removed=True, collection_name=acr.collection)