Skip to content

Commit f0933cf

Browse files
garethgreenawayMegan Wilhite
authored andcommitted
Adding ignore_list argument to the decorator to filter out functions in a module that should not have the deprecation warning applied.
1 parent 60a97b6 commit f0933cf

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

salt/utils/decorators/extension_deprecation.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@
1010
log = logging.getLogger(__name__)
1111

1212

13-
def extension_deprecation_message(version, extension_name, extension_repo):
13+
def extension_deprecation_message(
14+
version, extension_name, extension_repo, ignore_list=None
15+
):
1416
"""
1517
Decorator wrapper to warn about deprecation
1618
"""
1719

1820
def decorator(function):
1921
@wraps(function)
2022
def wrapper(*args, **kwargs):
21-
salt.utils.versions.warn_until(
22-
version,
23-
f"The '{extension_name}' functionality in Salt has been deprecated and its "
24-
"functionality will be removed in version {version} in favor of the "
25-
f"saltext.{extension_name} Salt Extension. "
26-
f"({extension_repo})",
27-
category=DeprecationWarning,
28-
)
23+
if not ignore_list or function.__name__ not in ignore_list:
24+
salt.utils.versions.warn_until(
25+
version,
26+
f"The '{extension_name}' functionality in Salt has been deprecated and its "
27+
"functionality will be removed in version {version} in favor of the "
28+
f"saltext.{extension_name} Salt Extension. "
29+
f"({extension_repo})",
30+
category=DeprecationWarning,
31+
)
2932
return function(*args, **salt.utils.args.clean_kwargs(**kwargs))
3033

3134
return wrapper

tests/pytests/functional/utils/test_extension_deprecation.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55

66
@extension_deprecation_message(3009, "salt_mod", "http://www.example.com")
7-
def salt_func():
7+
def salt_func_one():
8+
return True
9+
10+
11+
@extension_deprecation_message(
12+
3009, "salt_mod", "http://www.example.com", ignore_list=["salt_func_two"]
13+
)
14+
def salt_func_two():
815
return True
916

1017

@@ -20,9 +27,13 @@ def test_extension_deprecation():
2027
"in favor of the saltext.salt_mod Salt Extension. (http://www.example.com)"
2128
)
2229
with warnings.catch_warnings(record=True) as catch_warnings:
23-
ret = salt_func()
30+
ret = salt_func_one()
2431
assert ret
25-
2632
assert len(catch_warnings) == 1
2733
assert issubclass(catch_warnings[-1].category, DeprecationWarning)
2834
assert str(catch_warnings[-1].message) == expected_deprecation_message
35+
36+
with warnings.catch_warnings(record=True) as catch_warnings:
37+
ret = salt_func_two()
38+
assert ret
39+
assert len(catch_warnings) == 0

0 commit comments

Comments
 (0)