[elbe-devel] [PATCH 4/4] initvmaction: improve errormessages, when libvirt.open() fails
Manuel Traut
manuel.traut at linutronix.de
Thu Apr 26 17:36:19 CEST 2018
On Thu, Apr 26, 2018 at 05:01:49PM +0200, Torben Hohn wrote:
> in the testssystem we saw 2 Exceptions:
>
> ---------------------------------------------------------------------------
> 00:03:06.085 [elbe] Running shell script
> 00:03:06.356 + pyjutest ./elbe initvm create --devel
> 00:03:06.616 libvirt: XML-RPC error : Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
> 00:03:06.616 Traceback (most recent call last):
> 00:03:06.617 File "./elbe", line 55, in <module>
> 00:03:06.617 cmdmod.run_command(sys.argv[2:])
> 00:03:06.617 File
> +"/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/commands/initvm.py", line 81, in
> +run_command
> 00:03:06.617 action = InitVMAction(args[0])
> 00:03:06.617 File "/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/initvmaction.py",
> +line 214, in __init__
> 00:03:06.617 InitVMAction.__init__(self, node, initvmNeeded=False)
> 00:03:06.617 File "/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/initvmaction.py",
> +line 76, in __init__
> 00:03:06.617 self.conn = libvirt.open("qemu:///system")
> 00:03:06.617 File "/usr/lib/python2.7/dist-packages/libvirt.py", line 255, in open
> 00:03:06.617 if ret is None:raise libvirtError('virConnectOpen() failed')
> ---------------------------------------------------------------------------
>
> and
>
> ---------------------------------------------------------------------------
> 00:04:50.675 libvirt: Polkit error : authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'
> 00:04:50.675 Traceback (most recent call last):
> 00:04:50.675 File "./elbe", line 55, in <module>
> 00:04:50.675 cmdmod.run_command(sys.argv[2:])
> 00:04:50.675 File
> +"/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/commands/initvm.py", line 81, in
> +run_command
> 00:04:50.675 action = InitVMAction(args[0])
> 00:04:50.675 File "/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/initvmaction.py",
> +line 214, in __init__
> 00:04:50.675 InitVMAction.__init__(self, node, initvmNeeded=False)
> 00:04:50.675 File "/home/jenkins/workspace/elbe-ci_master-GR3Z27HXOEGCLBRIZJ26LAS7Z5D6A3IGOIJJKIZKSYAUUYZJSUYQ/elbe/elbepack/initvmaction.py",
> +line 76, in __init__
> 00:04:50.675 self.conn = libvirt.open("qemu:///system")
> 00:04:50.675 File "/usr/lib/python2.7/dist-packages/libvirt.py", line 255, in open
> 00:04:50.675 if ret is None:raise libvirtError('virConnectOpen() failed')
> 00:04:50.675 libvirt.libvirtError: authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'
> ---------------------------------------------------------------------------
>
> Add code, to catch em, and provide a meaningful Error message
>
> Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
Reviewed-by: Manuel Traut <manut at linutronix.de>
this will be merged into devel/elbe-3.0
> ---
> elbepack/initvmaction.py | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
> index 05ebf877..76fbc93d 100644
> --- a/elbepack/initvmaction.py
> +++ b/elbepack/initvmaction.py
> @@ -81,7 +81,29 @@ class InitVMAction(object):
> def __init__(self, node, initvmNeeded=True):
> # The tag initvmNeeded is required in order to be able to run `elbe
> # initvm create`
> - self.conn = libvirt.open("qemu:///system")
> + try:
> + self.conn = libvirt.open("qemu:///system")
> + except libvirt.libvirtError as verr:
> + if type(verr.args[0]) is not str:
> + raise
> + if verr.args[0].startswith('Failed to connect socket to'):
> + print("", file=sys.stderr)
> + print("Accessing libvirt provider system not possible.", file=sys.stderr)
> + print("Make sure that package 'libvirt-daemon-system' is", file=sys.stderr)
> + print("installed, and the service is running properly", file=sys.stderr)
> + sys.exit(20)
> +
> + if verr.args[0].startswith('authentication unavailable'):
> + print("", file=sys.stderr)
> + print("Accessing libvirt provider system not allowed.", file=sys.stderr)
> + print("Users which want to use elbe need to be members of the 'libvirt' group.", file=sys.stderr)
> + print("'gpasswd -a <user> libvirt' and logging in again,", file=sys.stderr)
> + print("should fix the problem.", file=sys.stderr)
> + sys.exit(20)
> +
> + # In case we get here, the exception is unknown, and we want to see it
> + raise
> +
> try:
> self.initvm = self.conn.lookupByName(cfg['initvm_domain'])
> except libvirt.libvirtError:
> --
> 2.11.0
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
More information about the elbe-devel
mailing list