Reviewed-by: Aline Manera <alinemanera@gmail.com>

I will test and apply it upstream tomorrow. 

Thanks, 

Aline Manera

On Oct 31, 2017 04:28, "Fu.Lin" <lfu@suse.com> wrote:

Long ago, I submitted an issue: https://github.com/kimchi-project/kimchi/issues/1170 ...

Test by following script:

import subprocess
import os
import time

def _check_remote_libvirt_conn(remote_host,
        user='root', transport='ssh'):

    FNULL = open(os.devnull, 'w')
    dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
    cmd = ['virsh', '-c', dest_uri, 'list']
    proc = subprocess.Popen(cmd, stdout=FNULL, stderr=FNULL,
            shell=True, preexec_fn=os.setsid)
    timeout = 0
    while proc.poll() is None:
        time.sleep(1)
        timeout += 1
        if timeout == 5:
            print("killed")
            os.killpg(os.getpgid(proc.pid), signal.SIGTERM)

if __name__ == '__main__':
    _check_remote_libvirt_conn('localhost')

`proc` is timeout every time although the connection is normal tested by `virsh -c <uri>` list


The following is the reason of changing(From Python Document 2.7.14):

 Do not use stdout=PIPE or stderr=PIPE with this function as that can deadlock based on the child process output volume. Use Popen with the communicate() method when you need pipes.

 Using shell=True can be a security hazard. See the warning under Frequently Used Arguments for details.

At the same time, if not change, it does not work.


diff --git a/model/vms.py b/model/vms.py
index 6da4f3b..92e771f 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -1885,10 +1885,11 @@ class VMModel(object):
     def _check_remote_libvirt_conn(self, remote_host,
                                    user='root', transport='ssh'):
 
+        FNULL = open(os.devnull, 'w')
         dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
         cmd = ['virsh', '-c', dest_uri, 'list']
-        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                                shell=True, preexec_fn=os.setsid)
+        proc = subprocess.Popen(cmd, stdout=FNULL, stderr=FNULL,
+                                shell=False, preexec_fn=os.setsid)
         timeout = 0
         while proc.poll() is None:
             time.sleep(1)

-- 
Regards
River (Fu.Lin)

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel