Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put back deprecation warnings #63315

Merged
merged 8 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/62185.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restored Salt's DeprecationWarnings
1 change: 1 addition & 0 deletions changelog/63315.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added deprecation_warning test state for ensuring that deprecation warnings are correctly emitted.
3 changes: 2 additions & 1 deletion salt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def exec_module(self, module):
"", # No deprecation message match
DeprecationWarning, # This filter is for DeprecationWarnings
r"^(salt|salt\.(.*))$", # Match module(s) 'salt' and 'salt.<whatever>'
append=True,
# Do *NOT* add append=True here - if we do, salt's DeprecationWarnings will
# never show up
)

# Filter the backports package UserWarning about being re-imported
Expand Down
25 changes: 25 additions & 0 deletions salt/modules/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import salt.utils.functools
import salt.utils.hashutils
import salt.utils.platform
import salt.utils.versions
import salt.version
from salt.utils.decorators import depends

Expand Down Expand Up @@ -675,3 +676,27 @@ def _is_exc(cls):
except AttributeError:
log.error("No such exception: %s", name)
return False


def deprecation_warning():
r"""
Return True, but also produce two DeprecationWarnings. One by date, the
other by the codename - release Oganesson, which should correspond to Salt
3108.

CLI Example:

.. code-block:: bash

salt \* test.deprecation_warning
"""
# This warn should always stay in Salt.
salt.utils.versions.warn_until(
"Oganesson",
"This is a test deprecation warning by version.",
)
salt.utils.versions.warn_until_date(
"30000101",
"This is a test deprecation warning by date very far into the future ({date}).",
)
return True
28 changes: 26 additions & 2 deletions tests/pytests/integration/cli/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,19 @@ def test_batch_retcode(salt_cli, salt_minion, salt_sub_minion, run_timeout):
)

assert cmd.returncode == 23
assert not cmd.stderr
# TODO: Certain platforms will have a warning related to jinja. But
# that's an issue with dependency versions that may be due to the versions
# installed on the test images. When those issues are sorted, this can
# simply `not cmd.stderr`.
assert (
not cmd.stderr
or cmd.stderr.endswith(
"jinja.py:736: DeprecationWarning: 'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.\n @contextfunction\n"
)
or cmd.stderr.endswith(
"process.py:54: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats\n current = setproctitle.getproctitle()\n"
)
)
assert "true" in cmd.stdout


Expand All @@ -198,7 +210,19 @@ def test_multiple_modules_in_batch(salt_cli, salt_minion, salt_sub_minion, run_t
)

assert cmd.returncode == 23
assert not cmd.stderr
# TODO: Certain platforms will have a warning related to setproctitle. But
# that's an issue with dependency versions that may be due to the versions
# installed on the test images. When those issues are sorted, this can
# simply `not cmd.stderr`.
assert (
not cmd.stderr
or cmd.stderr.endswith(
"process.py:54: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats\n current = setproctitle.getproctitle()\n"
)
or cmd.stderr.endswith(
"jinja.py:736: DeprecationWarning: 'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.\n @contextfunction\n"
)
)


def test_batch_module_stopping_failed_respond(
Expand Down
8 changes: 8 additions & 0 deletions tests/pytests/integration/modules/test_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def test_deprecation_warning_emits_deprecation_warnings(salt_call_cli):
ret = salt_call_cli.run("test.deprecation_warning")
assert ret.stderr.count("DeprecationWarning") >= 2
assert "This is a test deprecation warning by version." in ret.stderr
assert (
"This is a test deprecation warning by date very far into the future (3000-01-01)"
in ret.stderr
)
46 changes: 44 additions & 2 deletions tests/pytests/scenarios/daemons/test_salt_as_daemons.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,28 @@ def test_salt_master_as_daemon(salt_master_factory):
pass
finally:
assert salt_master_factory.impl._terminal_result.stdout == ""
assert salt_master_factory.impl._terminal_result.stderr == ""
# TODO currently setproctitle.getproctitle warns on some platforms.
# It's fine, actually, for that warning to show up, until the
# correct versions are configured for those platforms. When they
# are, the 'if not all(...):' line should be removed and just the
# assertion that `stderr == ""` should be left.
if not any(
(
all(
text in salt_master_factory.impl._terminal_result.stderr
for text in ("PY_SSIZE_T_CLEAN", "salt/utils/process.py:54")
),
all(
text in salt_master_factory.impl._terminal_result.stderr
for text in (
"salt/utils/jinja.py:736",
"contextfunction",
"pass_context",
)
),
)
):
assert salt_master_factory.impl._terminal_result.stderr == ""
assert salt_master_factory.impl._terminal_result.returncode == 0

# We are going to kill the possible child processes based on the entire cmdline
Expand Down Expand Up @@ -61,7 +82,28 @@ def test_salt_minion_as_daemon(salt_minion_factory):
pass
finally:
assert salt_minion_factory.impl._terminal_result.stdout == ""
assert salt_minion_factory.impl._terminal_result.stderr == ""
# TODO currently setproctitle.getproctitle warns on some platforms.
# It's fine, actually, for that warning to show up, until the
# correct versions are configured for those platforms. When they
# are, the 'if not all(...):' line should be removed and just the
# assertion that `stderr == ""` should be left.
if not any(
(
all(
text in salt_minion_factory.impl._terminal_result.stderr
for text in ("PY_SSIZE_T_CLEAN", "salt/utils/process.py:54")
),
all(
text in salt_minion_factory.impl._terminal_result.stderr
for text in (
"salt/utils/jinja.py:736",
"contextfunction",
"pass_context",
)
),
)
):
assert salt_minion_factory.impl._terminal_result.stderr == ""
assert salt_minion_factory.impl._terminal_result.returncode == 0

# We are going to kill the possible child processes based on the entire cmdline
Expand Down