Skip to content

Commit

Permalink
Change some log messages from warning to info
Browse files Browse the repository at this point in the history
Warning logs tends to alert customers that something is broken! Info log level
is more suitable in those cases where we want to inform the user of some actions
but not give an impression that something is broken and needs fixing. Convert
some warn logs to info logs when handling user account passwords.

Signed-off-by: Ani Sinha <[email protected]>
  • Loading branch information
ani-sinha committed Dec 12, 2024
1 parent f6075a9 commit 8cc3a60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
6 changes: 3 additions & 3 deletions cloudinit/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def create_user(self, name, **kwargs):
password_key = "passwd"
# Only "plain_text_passwd" and "hashed_passwd"
# are valid for an existing user.
LOG.warning(
LOG.info(
"'passwd' in user-data is ignored for existing "
"user %s",
name,
Expand Down Expand Up @@ -937,7 +937,7 @@ def create_user(self, name, **kwargs):
elif pre_existing_user:
# Pre-existing user with no existing password and none
# explicitly set in user-data.
LOG.warning(
LOG.info(
"Not unlocking blank password for existing user %s."
" 'lock_passwd: false' present in user-data but no existing"
" password set and no 'plain_text_passwd'/'hashed_passwd'"
Expand All @@ -946,7 +946,7 @@ def create_user(self, name, **kwargs):
)
else:
# No password (whether blank or otherwise) explicitly set
LOG.warning(
LOG.info(
"Not unlocking password for user %s. 'lock_passwd: false'"
" present in user-data but no 'passwd'/'plain_text_passwd'/"
"'hashed_passwd' provided in user-data",
Expand Down
33 changes: 0 additions & 33 deletions tests/integration_tests/modules/test_users_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
uid: 1743
"""

NEW_USER_EMPTY_PASSWD_WARNING = "Not unlocking password for user {username}. 'lock_passwd: false' present in user-data but no 'passwd'/'plain_text_passwd'/'hashed_passwd' provided in user-data" # noqa: E501

EXISTING_USER_EMPTY_PASSWD_WARNING = "Not unlocking blank password for existing user {username}. 'lock_passwd: false' present in user-data but no existing password set and no 'plain_text_passwd'/'hashed_passwd' provided in user-data" # noqa E501


@pytest.mark.ci
@pytest.mark.user_data(USER_DATA)
Expand Down Expand Up @@ -114,41 +110,12 @@ def test_user_root_in_secret(self, class_client):
"""Test root user is in 'secret' group."""
verify_clean_boot(
class_client,
require_warnings=[
NEW_USER_EMPTY_PASSWD_WARNING.format(username="nopassworduser")
],
)
output = class_client.execute("groups root").stdout
_, groups_str = output.split(":", maxsplit=1)
groups = groups_str.split()
assert "secret" in groups

def test_nopassword_unlock_warnings(self, class_client):
"""Verify warnings for empty passwords for new and existing users."""
verify_clean_boot(
class_client,
require_warnings=[
NEW_USER_EMPTY_PASSWD_WARNING.format(username="nopassworduser")
],
)

# Fake admin clearing and unlocking and empty unlocked password foobar
# This will generate additional warnings about not unlocking passwords
# for pre-existing users which have an existing empty password
class_client.execute("passwd -d foobar")
class_client.instance.clean()
class_client.restart()
verify_clean_boot(
class_client,
ignore_warnings=True, # ignore warnings about existing groups
require_warnings=[
EXISTING_USER_EMPTY_PASSWD_WARNING.format(
username="nopassworduser"
),
EXISTING_USER_EMPTY_PASSWD_WARNING.format(username="foobar"),
],
)


@pytest.mark.user_data(USER_DATA)
@pytest.mark.skipif(
Expand Down

0 comments on commit 8cc3a60

Please sign in to comment.