mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-07-29 23:58:20 -05:00
uitests: finish connection, connectauth
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[org/virt-manager/virt-manager/vmlist-fields]
|
||||
disk-usage=true
|
||||
network-traffic=true
|
||||
host-cpu-usage=true
|
||||
memory-usage=true
|
||||
|
||||
[org/virt-manager/virt-manager/stats]
|
||||
enable-disk-poll=true
|
||||
enable-net-poll=true
|
||||
enable-memory-poll=true
|
||||
update-interval=1
|
||||
@@ -27,7 +27,9 @@ def _vm_wrapper(vmname, uri="qemu:///system", opts=None):
|
||||
self.conn = conn
|
||||
extra_opts = (opts or [])
|
||||
extra_opts += ["--show-domain-console", vmname]
|
||||
self.app.open(extra_opts=extra_opts)
|
||||
# Enable stats for more code coverage
|
||||
keyfile = "statsonly.ini"
|
||||
self.app.open(extra_opts=extra_opts, keyfile=keyfile)
|
||||
fn(self, dom, *args, **kwargs)
|
||||
finally:
|
||||
try:
|
||||
|
||||
+26
-29
@@ -112,8 +112,6 @@ class _ObjectList(vmmGObject):
|
||||
if (checkobj.__class__ == obj.__class__ and
|
||||
checkobj.get_name() == obj.get_name()):
|
||||
return False
|
||||
if obj in self._objects:
|
||||
return False
|
||||
|
||||
self._objects.append(obj)
|
||||
return True
|
||||
@@ -249,7 +247,7 @@ class vmmConnection(vmmGObject):
|
||||
if compare_cb():
|
||||
return
|
||||
if (cur_time - start_time) >= timeout:
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
if is_main_thread:
|
||||
if Gtk.events_pending():
|
||||
@@ -311,7 +309,7 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
def host_active_processor_count(self):
|
||||
if not self._backend.is_open() or self._hostinfo is None:
|
||||
return 0
|
||||
return 0 # pragma: no cover
|
||||
return self._hostinfo[2]
|
||||
|
||||
|
||||
@@ -348,21 +346,21 @@ class vmmConnection(vmmGObject):
|
||||
uri = self.get_uri().replace("/", "_")
|
||||
ret = os.path.join(self._backend.get_app_cache_dir(), uri)
|
||||
if not os.path.exists(ret):
|
||||
os.makedirs(ret, 0o755)
|
||||
os.makedirs(ret, 0o755) # pragma: no cover
|
||||
return ret
|
||||
|
||||
def get_default_storage_format(self):
|
||||
raw = self.config.get_default_storage_format(raw=True)
|
||||
if raw != "default":
|
||||
return raw
|
||||
return raw # pragma: no cover
|
||||
|
||||
fmt = self.config.get_default_storage_format()
|
||||
if fmt != "qcow2":
|
||||
return fmt
|
||||
return fmt # pragma: no cover
|
||||
|
||||
if self.support.conn_default_qcow2():
|
||||
return fmt
|
||||
return None
|
||||
return None # pragma: no cover
|
||||
|
||||
|
||||
####################################
|
||||
@@ -582,7 +580,7 @@ class vmmConnection(vmmGObject):
|
||||
log.debug("Error defining new name %s XML",
|
||||
obj.class_name(), exc_info=True)
|
||||
newobj = define_cb(origxml)
|
||||
except Exception as fixerr:
|
||||
except Exception as fixerr: # pragma: no cover
|
||||
log.debug("Failed to redefine original %s!",
|
||||
obj.class_name(), exc_info=True)
|
||||
msg = _("%(object)s rename failed. Attempting to recover also "
|
||||
@@ -622,9 +620,7 @@ class vmmConnection(vmmGObject):
|
||||
log.debug("domain xmlmisc event: domain=%s event=%s args=%s",
|
||||
name, eventstr, args)
|
||||
obj = self.get_vm_by_name(name)
|
||||
if not obj:
|
||||
return
|
||||
|
||||
if obj:
|
||||
self.idle_add(obj.recache_from_event_loop)
|
||||
|
||||
def _domain_lifecycle_event(self, conn, domain, state, reason, userdata):
|
||||
@@ -655,7 +651,7 @@ class vmmConnection(vmmGObject):
|
||||
if obj:
|
||||
self.idle_add(obj.recache_from_event_loop)
|
||||
else:
|
||||
self.schedule_priority_tick(pollvm=True, force=True)
|
||||
self.schedule_priority_tick(pollvm=True, force=True) # pragma: no cover
|
||||
|
||||
def _network_lifecycle_event(self, conn, network, state, reason, userdata):
|
||||
ignore = conn
|
||||
@@ -863,14 +859,14 @@ class vmmConnection(vmmGObject):
|
||||
self._stats = []
|
||||
|
||||
if self._init_object_event:
|
||||
self._init_object_event.clear()
|
||||
self._init_object_event.clear() # pragma: no cover
|
||||
|
||||
for obj in self._objects.all_objects():
|
||||
self._objects.remove(obj)
|
||||
try:
|
||||
self._remove_object_signal(obj)
|
||||
obj.cleanup()
|
||||
except Exception as e: # pramga: no cover
|
||||
except Exception as e: # pragma: no cover
|
||||
log.debug("Failed to cleanup %s: %s", obj, e)
|
||||
self._objects.cleanup()
|
||||
self._objects = _ObjectList()
|
||||
@@ -894,6 +890,9 @@ class vmmConnection(vmmGObject):
|
||||
self._backend.cb_fetch_all_vols = None
|
||||
self._backend.cb_cache_new_pool = None
|
||||
|
||||
self.statsmanager.cleanup()
|
||||
self.statsmanager = None
|
||||
|
||||
def open(self):
|
||||
if not self.is_disconnected():
|
||||
return # pragma: no cover
|
||||
@@ -931,7 +930,7 @@ class vmmConnection(vmmGObject):
|
||||
libvirt_error_message = exc.get_error_message()
|
||||
|
||||
if (libvirt_error_code ==
|
||||
getattr(libvirt, "VIR_ERR_AUTH_CANCELLED", None)):
|
||||
getattr(libvirt, "VIR_ERR_AUTH_CANCELLED", None)): # pragma: no cover
|
||||
log.debug("User cancelled auth, not raising any error.")
|
||||
return False, None
|
||||
|
||||
@@ -999,20 +998,20 @@ class vmmConnection(vmmGObject):
|
||||
log.debug("Building default pool failed: %s", str(e))
|
||||
|
||||
def _open_thread(self):
|
||||
ConnectError = None
|
||||
try:
|
||||
is_active, ConnectError = self._do_open()
|
||||
if is_active:
|
||||
self._populate_initial_state()
|
||||
|
||||
self.idle_add(self._change_state, is_active and
|
||||
self._STATE_ACTIVE or self._STATE_DISCONNECTED)
|
||||
except Exception as e:
|
||||
except Exception as e: # pragma: no cover
|
||||
is_active = False
|
||||
self._schedule_close()
|
||||
ConnectError = connectauth.connect_error(self, str(e),
|
||||
"".join(traceback.format_exc()), False)
|
||||
|
||||
if is_active:
|
||||
self.idle_add(self._change_state, self._STATE_ACTIVE)
|
||||
else:
|
||||
self._schedule_close()
|
||||
|
||||
self.idle_emit("open-completed", ConnectError)
|
||||
|
||||
|
||||
@@ -1041,10 +1040,7 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
for obj in gone_objects:
|
||||
class_name = obj.class_name()
|
||||
try:
|
||||
name = obj.get_name()
|
||||
except Exception:
|
||||
name = str(obj)
|
||||
|
||||
if not self._objects.remove(obj):
|
||||
log.debug("Requested removal of %s=%s, but it's "
|
||||
@@ -1241,7 +1237,8 @@ class vmmConnection(vmmGObject):
|
||||
libvirt.VIR_ERR_SYSTEM_ERROR)):
|
||||
# Try a simple getInfo call to see if conn was dropped
|
||||
self._backend.getInfo()
|
||||
log.debug("vm tick raised system error but "
|
||||
log.debug( # pragma: no cover
|
||||
"vm tick raised system error but "
|
||||
"connection doesn't seem to have dropped. "
|
||||
"Ignoring.")
|
||||
|
||||
@@ -1258,7 +1255,7 @@ class vmmConnection(vmmGObject):
|
||||
expected = self.config.get_stats_history_length()
|
||||
current = len(self._stats)
|
||||
if current > expected:
|
||||
del self._stats[expected:current]
|
||||
del self._stats[expected:current] # pragma: no cover
|
||||
|
||||
mem = 0
|
||||
cpuTime = 0
|
||||
@@ -1339,7 +1336,7 @@ class vmmConnection(vmmGObject):
|
||||
vector = []
|
||||
statslen = self.config.get_stats_history_length() + 1
|
||||
if limit is not None:
|
||||
statslen = min(statslen, limit)
|
||||
statslen = min(statslen, limit) # pragma: no cover
|
||||
|
||||
for i in range(statslen):
|
||||
if i < len(self._stats):
|
||||
@@ -1385,7 +1382,7 @@ class vmmConnection(vmmGObject):
|
||||
def set_config_pretty_name(self, value):
|
||||
cfgname = self._get_config_pretty_name()
|
||||
if value == cfgname:
|
||||
return
|
||||
return # pragma: no cover
|
||||
if not cfgname and value == self.get_pretty_desc():
|
||||
# Don't encode the default connection value into gconf right
|
||||
# away, require the user to edit it first
|
||||
|
||||
@@ -23,26 +23,23 @@ from . import uiutil
|
||||
|
||||
def do_we_have_session():
|
||||
pid = os.getpid()
|
||||
try:
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
except Exception:
|
||||
log.exception("Error getting system bus handle")
|
||||
return
|
||||
|
||||
# Check systemd
|
||||
try:
|
||||
ret = False
|
||||
try: # pragma: no cover
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
manager = Gio.DBusProxy.new_sync(bus, 0, None,
|
||||
"org.freedesktop.login1",
|
||||
"/org/freedesktop/login1",
|
||||
"org.freedesktop.login1.Manager", None)
|
||||
|
||||
ret = manager.GetSessionByPID("(u)", pid)
|
||||
log.debug("Found login1 session=%s", ret)
|
||||
return True
|
||||
except Exception:
|
||||
log.exception("Couldn't connect to logind")
|
||||
# This raises an error exception
|
||||
out = manager.GetSessionByPID("(u)", pid)
|
||||
log.debug("Found login1 session=%s", out)
|
||||
ret = True
|
||||
except Exception: # pragma: no cover
|
||||
log.exception("Failure talking to logind")
|
||||
|
||||
return False
|
||||
return ret
|
||||
|
||||
|
||||
class _vmmConnectAuth(vmmGObjectUI):
|
||||
@@ -152,12 +149,12 @@ def connect_error(conn, errmsg, tb, warnconsole):
|
||||
if conn.is_remote():
|
||||
log.debug("connect_error: conn transport=%s",
|
||||
conn.get_uri_transport())
|
||||
if re.search(r"nc: .* -- 'U'", tb):
|
||||
if re.search(r"nc: .* -- 'U'", tb): # pragma: no cover
|
||||
hint += _("The remote host requires a version of netcat/nc "
|
||||
"which supports the -U option.")
|
||||
show_errmsg = False
|
||||
elif (conn.get_uri_transport() == "ssh" and
|
||||
re.search(r"askpass", tb)):
|
||||
re.search(r"askpass", tb)): # pragma: no cover
|
||||
|
||||
hint += _("Configure SSH key access for the remote host, "
|
||||
"or install an SSH askpass package locally.")
|
||||
@@ -166,7 +163,7 @@ def connect_error(conn, errmsg, tb, warnconsole):
|
||||
hint += _("Verify that the 'libvirtd' daemon is running "
|
||||
"on the remote host.")
|
||||
|
||||
elif conn.is_xen():
|
||||
elif conn.is_xen(): # pragma: no cover
|
||||
hint += _("Verify that:\n"
|
||||
" - A Xen host kernel was booted\n"
|
||||
" - The Xen service has been started")
|
||||
@@ -178,7 +175,7 @@ def connect_error(conn, errmsg, tb, warnconsole):
|
||||
"may not be able to connect to libvirt as a "
|
||||
"regular user. Try running as root.")
|
||||
show_errmsg = False
|
||||
elif re.search(r"libvirt-sock", tb):
|
||||
elif re.search(r"libvirt-sock", tb): # pragma: no cover
|
||||
hint += _("Verify that the 'libvirtd' daemon is running.")
|
||||
show_errmsg = False
|
||||
|
||||
@@ -222,7 +219,7 @@ def _start_libvirtd(config):
|
||||
"org.freedesktop.systemd1.Manager", None)
|
||||
units = systemd.ListUnits()
|
||||
log.debug("Successfully listed units via systemd")
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
units = []
|
||||
log.exception("Couldn't connect to systemd")
|
||||
libvirtd_installed = os.path.exists("/var/run/libvirt")
|
||||
@@ -242,7 +239,7 @@ def _start_libvirtd(config):
|
||||
|
||||
# If it's not running, try to start it
|
||||
try:
|
||||
if unitpath and libvirtd_installed and not libvirtd_active:
|
||||
if unitpath and libvirtd_installed and not libvirtd_active: # pragma: no cover
|
||||
unit = Gio.DBusProxy.new_sync(
|
||||
bus, 0, None,
|
||||
"org.freedesktop.systemd1", unitpath,
|
||||
@@ -251,7 +248,7 @@ def _start_libvirtd(config):
|
||||
unit.Start("(s)", "fail")
|
||||
time.sleep(2)
|
||||
libvirtd_active = True
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
log.exception("Error starting libvirtd")
|
||||
|
||||
return libvirtd_installed, libvirtd_active
|
||||
@@ -268,17 +265,17 @@ def setup_first_uri(config, tryuri):
|
||||
|
||||
# Manager fail message
|
||||
msg = ""
|
||||
if not libvirtd_installed:
|
||||
if not libvirtd_installed: # pragma: no cover
|
||||
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:
|
||||
elif not libvirtd_active: # pragma: no cover
|
||||
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 += "\n\n" # pragma: no cover
|
||||
msg += _("Could not detect a default hypervisor. Make "
|
||||
"sure the appropriate QEMU/KVM virtualization "
|
||||
"packages are installed to manage virtualization "
|
||||
|
||||
Reference in New Issue
Block a user