Skip to content

Conversation

@bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Jul 12, 2024

Hi @psafont,
For logging the output of /usr/bin/systemctl reload-or-restart sshd in python3/plugins/extauth-hook-AD.py, mypy found a minor regression:

  • We should add universal_newlines=True there to fix the formatting of the logged output.

How this could be found:

  • mypy is good at spotting changes in str/bytes from moving to Python3
  • mypy wasn't fully usable yet, the config was not yet updated for python3/*.
    • But with the moving of files to python3/* having made good process, I fixed the config for it.

In Python3, subprocess.check_output(command) returns bytes by default (unless it is switched to text mode).

  • The original Python2 code assumes it returns str by default.
    • This leads to slightly non-ideal logging in this case.
  • Fix this by using subprocess.check_output(command, universal_newlines=True)

The run_cmd function in python3/plugins/extauth-hook-AD.py has only one call:

       run_cmd(["/usr/bin/systemctl", "reload-or-restart", "sshd"])

Therefore, the unused default argument and returning the output can be removed (both are not used):

Commit 1:

  • python3/plugins/test_extauth_hook_AD.py:
    • Assert the current bug and cover the to be fixed code.
    • No code change.

Commit 2:

  • python3/plugins/extauth-hook-AD.py: Fix logging in run_cmd()
    • Fixes the bug and updates the test case
    • Simply the code and the test:
      • Remove the unused default argument log_cmd=True (cmd is always logged - only one call site)
      • Remove returning the command output (not used by the sole call site of this function)

Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
@bernhardkaindl bernhardkaindl changed the title python3/plugins/test_extauth_hook_AD.py: Assert the current bug python3/plugins/test_extauth_hook_AD.py: Fix logging in run_cmd() Jul 12, 2024
@psafont psafont merged commit b1e7710 into xapi-project:feature/py3 Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants