mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Adding ignore_list argument to the decorator to filter out functions in a module that should not have the deprecation warning applied.
This commit is contained in:
parent
60a97b6236
commit
f0933cf408
2 changed files with 26 additions and 12 deletions
|
@ -10,7 +10,9 @@ import salt.utils.versions
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def extension_deprecation_message(version, extension_name, extension_repo):
|
||||
def extension_deprecation_message(
|
||||
version, extension_name, extension_repo, ignore_list=None
|
||||
):
|
||||
"""
|
||||
Decorator wrapper to warn about deprecation
|
||||
"""
|
||||
|
@ -18,14 +20,15 @@ def extension_deprecation_message(version, extension_name, extension_repo):
|
|||
def decorator(function):
|
||||
@wraps(function)
|
||||
def wrapper(*args, **kwargs):
|
||||
salt.utils.versions.warn_until(
|
||||
version,
|
||||
f"The '{extension_name}' functionality in Salt has been deprecated and its "
|
||||
"functionality will be removed in version {version} in favor of the "
|
||||
f"saltext.{extension_name} Salt Extension. "
|
||||
f"({extension_repo})",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
if not ignore_list or function.__name__ not in ignore_list:
|
||||
salt.utils.versions.warn_until(
|
||||
version,
|
||||
f"The '{extension_name}' functionality in Salt has been deprecated and its "
|
||||
"functionality will be removed in version {version} in favor of the "
|
||||
f"saltext.{extension_name} Salt Extension. "
|
||||
f"({extension_repo})",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
return function(*args, **salt.utils.args.clean_kwargs(**kwargs))
|
||||
|
||||
return wrapper
|
||||
|
|
|
@ -4,7 +4,14 @@ from salt.utils.decorators.extension_deprecation import extension_deprecation_me
|
|||
|
||||
|
||||
@extension_deprecation_message(3009, "salt_mod", "http://www.example.com")
|
||||
def salt_func():
|
||||
def salt_func_one():
|
||||
return True
|
||||
|
||||
|
||||
@extension_deprecation_message(
|
||||
3009, "salt_mod", "http://www.example.com", ignore_list=["salt_func_two"]
|
||||
)
|
||||
def salt_func_two():
|
||||
return True
|
||||
|
||||
|
||||
|
@ -20,9 +27,13 @@ def test_extension_deprecation():
|
|||
"in favor of the saltext.salt_mod Salt Extension. (http://www.example.com)"
|
||||
)
|
||||
with warnings.catch_warnings(record=True) as catch_warnings:
|
||||
ret = salt_func()
|
||||
ret = salt_func_one()
|
||||
assert ret
|
||||
|
||||
assert len(catch_warnings) == 1
|
||||
assert issubclass(catch_warnings[-1].category, DeprecationWarning)
|
||||
assert str(catch_warnings[-1].message) == expected_deprecation_message
|
||||
|
||||
with warnings.catch_warnings(record=True) as catch_warnings:
|
||||
ret = salt_func_two()
|
||||
assert ret
|
||||
assert len(catch_warnings) == 0
|
||||
|
|
Loading…
Add table
Reference in a new issue