diff options
author | Cole Robinson <crobinso@redhat.com> | 2018-10-11 12:14:19 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2018-10-11 12:19:48 -0400 |
commit | 3e55e89453d9edf127d0242492ea34c5a24dc5b0 (patch) | |
tree | 71269f41d53d014b3646599bdaa37e5b5c6f987b | |
parent | 63b4d1f154652119ee9ff5559ce090ec005daa7d (diff) | |
download | virt-manager-3e55e89453d9edf127d0242492ea34c5a24dc5b0.tar.gz |
tests: Add better virt-install console testing
-rw-r--r-- | tests/clitest.py | 27 | ||||
-rwxr-xr-x | virt-install | 22 | ||||
-rw-r--r-- | virtinst/cli.py | 11 |
3 files changed, 36 insertions, 24 deletions
diff --git a/tests/clitest.py b/tests/clitest.py index 59b84b2d..5d6fb538 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -84,6 +84,7 @@ class Command(object): self.skip_check = None self.check_version = None + self.grep = None app, opts = self.cmdstr.split(" ", 1) self.app = app @@ -183,13 +184,20 @@ class Command(object): code, output = self._get_output(conn) - if bool(code) == self.check_success: + def _raise_error(_msg): raise AssertionError( - ("Expected command to %s, but it didn't.\n" % - (self.check_success and "pass" or "fail")) + ("Command was: %s\n" % self.cmdstr) + ("Error code : %d\n" % code) + - ("Output was:\n%s" % output)) + ("Output was:\n%s" % output) + + ("\n\n\nTESTSUITE: " + _msg + "\n")) + + + if bool(code) == self.check_success: + _raise_error("Expected command to %s, but it didn't.\n" % + (self.check_success and "pass" or "fail")) + + if self.grep and self.grep not in output: + _raise_error("Didn't find grep=%s" % self.grep) if self.compare_file: if self._check_support(tests, conn, self.check_version, @@ -285,7 +293,7 @@ class App(object): def _add(self, catname, testargs, valid, compfile, skip_check=None, check_version=None, input_file=None, - auto_printarg=True): + auto_printarg=True, grep=None): category = self.categories[catname] args = category.default_args + " " + testargs @@ -304,6 +312,7 @@ class App(object): category.check_version or self.check_version) cmd.input_file = input_file + cmd.grep = grep self.cmds.append(cmd) def add_valid(self, cat, args, **kwargs): @@ -814,10 +823,10 @@ c.add_valid("--file %(EXISTIMG1)s --file %(EXISTIMG1)s") # Multiple existing fi c.add_valid("--file %(NEWIMG1)s --file-size .00001 --nonsparse") # Nonexistent file c = vinst.add_category("console-tests", "--pxe --nodisks") -c.add_valid("--nographics") # mock virsh console waiting -c.add_valid("--graphics vnc --noreboot") # mock virt-viewer waiting, with noreboot magic -c.add_invalid("--noautoconsole --wait 1") # --wait 1 is converted to 1 second if we are in the test suite, so this should actually touch the wait machinery. however in this case it exits with failure -c.add_valid("--nographics --transient") # --transient handling +c.add_valid("", grep="testsuite console command: ['virt-viewer'") # mock default graphics+virt-viewer usage +c.add_valid("--graphics vnc --noreboot", grep="testsuite console command: ['virt-viewer'") # mock virt-viewer waiting, with noreboot magic +c.add_invalid("--noautoconsole --wait 1", grep="Installation has exceeded specified time limit") # --wait 1 is converted to 1 second if we are in the test suite, so this should actually touch the wait machinery. however in this case it exits with failure +c.add_valid("--nographics --transient", grep="testsuite console command: ['virsh'") # --transient handling diff --git a/virt-install b/virt-install index 173ceb12..51307e20 100755 --- a/virt-install +++ b/virt-install @@ -7,7 +7,6 @@ import argparse import logging -import os import sys import time @@ -558,9 +557,6 @@ def start_install(guest, installer, options): if options.wait is not None: wait_on_install = True wait_time = options.wait * 60 - if "VIRTINST_TEST_SUITE" in os.environ and wait_time: - # Convert wait time to 1 second, for the test suite - wait_time = 1 else: wait_on_install = False wait_time = -1 @@ -692,14 +688,20 @@ def check_domain(installer, domain, conscb, transient, print_stdout(_("Domain has shutdown. Continuing.")) break - time.sleep(1) + if not cli.in_testsuite(): + time.sleep(1) time_elapsed = (time.time() - start_time) - if not wait_forever and time_elapsed >= wait_time: - print_stdout( - _("Installation has exceeded specified time limit. " - "Exiting application.")) - sys.exit(1) + if not cli.in_testsuite(): + if wait_forever: + continue + if time_elapsed < wait_time: + continue + + print_stdout( + _("Installation has exceeded specified time limit. " + "Exiting application.")) + sys.exit(1) ######################## diff --git a/virtinst/cli.py b/virtinst/cli.py index a064fc6f..6bac7ff3 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -121,7 +121,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True): vi_dir = None logfile = None - if not _in_testsuite(): + if not in_testsuite(): vi_dir = util.get_cache_dir() logfile = os.path.join(vi_dir, appname + ".log") @@ -200,7 +200,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True): logging.debug("Launched with command line: %s", " ".join(sys.argv)) -def _in_testsuite(): +def in_testsuite(): return "VIRTINST_TEST_SUITE" in os.environ @@ -359,7 +359,8 @@ def validate_disk(dev, warn_overwrite=False): def _run_console(domain, args): logging.debug("Running: %s", " ".join(args)) - if _in_testsuite(): + if in_testsuite(): + print_stdout("testsuite console command: %s" % args) # Add this destroy() in here to trigger more virt-install code # for the test suite domain.destroy() @@ -428,7 +429,7 @@ def get_console_cb(guest): logging.debug("No viewer to launch for graphics type '%s'", gtype) return - if not _in_testsuite(): + if not in_testsuite(): try: subprocess.check_output(["virt-viewer", "--version"]) except OSError: @@ -446,7 +447,7 @@ def get_console_cb(guest): def get_meter(): - quiet = (get_global_state().quiet or _in_testsuite()) + quiet = (get_global_state().quiet or in_testsuite()) return util.make_meter(quiet=quiet) |