Skip to content

[hostcfgd] Wait for chage before checking status#410

Open
dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-hostcfgd-chage-return-code
Open

[hostcfgd] Wait for chage before checking status#410
dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-hostcfgd-chage-return-code

Conversation

@dlanov

@dlanov dlanov commented Jul 15, 2026

Copy link
Copy Markdown

Why I did it

PasswHardening.passwd_aging_expire_modify() checked the chage process status immediately with poll().

When the process was still running, poll() returned None. Because None != 0, hostcfgd logged a failure even when chage completed successfully.

Fixes #397.

Work item tracking
  • Microsoft ADO: N/A

How I did it

  • Replaced the immediate poll() call with wait() so hostcfgd checks the completed process exit status.
  • Preserved the existing chage command arguments and nonzero-return error message.
  • Added focused unit tests for successful and failed chage execution.
  • Mocked the subprocess and syslog calls so the tests do not modify real user accounts.

How to verify it

Completed locally:

  • git diff --check
  • python3 -m py_compile scripts/hostcfgd tests/hostcfgd/hostcfgd_passwh_test.py

The compile check completed successfully with two pre-existing SyntaxWarning messages for unrelated escape sequences in scripts/hostcfgd.

The focused tests could not be executed locally because the environment does not have pytest or the parameterized test dependency installed.

In a SONiC host-services test environment, run:

python3 -m pytest \
  tests/hostcfgd/hostcfgd_passwh_test.py \
  -k 'passwd_aging_expire_modify' \
  -v

To run the full password-hardening test file:

python3 -m pytest \
  tests/hostcfgd/hostcfgd_passwh_test.py \
  -v

Previous behavior

A successful chage process could still generate:

failed: return code - None

New behavior

Hostcfgd waits for chage to complete and logs the existing error only when the process exits with a nonzero status.

Wait for the chage process to finish before evaluating its return code, preventing successful password-aging updates from logging false errors.

Add focused tests for successful and failed chage execution.

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>
@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hostcfgd passwd_aging_expire_modify always logs error even when chage succeeds

2 participants