kimchi-project / kimchi

An HTML5 management interface for KVM guests
https://github.com/kimchi-project/kimchi/releases/latest
Other
3.09k stars 365 forks source link

ERROR:KCHVM0090E: Unable to create a password-less libvirt connection to the remote libvirt daemon #1170

Closed time-river closed 6 years ago

time-river commented 7 years ago

I think it is a bug.

Error log

KCHVM0090E: Unable to create a password-less libvirt connection to the remote libvirt daemon at host 10.67.161.21 with the user root. Please verify the remote server libvirt configuration. More information: http://libvirt.org/auth.html .

Reason

```python
# model/vms.py
    def _check_remote_libvirt_conn(self, remote_host,
                                   user='root', transport='ssh'):

        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)
        timeout = 0
        while proc.poll() is None:
            time.sleep(1)
            timeout += 1
            if timeout == 5:
                os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
                raise OperationFailed("KCHVM0090E",
                                      {'host': remote_host, 'user': user})

proc is timeout every time although the connection is normal tested by virsh -c uri list and the following script:

novell@bj-ha-1:~> python2
Python 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex, subprocess
>>> command_line = raw_input()
virsh -c qemu+ssh://root@10.67.161.11/system list
>>> args = shlex.split(command_line)
>>> proc = subprocess.Popen(args)
>>>  Id    Name                           State
----------------------------------------------------

>>> proc.poll()
0

There is my patch:

diff -ru orig-kimchi-2.5.0/model/vms.py kimchi-2.5.0/model/vms.py
--- orig-kimchi-2.5.0/model/vms.py  2017-08-22 17:08:00.133961163 +0800
+++ kimchi-2.5.0/model/vms.py   2017-08-22 17:10:21.965865080 +0800
@@ -1885,10 +1885,11 @@
     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)

Attention: shell=False And I think FNULL is better than PIPE in the connection test.

Environment: Python: 2.7.13 Kimchi: 2.5.0 from Release tag