Skip to content

Commit

Permalink
refactor: Pass deprecation log args as tuple (canonical#5953)
Browse files Browse the repository at this point in the history
The previous way was preventing passing multiple (or no) args.
  • Loading branch information
TheRealFalcon committed Jan 13, 2025
1 parent 4d559e7 commit 07db0da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cloudinit/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _should_wait_via_user_data(
version="24.4",
requested_level=logging.WARNING,
msg="Unexpected failure parsing userdata: %s",
args=e,
args=(e,),
)
return True, "failed to parse user data as yaml"

Expand Down
6 changes: 3 additions & 3 deletions cloudinit/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def log_with_downgradable_level(
version: str,
requested_level: int,
msg: str,
args,
args: tuple,
):
"""Log a message at the requested level, if that is acceptable.
Expand All @@ -145,9 +145,9 @@ def log_with_downgradable_level(
:return: True if the message should be logged, else False.
"""
if should_log_deprecation(version, features.DEPRECATION_INFO_BOUNDARY):
logger.log(requested_level, msg, args)
logger.log(requested_level, msg, *args)
else:
logger.debug(msg, args)
logger.debug(msg, *args)


def deprecate(
Expand Down
32 changes: 32 additions & 0 deletions tests/unittests/cloudinit/test_lifecycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging

import pytest

from cloudinit import lifecycle

LOG = logging.getLogger()


class TestLogWithDowngradableLevel:
@pytest.mark.parametrize(
"version,expected",
[
("9", logging.ERROR),
("11", logging.DEBUG),
],
)
def test_log_with_downgradable_level(
self, mocker, caplog, version, expected
):
mocker.patch("cloudinit.features.DEPRECATION_INFO_BOUNDARY", "10")
lifecycle.log_with_downgradable_level(
logger=LOG,
version=version,
requested_level=logging.ERROR,
msg="look at me %s %s!",
args=("one", "two"),
)
records = caplog.record_tuples
assert len(records) == 1
assert records[0][1] == expected
assert records[0][2] == "look at me one two!"

0 comments on commit 07db0da

Please sign in to comment.