Skip to content
New issue

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

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

Already on GitHub? # to your account

Added logging of additional debugging information to nsenter function #17

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

lveyde
Copy link
Member

@lveyde lveyde commented Jul 7, 2022

Previosuly we haven't logged the output of the STDERR, only the STDOUT, while calling the nsenter command.
Additionally we haven't logged the return code.
This patch fixes that.

Signed-off-by: Lev Veyde lveyde@redhat.com

Changes introduced with this PR

  • nsenter function was modified, so we log both STDOUT and STDERR output of the nsenter command
  • Also we now log the returncode from that same call

Are you the owner of the code you are sending in, or do you have permission of the owner?

[y]

Copy link
Member

@sandrobonazzola sandrobonazzola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Previosuly we haven't logged the output of the STDERR, only the STDOUT.
Additionally we haven't logged the return code.
This patch fixes that.

Signed-off-by: Lev Veyde <lveyde@redhat.com>
@lveyde lveyde force-pushed the log-stderr-and-returncodes branch from a58883f to 6595889 Compare July 7, 2022 13:50
Copy link
Member

@aesteve-rh aesteve-rh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

stdout, stderr = proc.communicate()
log.debug("STDOUT: %s", repr(stdout))
log.debug("STDERR: %s", repr(stderr))
log.debug("ReturnCode: %s", repr(proc.returncode))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but having single log like we have in vdsm can be more clear:

log.debug("Command %s terminated with return code %s, out %r, err %r",
          arg, proc.returncode, out, err)

We don't need to use repr(obj), %r does it for us. There is no need to do repr of the return code, it is an integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output normally is already long enough, and frequently is multi-line.
So pushing it into one line will make it even less visible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, marked as resolved but I don't see any change in the code or reply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but having single log like we have in vdsm can be more clear:

log.debug("Command %s terminated with return code %s, out %r, err %r",
          arg, proc.returncode, out, err)

We don't need to use repr(obj), %r does it for us. There is no need to do repr of the return code, it is an integer.

Potentially the returncode can be None if for some weird reason the process hasn't been ended by the time we return from communicate(), so I preferred to use repr() on it as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return code cannot be None when communicate() returns. It returns after the process terminated and and the child was reaped.
https://docs.python.org/3.6/library/subprocess.html#subprocess.Popen.communicate

Regardless, logging None with %s is the same as logging with %r:

>>> "%s %s %r %r" % (None, None, 0, 0)

'None None 0 0'

You did not answer about using repr() instead of %r, I guess you missed this. This should be fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is already merged, I'll open a new PR for that.

Copy link
Member Author

@lveyde lveyde Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent PR#18 ( #18 ) to address this.

@lveyde lveyde merged commit d1373b1 into oVirt:master Jul 7, 2022
@sandrobonazzola sandrobonazzola added this to the ovirt-4.5.4 milestone Dec 5, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants