[Kimchi-devel] [PATCH] [Kimchi] Allow kvmusertests to run with regular user
Aline Manera
alinefm at linux.vnet.ibm.com
Tue Mar 7 13:23:33 UTC 2017
Hi Lucio,
I have tested this patch and I got the following outputs while running
with and without sudo permissions:
[alinefm at alinefm-TP440 kimchi]$ PYTHONPATH=../../../ python kvmusertests.py
alinefm
[alinefm at alinefm-TP440 kimchi]$ sudo PYTHONPATH=../../../ python
kvmusertests.py
qemu
As you can see, when running it without sudo the result is different of
when running with sudo.
This code is used to determine the qemu user in the system to make sure
qemu and libvirt can work with some disk files.
So 'alinefm' is not the right value to do that.
The idea behind this patch is to allow the tests run without sudo, so
maybe, it is better to overwrite this code in the tests files instead of
changing the production behavior.
On 03/03/2017 01:22 PM, Lucio Correia wrote:
> Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
> ---
> kvmusertests.py | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/kvmusertests.py b/kvmusertests.py
> index a3fb273..3b3a603 100644
> --- a/kvmusertests.py
> +++ b/kvmusertests.py
> @@ -1,6 +1,6 @@
> # Project Kimchi
> #
> -# Copyright IBM Corp, 2015-2016
> +# Copyright IBM Corp, 2015-2017
> #
> # This library is free software; you can redistribute it and/or
> # modify it under the terms of the GNU Lesser General Public
> @@ -17,6 +17,7 @@
> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>
> import libvirt
> +import os
> import platform
> import psutil
> import threading
> @@ -56,12 +57,18 @@ class UserTests(object):
>
> with RollbackContext() as rollback:
> with cls.lock:
> - conn = libvirt.open(None)
> + conn = libvirt.open("qemu:///session")
> rollback.prependDefer(conn.close)
> f = libvirt.VIR_DOMAIN_START_AUTODESTROY
> dom = conn.createXML(xml, flags=f)
> rollback.prependDefer(dom.destroy)
> - filename = '/var/run/libvirt/qemu/%s.pid' % KVMUSERTEST_VM_NAME
> +
> + # find pid file for VM
> + uid = str(os.getuid())
> + filedir = os.path.join('/run/user', uid, 'libvirt/qemu/run')
> + if uid == '0':
> + filedir = '/var/run/libvirt/qemu'
> + filename = os.path.join(filedir, KVMUSERTEST_VM_NAME + ".pid")
> with open(filename) as f:
> pidStr = f.read()
> p = psutil.Process(int(pidStr))
More information about the Kimchi-devel
mailing list