-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[WIP] lxc_container: replace subprocess.Popen() with run_command() #11204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[WIP] lxc_container: replace subprocess.Popen() with run_command() #11204
Conversation
| with tempfile.NamedTemporaryFile(prefix="lxc-attach-script-err", delete=False, mode="ab") as stderr_file: | ||
| rc, out, err = module.run_command([script_file], binary_data=True, encoding=None) | ||
| stdout_file.write(out) | ||
| stderr_file.write(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this makes sense anymore. I think the temporary files are created so that if something goes wrong while executing the external command, that you can look at the temporary files to figure out what's happening. Like if the program doesn't terminate, takes too long, crashes - as the files arent' deleted.
Now stdout/stderr is only written after the program is done, and right afterwards the temporary files are deleted.
If we really want to use AnsibleModule.run_command here, we shouldn't create these files. But I'm not sure I understand this function good enough to be able to say whether Popen isn't better here...
@cloudnull, do you remember what's going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_script is called using lxc.Container.attach_wait(), which basically is a fork() that also changes the "container" where the process runs. The only temporary file that is deleted is the script_file one, and I agree it might be a good candidate for removal, but I did not want to change things too much in this PR.
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
|
Another thing I am not sure of: it is not clear how This part of the current code was from AI, and even though I did some spelunking in |
|
I will write the changelog fragment after the code change is settled. |
|
friendly ping @cloudnull sorry to bother, any chance you could help with this? TIA |
SUMMARY
The module was using
subprocess.Popen()to run an external command, whilst the recommended way is to useAnsibleModule.run_command().ISSUE TYPE
COMPONENT NAME
lxc_container