Am 13. Dezember 2010 16:21 schrieb Apollon Oikonomopoulos <[email protected]>: > Passing tap devices to KVM as file descriptors requires that the respective > file decriptors remain open during utils.RunCmd execution. To this direction, > we add a “noclose_fds” keyword argument to utils.RunCmd, accepting a list of > file descriptors to keep open. The actual fd handling is implemented in > _RunCmdPipe and _RunCmdFile using subprocess.Popen's “preexec_fn”[1], > since subprocess.Popen provides no other way to selectively handle fds. > > A small modification is also made to test/ganeti.utils_unittest.py to comply > with _RunCmdPipe's new API. > > [1] “If preexec_fn is set to a callable object, this object will be called in > the child process just before the child is executed. (Unix only)” > Subprocess documentation
Could you please provide a unittest for this? - Open temporary file in Python - Write something to file - Seek to beginning of file - RunCmd with file descriptor - In command, read from file descriptor and check whether you get the expected content Also test the opposite, that is whether it fails without noclose_fds. Thanks, Michael
