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:
Cole Robinson 2020-08-29 13:07:19 -04:00
parent 7769d9a1e4
commit b0294a1bc6
8 changed files with 67 additions and 46 deletions

View File

@ -127,13 +127,14 @@ class VMMCLI(uiutils.UITestCase):
def testCLINoFirstRun(self):
# 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)
uiutils.check(lambda: self.app.topwin.showing)
def testCLINoFork(self):
# 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
uiutils.check(lambda: self.app.topwin.showing)
self.app.topwin.keyCombo("<alt>F4")

View File

@ -28,7 +28,7 @@ class VMMInspection(uiutils.UITestCase):
# Use the test suite inspection mocking to test parts
# 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.find("OS information", "table cell").click()
tab = details.find("os-tab")

View File

@ -543,7 +543,8 @@ class VMMDogtailApp(object):
def open(self, extra_opts=None, check_already_running=True, use_uri=True,
window_name=None, xmleditor_enabled=False, keyfile=None,
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 []
if tests.utils.TESTCONFIG.debug and no_fork:
@ -558,16 +559,25 @@ class VMMDogtailApp(object):
cmd += [os.path.join(os.getcwd(), "virt-manager")]
if no_fork:
cmd += ["--no-fork"]
if first_run:
cmd += ["--test-first-run"]
if use_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:
testoptions.append("xmleditor-enabled")
cmd.append("--test-options=xmleditor-enabled")
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:
import atexit
import tempfile
@ -575,10 +585,8 @@ class VMMDogtailApp(object):
tempname = tempfile.mktemp(prefix="virtmanager-uitests-keyfile")
open(tempname, "w").write(open(keyfile).read())
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
if check_already_running:

View File

@ -206,6 +206,10 @@ class vmmConfig(object):
self.CLITestOptions = CLITestOptions
if self.CLITestOptions.xmleditor_enabled:
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
# to block the app pending user authorization to access
@ -426,10 +430,6 @@ class vmmConfig(object):
# Libguestfs VM inspection
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")
def set_libguestfs_inspect_vms(self, val):
self.conf.set("/enable-libguestfs-vm-inspection", val)

View File

@ -133,9 +133,9 @@ class vmmEngine(vmmGObject):
tryuri = vmmCreateConn.default_uri()
log.debug("Probed default URI=%s", tryuri)
if self.config.CLITestOptions.first_run:
log.debug("--test-first-run, using uri=None to trigger error")
tryuri = None
if self.config.CLITestOptions.firstrun_uri is not None:
tryuri = self.config.CLITestOptions.firstrun_uri or None
log.debug("Using test-options firstrun_uri=%s", tryuri)
manager = self._get_manager()
msg = connectauth.setup_first_uri(self.config, tryuri)

View File

@ -246,7 +246,7 @@ def _start_libvirtd(config):
bus, 0, None,
"org.freedesktop.systemd1", unitpath,
"org.freedesktop.systemd1.Unit", None)
if not config.CLITestOptions.first_run:
if config.CLITestOptions.fake_systemd_success:
unit.Start("(s)", "fail")
time.sleep(2)
libvirtd_active = True
@ -258,6 +258,9 @@ def _start_libvirtd(config):
def setup_first_uri(config, tryuri):
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:
return

View File

@ -3,6 +3,11 @@
# This work is licensed under the GNU GPLv2 or later.
# 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():
import random
@ -62,12 +67,13 @@ class CLITestOptionsClass:
Helper class for parsing and tracking --test-* options.
The suboptions are:
* first-run: Run the app with fresh gsettings values and
no config changes saved to disk, among a few other tweaks.
Heavily used by the UI test suite.
* first-run: Run the app with fresh gsettings values saved to
a keyfile, mimicking a first app run. Also sets
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
using first-run. Used by the test suite
* xmleditor-enabled: Force the xmleditor gsettings preference on.
* gsettings-keyfile: Override the gsettings values with those
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
for disk image usage for qemu
* config-libguestfs: Override the first-run default of
disabling libguestfs support, so it is enabled
* enable-libguestfs: Force enable the libguestfs gsetting
* disable-libguestfs: Force disable the libguestfs gsetting
* test-managed-save: Triggers a couple conditions for testing
managed save issues
@ -97,16 +103,19 @@ class CLITestOptionsClass:
* 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
* 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()
for optstr in test_options_str:
optset.update(set(optstr.split(",")))
self._parse(optset)
if test_first_run:
self.first_run = True
self._process()
first_run = self._parse(optset)
self._process(first_run)
def _parse(self, optset):
def _get(optname):
@ -121,25 +130,33 @@ class CLITestOptionsClass:
optset.remove(opt)
return opt.split("=", 1)[1]
self.first_run = _get("first-run")
first_run = _get("first-run")
self.leak_debug = _get("leak-debug")
self.no_events = _get("no-events")
self.xmleditor_enabled = _get("xmleditor-enabled")
self.gsettings_keyfile = _get_value("gsettings-keyfile")
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_vm_run_fail = _get("test-vm-run-fail")
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
raise RuntimeError("Unknown --test-options keys: %s" % optset)
def _process(self):
if self.first_run and not self.gsettings_keyfile:
return first_run
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 tempfile
import os
filename = tempfile.mktemp(prefix="virtmanager-firstrun-keyfile")
self.gsettings_keyfile = filename
atexit.register(lambda: os.unlink(filename))

View File

@ -131,11 +131,6 @@ def parse_commandline():
parser.add_argument("--trace-libvirt", choices=["all", "mainloop"],
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,
# for manual and automated testing config
parser.add_argument("--test-options", action='append',
@ -184,13 +179,10 @@ def main():
mainloop=(options.trace_libvirt == "mainloop"),
regex=None)
CLITestOptions = CLITestOptionsClass(options.test_options,
options.test_first_run)
CLITestOptions = CLITestOptionsClass(options.test_options)
# With F27 gnome+wayland we need to set these before GTK import
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
do_drop_stdio = False