mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-03-09 08:58:27 +03:00
testmock: Split apart the first-run option
Break it into disable-libguestfs, fake-systemd-success, and firstrun-uri suboptions, and adjust using code to match Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
7769d9a1e4
commit
b0294a1bc6
@ -127,13 +127,14 @@ class VMMCLI(uiutils.UITestCase):
|
|||||||
|
|
||||||
def testCLINoFirstRun(self):
|
def testCLINoFirstRun(self):
|
||||||
# Test a simple case of loading without any config override
|
# Test a simple case of loading without any config override
|
||||||
self.app.open(first_run=False, use_uri=False)
|
self.app.open(first_run=False, enable_libguestfs=None, use_uri=False)
|
||||||
self.sleep(2)
|
self.sleep(2)
|
||||||
uiutils.check(lambda: self.app.topwin.showing)
|
uiutils.check(lambda: self.app.topwin.showing)
|
||||||
|
|
||||||
def testCLINoFork(self):
|
def testCLINoFork(self):
|
||||||
# Test app without forking
|
# Test app without forking
|
||||||
self.app.open(first_run=False, use_uri=False, no_fork=False)
|
self.app.open(first_run=False, enable_libguestfs=None,
|
||||||
|
use_uri=False, no_fork=False)
|
||||||
assert self.app.wait_for_exit() is True
|
assert self.app.wait_for_exit() is True
|
||||||
uiutils.check(lambda: self.app.topwin.showing)
|
uiutils.check(lambda: self.app.topwin.showing)
|
||||||
self.app.topwin.keyCombo("<alt>F4")
|
self.app.topwin.keyCombo("<alt>F4")
|
||||||
|
@ -28,7 +28,7 @@ class VMMInspection(uiutils.UITestCase):
|
|||||||
|
|
||||||
# Use the test suite inspection mocking to test parts
|
# Use the test suite inspection mocking to test parts
|
||||||
# of the UI that interact with inspection data
|
# of the UI that interact with inspection data
|
||||||
self.app.open(extra_opts=["--test-options=config-libguestfs"])
|
self.app.open(enable_libguestfs=True)
|
||||||
details = self._open_details_window("test-clone")
|
details = self._open_details_window("test-clone")
|
||||||
details.find("OS information", "table cell").click()
|
details.find("OS information", "table cell").click()
|
||||||
tab = details.find("os-tab")
|
tab = details.find("os-tab")
|
||||||
|
@ -543,7 +543,8 @@ class VMMDogtailApp(object):
|
|||||||
def open(self, extra_opts=None, check_already_running=True, use_uri=True,
|
def open(self, extra_opts=None, check_already_running=True, use_uri=True,
|
||||||
window_name=None, xmleditor_enabled=False, keyfile=None,
|
window_name=None, xmleditor_enabled=False, keyfile=None,
|
||||||
break_setfacl=False, first_run=True, no_fork=True,
|
break_setfacl=False, first_run=True, no_fork=True,
|
||||||
will_fail=False):
|
will_fail=False, enable_libguestfs=False,
|
||||||
|
firstrun_uri=None, fake_systemd_success=True):
|
||||||
extra_opts = extra_opts or []
|
extra_opts = extra_opts or []
|
||||||
|
|
||||||
if tests.utils.TESTCONFIG.debug and no_fork:
|
if tests.utils.TESTCONFIG.debug and no_fork:
|
||||||
@ -558,16 +559,25 @@ class VMMDogtailApp(object):
|
|||||||
cmd += [os.path.join(os.getcwd(), "virt-manager")]
|
cmd += [os.path.join(os.getcwd(), "virt-manager")]
|
||||||
if no_fork:
|
if no_fork:
|
||||||
cmd += ["--no-fork"]
|
cmd += ["--no-fork"]
|
||||||
if first_run:
|
|
||||||
cmd += ["--test-first-run"]
|
|
||||||
if use_uri:
|
if use_uri:
|
||||||
cmd += ["--connect", self.uri]
|
cmd += ["--connect", self.uri]
|
||||||
|
|
||||||
testoptions = []
|
if first_run:
|
||||||
|
cmd.append("--test-options=first-run")
|
||||||
|
if not firstrun_uri:
|
||||||
|
firstrun_uri = ""
|
||||||
|
if firstrun_uri is not None:
|
||||||
|
cmd.append("--test-options=firstrun-uri=%s" % firstrun_uri)
|
||||||
if xmleditor_enabled:
|
if xmleditor_enabled:
|
||||||
testoptions.append("xmleditor-enabled")
|
cmd.append("--test-options=xmleditor-enabled")
|
||||||
if break_setfacl:
|
if break_setfacl:
|
||||||
testoptions.append("break-setfacl")
|
cmd.append("--test-options=break-setfacl")
|
||||||
|
if enable_libguestfs is True:
|
||||||
|
cmd.append("--test-options=enable-libguestfs")
|
||||||
|
if enable_libguestfs is False:
|
||||||
|
cmd.append("--test-options=disable-libguestfs")
|
||||||
|
if fake_systemd_success:
|
||||||
|
cmd.append("--test-options=fake-systemd-success")
|
||||||
if keyfile:
|
if keyfile:
|
||||||
import atexit
|
import atexit
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -575,10 +585,8 @@ class VMMDogtailApp(object):
|
|||||||
tempname = tempfile.mktemp(prefix="virtmanager-uitests-keyfile")
|
tempname = tempfile.mktemp(prefix="virtmanager-uitests-keyfile")
|
||||||
open(tempname, "w").write(open(keyfile).read())
|
open(tempname, "w").write(open(keyfile).read())
|
||||||
atexit.register(lambda: os.unlink(tempname))
|
atexit.register(lambda: os.unlink(tempname))
|
||||||
testoptions.append("gsettings-keyfile=%s" % tempname)
|
cmd.append("--test-options=gsettings-keyfile=%s" % tempname)
|
||||||
|
|
||||||
if testoptions:
|
|
||||||
cmd += ["--test-options=%s" % ",".join(testoptions)]
|
|
||||||
cmd += extra_opts
|
cmd += extra_opts
|
||||||
|
|
||||||
if check_already_running:
|
if check_already_running:
|
||||||
|
@ -206,6 +206,10 @@ class vmmConfig(object):
|
|||||||
self.CLITestOptions = CLITestOptions
|
self.CLITestOptions = CLITestOptions
|
||||||
if self.CLITestOptions.xmleditor_enabled:
|
if self.CLITestOptions.xmleditor_enabled:
|
||||||
self.set_xmleditor_enabled(True)
|
self.set_xmleditor_enabled(True)
|
||||||
|
if self.CLITestOptions.enable_libguestfs:
|
||||||
|
self.set_libguestfs_inspect_vms(True)
|
||||||
|
if self.CLITestOptions.disable_libguestfs:
|
||||||
|
self.set_libguestfs_inspect_vms(False)
|
||||||
|
|
||||||
# We don't create it straight away, since we don't want
|
# We don't create it straight away, since we don't want
|
||||||
# to block the app pending user authorization to access
|
# to block the app pending user authorization to access
|
||||||
@ -426,10 +430,6 @@ class vmmConfig(object):
|
|||||||
|
|
||||||
# Libguestfs VM inspection
|
# Libguestfs VM inspection
|
||||||
def get_libguestfs_inspect_vms(self):
|
def get_libguestfs_inspect_vms(self):
|
||||||
if self.CLITestOptions.config_libguestfs:
|
|
||||||
return True
|
|
||||||
if self.CLITestOptions.first_run:
|
|
||||||
return False
|
|
||||||
return self.conf.get("/enable-libguestfs-vm-inspection")
|
return self.conf.get("/enable-libguestfs-vm-inspection")
|
||||||
def set_libguestfs_inspect_vms(self, val):
|
def set_libguestfs_inspect_vms(self, val):
|
||||||
self.conf.set("/enable-libguestfs-vm-inspection", val)
|
self.conf.set("/enable-libguestfs-vm-inspection", val)
|
||||||
|
@ -133,9 +133,9 @@ class vmmEngine(vmmGObject):
|
|||||||
|
|
||||||
tryuri = vmmCreateConn.default_uri()
|
tryuri = vmmCreateConn.default_uri()
|
||||||
log.debug("Probed default URI=%s", tryuri)
|
log.debug("Probed default URI=%s", tryuri)
|
||||||
if self.config.CLITestOptions.first_run:
|
if self.config.CLITestOptions.firstrun_uri is not None:
|
||||||
log.debug("--test-first-run, using uri=None to trigger error")
|
tryuri = self.config.CLITestOptions.firstrun_uri or None
|
||||||
tryuri = None
|
log.debug("Using test-options firstrun_uri=%s", tryuri)
|
||||||
|
|
||||||
manager = self._get_manager()
|
manager = self._get_manager()
|
||||||
msg = connectauth.setup_first_uri(self.config, tryuri)
|
msg = connectauth.setup_first_uri(self.config, tryuri)
|
||||||
|
@ -246,7 +246,7 @@ def _start_libvirtd(config):
|
|||||||
bus, 0, None,
|
bus, 0, None,
|
||||||
"org.freedesktop.systemd1", unitpath,
|
"org.freedesktop.systemd1", unitpath,
|
||||||
"org.freedesktop.systemd1.Unit", None)
|
"org.freedesktop.systemd1.Unit", None)
|
||||||
if not config.CLITestOptions.first_run:
|
if config.CLITestOptions.fake_systemd_success:
|
||||||
unit.Start("(s)", "fail")
|
unit.Start("(s)", "fail")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
libvirtd_active = True
|
libvirtd_active = True
|
||||||
@ -258,6 +258,9 @@ def _start_libvirtd(config):
|
|||||||
|
|
||||||
def setup_first_uri(config, tryuri):
|
def setup_first_uri(config, tryuri):
|
||||||
libvirtd_installed, libvirtd_active = _start_libvirtd(config)
|
libvirtd_installed, libvirtd_active = _start_libvirtd(config)
|
||||||
|
if config.CLITestOptions.fake_systemd_success:
|
||||||
|
libvirtd_installed = True
|
||||||
|
libvirtd_active = True
|
||||||
|
|
||||||
if tryuri and libvirtd_installed and libvirtd_active:
|
if tryuri and libvirtd_installed and libvirtd_active:
|
||||||
return
|
return
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
# This work is licensed under the GNU GPLv2 or later.
|
# This work is licensed under the GNU GPLv2 or later.
|
||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
|
# This file is a collection of code used for testing
|
||||||
|
# code paths primarily via our uitests/
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def fake_job_info():
|
def fake_job_info():
|
||||||
import random
|
import random
|
||||||
@ -62,12 +67,13 @@ class CLITestOptionsClass:
|
|||||||
Helper class for parsing and tracking --test-* options.
|
Helper class for parsing and tracking --test-* options.
|
||||||
The suboptions are:
|
The suboptions are:
|
||||||
|
|
||||||
* first-run: Run the app with fresh gsettings values and
|
* first-run: Run the app with fresh gsettings values saved to
|
||||||
no config changes saved to disk, among a few other tweaks.
|
a keyfile, mimicking a first app run. Also sets
|
||||||
Heavily used by the UI test suite.
|
GSETTINGS to use memory backend, in case any other app
|
||||||
|
preferences would be affected. The ui testsuite sets this
|
||||||
|
for most tests.
|
||||||
|
|
||||||
* xmleditor-enabled: Force the xmleditor preference on if
|
* xmleditor-enabled: Force the xmleditor gsettings preference on.
|
||||||
using first-run. Used by the test suite
|
|
||||||
|
|
||||||
* gsettings-keyfile: Override the gsettings values with those
|
* gsettings-keyfile: Override the gsettings values with those
|
||||||
from the passed in keyfile, to test with different default
|
from the passed in keyfile, to test with different default
|
||||||
@ -88,8 +94,8 @@ class CLITestOptionsClass:
|
|||||||
This is hit via the directory search permissions checking
|
This is hit via the directory search permissions checking
|
||||||
for disk image usage for qemu
|
for disk image usage for qemu
|
||||||
|
|
||||||
* config-libguestfs: Override the first-run default of
|
* enable-libguestfs: Force enable the libguestfs gsetting
|
||||||
disabling libguestfs support, so it is enabled
|
* disable-libguestfs: Force disable the libguestfs gsetting
|
||||||
|
|
||||||
* test-managed-save: Triggers a couple conditions for testing
|
* test-managed-save: Triggers a couple conditions for testing
|
||||||
managed save issues
|
managed save issues
|
||||||
@ -97,16 +103,19 @@ class CLITestOptionsClass:
|
|||||||
* test-vm-run-fail: Make VM run fail, so we can test the error path
|
* test-vm-run-fail: Make VM run fail, so we can test the error path
|
||||||
|
|
||||||
* spice-agent: Make spice-agent detection return true in viewer.py
|
* spice-agent: Make spice-agent detection return true in viewer.py
|
||||||
|
|
||||||
|
* firstrun-uri: If set, use this as the initial connection URI
|
||||||
|
if we are doing firstrun testing
|
||||||
|
* fake-systemd-success: If doing firstrun testing, fake that
|
||||||
|
systemd checks for libvirtd succeeded
|
||||||
"""
|
"""
|
||||||
def __init__(self, test_options_str, test_first_run):
|
def __init__(self, test_options_str):
|
||||||
optset = set()
|
optset = set()
|
||||||
for optstr in test_options_str:
|
for optstr in test_options_str:
|
||||||
optset.update(set(optstr.split(",")))
|
optset.update(set(optstr.split(",")))
|
||||||
|
|
||||||
self._parse(optset)
|
first_run = self._parse(optset)
|
||||||
if test_first_run:
|
self._process(first_run)
|
||||||
self.first_run = True
|
|
||||||
self._process()
|
|
||||||
|
|
||||||
def _parse(self, optset):
|
def _parse(self, optset):
|
||||||
def _get(optname):
|
def _get(optname):
|
||||||
@ -121,25 +130,33 @@ class CLITestOptionsClass:
|
|||||||
optset.remove(opt)
|
optset.remove(opt)
|
||||||
return opt.split("=", 1)[1]
|
return opt.split("=", 1)[1]
|
||||||
|
|
||||||
self.first_run = _get("first-run")
|
first_run = _get("first-run")
|
||||||
self.leak_debug = _get("leak-debug")
|
self.leak_debug = _get("leak-debug")
|
||||||
self.no_events = _get("no-events")
|
self.no_events = _get("no-events")
|
||||||
self.xmleditor_enabled = _get("xmleditor-enabled")
|
self.xmleditor_enabled = _get("xmleditor-enabled")
|
||||||
self.gsettings_keyfile = _get_value("gsettings-keyfile")
|
self.gsettings_keyfile = _get_value("gsettings-keyfile")
|
||||||
self.break_setfacl = _get("break-setfacl")
|
self.break_setfacl = _get("break-setfacl")
|
||||||
self.config_libguestfs = _get("config-libguestfs")
|
self.disable_libguestfs = _get("disable-libguestfs")
|
||||||
|
self.enable_libguestfs = _get("enable-libguestfs")
|
||||||
self.test_managed_save = _get("test-managed-save")
|
self.test_managed_save = _get("test-managed-save")
|
||||||
self.test_vm_run_fail = _get("test-vm-run-fail")
|
self.test_vm_run_fail = _get("test-vm-run-fail")
|
||||||
self.spice_agent = _get("spice-agent")
|
self.spice_agent = _get("spice-agent")
|
||||||
|
self.firstrun_uri = _get_value("firstrun-uri")
|
||||||
|
self.fake_systemd_success = _get("fake-systemd-success")
|
||||||
|
|
||||||
if optset: # pragma: no cover
|
if optset: # pragma: no cover
|
||||||
raise RuntimeError("Unknown --test-options keys: %s" % optset)
|
raise RuntimeError("Unknown --test-options keys: %s" % optset)
|
||||||
|
|
||||||
def _process(self):
|
return first_run
|
||||||
if self.first_run and not self.gsettings_keyfile:
|
|
||||||
|
def _process(self, first_run):
|
||||||
|
if first_run:
|
||||||
|
# So other settings like gtk are reset and not affected
|
||||||
|
os.environ["GSETTINGS_BACKEND"] = "memory"
|
||||||
|
|
||||||
|
if first_run and not self.gsettings_keyfile:
|
||||||
import atexit
|
import atexit
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
|
||||||
filename = tempfile.mktemp(prefix="virtmanager-firstrun-keyfile")
|
filename = tempfile.mktemp(prefix="virtmanager-firstrun-keyfile")
|
||||||
self.gsettings_keyfile = filename
|
self.gsettings_keyfile = filename
|
||||||
atexit.register(lambda: os.unlink(filename))
|
atexit.register(lambda: os.unlink(filename))
|
||||||
|
@ -131,11 +131,6 @@ def parse_commandline():
|
|||||||
parser.add_argument("--trace-libvirt", choices=["all", "mainloop"],
|
parser.add_argument("--trace-libvirt", choices=["all", "mainloop"],
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
# Don't load any connections on startup to test first run
|
|
||||||
# PackageKit integration
|
|
||||||
parser.add_argument("--test-first-run",
|
|
||||||
help=argparse.SUPPRESS, action="store_true")
|
|
||||||
|
|
||||||
# comma separated string of options to tweak app behavior,
|
# comma separated string of options to tweak app behavior,
|
||||||
# for manual and automated testing config
|
# for manual and automated testing config
|
||||||
parser.add_argument("--test-options", action='append',
|
parser.add_argument("--test-options", action='append',
|
||||||
@ -184,13 +179,10 @@ def main():
|
|||||||
mainloop=(options.trace_libvirt == "mainloop"),
|
mainloop=(options.trace_libvirt == "mainloop"),
|
||||||
regex=None)
|
regex=None)
|
||||||
|
|
||||||
CLITestOptions = CLITestOptionsClass(options.test_options,
|
CLITestOptions = CLITestOptionsClass(options.test_options)
|
||||||
options.test_first_run)
|
|
||||||
|
|
||||||
# With F27 gnome+wayland we need to set these before GTK import
|
# With F27 gnome+wayland we need to set these before GTK import
|
||||||
os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir
|
os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir
|
||||||
if CLITestOptions.first_run:
|
|
||||||
os.environ["GSETTINGS_BACKEND"] = "memory"
|
|
||||||
|
|
||||||
# Now we've got basic environment up & running we can fork
|
# Now we've got basic environment up & running we can fork
|
||||||
do_drop_stdio = False
|
do_drop_stdio = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user