engine: Drop PackageKit integration

On first run of the app we will check to see if libvirt and qemu
are installed, and if not, offer to install them. In theory anyways.
In practice this stuff breaks repeatedly and is a pain to test because
every desktop has their own API provider with subtly different behavior.

My last round of testing about 12 months ago: apper on KDE was completely
busted and apparently unmaintained (although that may have changed lately),
gnome-software is the latest packagekit provider on gnome and completely
changes the semantics of the API compared to old style gnome-packagekit
that break a lot of virt-manager assumptions.

So I'm tired of it and want it all gone. Still use systemd to try and
check if libvirtd is running, and provide error messages at startup
to guide people.
This commit is contained in:
Cole Robinson
2018-10-07 14:24:05 -04:00
parent e2352e8518
commit a1d1b4d5a0
5 changed files with 103 additions and 172 deletions
+75 -33
View File
@@ -5,14 +5,15 @@
# See the COPYING file in the top-level directory.
import logging
import os
import queue
import threading
import time
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import Gtk
from . import packageutils
from .baseclass import vmmGObject
from .connect import vmmConnect
from .connmanager import vmmConnectionManager
@@ -117,61 +118,102 @@ class vmmEngine(vmmGObject):
if not self.config.get_conn_uris() and not cliuri:
# Only add default if no connections are currently known
manager = self._get_manager()
manager.set_startup_error(
_("Checking for virtualization packages..."))
self.timeout_add(1000, self._add_default_conn)
def _add_default_conn(self):
"""
If there's no cached connections, or any requested on the command
line, try to determine a default URI and open it, possibly talking
to packagekit and other bits
line, try to determine a default URI and open it, first checking
if libvirt is running
"""
manager = self._get_manager()
# Manager fail message
msg = _("Could not detect a default hypervisor. Make\n"
"sure the appropriate virtualization packages\n"
"containing kvm, qemu, libvirt, etc. are\n"
"installed, and that libvirtd is running.\n\n"
"A hypervisor connection can be manually\n"
"added via File->Add Connection")
logging.debug("Trying to start libvirtd through systemd")
unitname = "libvirtd.service"
libvirtd_installed = False
libvirtd_active = False
logging.debug("Determining default libvirt URI")
packages_verified = False
# Fetch all units from systemd
try:
libvirt_packages = self.config.libvirt_packages
packages = self.config.hv_packages + libvirt_packages
packages_verified = packageutils.check_packagekit(
manager, manager.err, packages)
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
systemd = Gio.DBusProxy.new_sync(bus, 0, None,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager", None)
units = systemd.ListUnits()
except Exception:
logging.exception("Error talking to PackageKit")
units = []
logging.exception("Couldn't connect to systemd")
libvirtd_installed = os.path.exists("/var/run/libvirt")
libvirtd_active = os.path.exists("/var/run/libvirt/libvirt-sock")
# Check if libvirtd is installed and running
for unitinfo in units:
if unitinfo[0] != unitname:
continue
libvirtd_installed = True
libvirtd_active = unitinfo[3] == "active"
unitpath = unitinfo[6]
break
# If it's not running, try to start it
try:
if units and libvirtd_installed and not libvirtd_active:
unit = Gio.DBusProxy.new_sync(
bus, 0, None,
"org.freedesktop.systemd1", unitpath,
"org.freedesktop.systemd1.Unit", None)
if not self.config.test_first_run:
unit.Start("(s)", "fail")
time.sleep(2)
libvirtd_active = True
except Exception:
logging.exception("Error starting libvirtd")
# Manager fail message
tryuri = None
if packages_verified:
tryuri = "qemu:///system"
elif not self.config.test_first_run:
if not self.config.test_first_run:
tryuri = vmmConnect.default_uri()
logging.debug("Probed default URI=%s", tryuri)
if tryuri is None:
msg = ""
if not libvirtd_installed:
msg += _("The libvirtd service does not appear to be installed. "
"Install and run the libvirtd service to manage "
"virtualization on this host.")
elif not libvirtd_active:
msg += _("libvirtd is installed but not running. Start the "
"libvirtd service to manage virtualization on this host.")
if not tryuri or "qemu" not in tryuri:
if msg:
msg += "\n\n"
msg += _("Could not detect a default hypervisor. Make "
"sure the appropriate qemu/kvm virtualization "
"packages are installed to manage virtualization "
"on this host.")
if msg:
msg += "\n\n"
msg += _("A virtualization connection can be manually "
"added via File->Add Connection")
if (tryuri is None or
not libvirtd_installed or
not libvirtd_active):
manager.set_startup_error(msg)
return
# packagekit API via gnome-software doesn't even work nicely these
# days. Not sure what the state of this warning is...
#
# warnmsg = _("The 'libvirtd' service will need to be started.\n\n"
# "After that, virt-manager will connect to libvirt on\n"
# "the next application start up.")
# if not connected and not libvirtd_started:
# manager.err.ok(_("Libvirt service must be started"), warnmsg)
# Launch idle callback to connect to default URI
def idle_connect():
def _open_completed(c, ConnectError):
if ConnectError:
self._handle_conn_error(c, ConnectError)
packageutils.start_libvirtd()
conn = vmmConnectionManager.get_instance().add_conn(tryuri)
conn.set_autoconnect(True)
conn.connect_once("open-completed", _open_completed)