diff options
-rwxr-xr-x | virt-manager | 52 | ||||
-rw-r--r-- | virtManager/config.py | 8 | ||||
-rw-r--r-- | virtManager/connection.py | 23 | ||||
-rw-r--r-- | virtManager/engine.py | 6 |
4 files changed, 59 insertions, 30 deletions
diff --git a/virt-manager b/virt-manager index 46838838..8a5b9e17 100755 --- a/virt-manager +++ b/virt-manager @@ -145,6 +145,10 @@ def parse_commandline(): parser.add_argument("--test-leak-debug", help=argparse.SUPPRESS, action="store_true") + # comma separated string of options to tweak app behavior, + # for manual and automated testing config + parser.add_argument("--test-options", help=argparse.SUPPRESS) + parser.add_argument("-c", "--connect", dest="uri", help="Connect to hypervisor at URI", metavar="URI") parser.add_argument("--debug", action="store_true", @@ -169,6 +173,31 @@ def parse_commandline(): return parser.parse_known_args() +class CLITestOptionsClass: + """ + Helper class for parsing and tracking --test-* options + """ + def __init__(self, test_options_str): + opts = [] + if test_options_str: + opts = test_options_str.split(",") + + def _get(optname): + if optname not in opts: + return False + opts.remove(optname) + return True + + self.first_run = _get("first-run") + self.leak_debug = _get("leak-debug") + self.old_poll = _get("old-poll") + self.no_events = _get("no-events") + + if opts: + print("Unknown --test-options keys: %s" % opts) + sys.exit(1) + + def main(): (options, leftovers) = parse_commandline() @@ -186,9 +215,19 @@ def main(): mainloop=(options.trace_libvirt == "mainloop"), regex=None) + CLITestOptions = CLITestOptionsClass(options.test_options) + if options.test_first_run: + CLITestOptions.first_run = True + if options.test_leak_debug: + CLITestOptions.leak_debug = True + if options.test_no_events: + CLITestOptions.no_events = True + if options.test_old_poll: + CLITestOptions.old_poll = True + # With F27 gnome+wayland we need to set these before GTK import os.environ["GSETTINGS_SCHEMA_DIR"] = CLIConfig.gsettings_dir - if options.test_first_run: + if CLITestOptions.first_run: os.environ["GSETTINGS_BACKEND"] = "memory" # Now we've got basic environment up & running we can fork @@ -219,16 +258,14 @@ def main(): Gtk.get_minor_version(), Gtk.get_micro_version()) - config = virtManager.config.vmmConfig.get_instance(CLIConfig, - options.test_first_run) - config.test_leak_debug = options.test_leak_debug - if not util.local_libvirt_version() >= 6000: # We need this version for threaded virConnect access _show_startup_error( _("virt-manager requires libvirt 0.6.0 or later."), "") return + # Prime the vmmConfig cache + virtManager.config.vmmConfig.get_instance(CLIConfig, CLITestOptions) # Add our icon dir to icon theme icon_theme = Gtk.IconTheme.get_default() @@ -238,11 +275,8 @@ def main(): Gtk.Window.set_default_icon_name("virt-manager") - import virtManager.connection - virtManager.connection.FORCE_DISABLE_EVENTS = bool(options.test_no_events) - import virtinst.pollhelpers - virtinst.pollhelpers.FORCE_OLD_POLL = bool(options.test_old_poll) + virtinst.pollhelpers.FORCE_OLD_POLL = CLITestOptions.old_poll show_window = None domain = None diff --git a/virtManager/config.py b/virtManager/config.py index eb0b756f..216725f5 100644 --- a/virtManager/config.py +++ b/virtManager/config.py @@ -160,16 +160,16 @@ class vmmConfig(object): def is_initialized(cls): return bool(cls._instance) - def __init__(self, CLIConfig, test_first_run): + def __init__(self, CLIConfig, CLITestOptions): self.appname = "virt-manager" self.appversion = CLIConfig.version self.conf_dir = "/org/virt-manager/%s/" % self.appname self.ui_dir = CLIConfig.ui_dir - self.test_first_run = bool(test_first_run) - self.test_leak_debug = False self.conf = _SettingsWrapper("org.virt-manager.virt-manager") + self.CLITestOptions = CLITestOptions + # We don't create it straight away, since we don't want # to block the app pending user authorization to access # the keyring @@ -368,7 +368,7 @@ class vmmConfig(object): def on_libguestfs_inspect_vms_changed(self, cb): return self.conf.notify_add("/enable-libguestfs-vm-inspection", cb) def get_libguestfs_inspect_vms(self): - if self.test_first_run: + if self.CLITestOptions.first_run: return False return self.conf.get("/enable-libguestfs-vm-inspection") def set_libguestfs_inspect_vms(self, val): diff --git a/virtManager/connection.py b/virtManager/connection.py index 1ab434ff..e86e458f 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -27,11 +27,6 @@ from .statsmanager import vmmStatsManager from .storagepool import vmmStoragePool -# debugging helper to turn off events -# Can be enabled with virt-manager --test-no-events -FORCE_DISABLE_EVENTS = False - - class _ObjectList(vmmGObject): """ Class that wraps our internal list of libvirt objects @@ -819,9 +814,12 @@ class vmmConnection(vmmGObject): self._backend.SUPPORT_CONN_WORKING_XEN_EVENTS): return + def _check_events_disabled(): + if self.config.CLITestOptions.no_events: + raise RuntimeError("events disabled via cli") + try: - if FORCE_DISABLE_EVENTS: - raise RuntimeError("FORCE_DISABLE_EVENTS = True") + _check_events_disabled() self._domain_cb_ids.append( self.get_backend().domainEventRegisterAny( @@ -855,8 +853,7 @@ class vmmConnection(vmmGObject): self._domain_agent_lifecycle_event) try: - if FORCE_DISABLE_EVENTS: - raise RuntimeError("FORCE_DISABLE_EVENTS = True") + _check_events_disabled() eventid = getattr(libvirt, "VIR_NETWORK_EVENT_ID_LIFECYCLE", 0) self._network_cb_ids.append( @@ -869,8 +866,7 @@ class vmmConnection(vmmGObject): logging.debug("Error registering network events: %s", e) try: - if FORCE_DISABLE_EVENTS: - raise RuntimeError("FORCE_DISABLE_EVENTS = True") + _check_events_disabled() eventid = getattr(libvirt, "VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE", 0) @@ -889,8 +885,7 @@ class vmmConnection(vmmGObject): logging.debug("Error registering storage pool events: %s", e) try: - if FORCE_DISABLE_EVENTS: - raise RuntimeError("FORCE_DISABLE_EVENTS = True") + _check_events_disabled() eventid = getattr(libvirt, "VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE", 0) updateid = getattr(libvirt, "VIR_NODE_DEVICE_EVENT_ID_UPDATE", 1) @@ -956,7 +951,7 @@ class vmmConnection(vmmGObject): self._objects = _ObjectList() closeret = self._backend.close() - if closeret == 1 and self.config.test_leak_debug: + if closeret == 1 and self.config.CLITestOptions.leak_debug: logging.debug("LEAK: conn close() returned 1, " "meaning refs may have leaked.") diff --git a/virtManager/engine.py b/virtManager/engine.py index 3d9ca7d3..564b44a8 100644 --- a/virtManager/engine.py +++ b/virtManager/engine.py @@ -172,14 +172,14 @@ class vmmEngine(vmmGObject): bus, 0, None, "org.freedesktop.systemd1", unitpath, "org.freedesktop.systemd1.Unit", None) - if not self.config.test_first_run: + if not self.config.CLITestOptions.first_run: unit.Start("(s)", "fail") time.sleep(2) libvirtd_active = True except Exception: logging.exception("Error starting libvirtd") - if self.config.test_first_run: + if self.config.CLITestOptions.first_run: logging.debug("--test-first-run, using uri=None to trigger error") tryuri = None else: @@ -432,7 +432,7 @@ class vmmEngine(vmmGObject): self.emit("app-closing") self.cleanup() - if self.config.test_leak_debug: + if self.config.CLITestOptions.leak_debug: objs = self.config.get_objects() # Engine will always appear to leak objs.remove(self.object_key) |