mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-18 06:03:58 +03:00
cli: Add more code coverage
This commit is contained in:
parent
75101ce27b
commit
cc366fff7d
@ -1,6 +1,6 @@
|
|||||||
<domain type="kvm">
|
<domain type="kvm">
|
||||||
<name>foobar</name>
|
<name>foobar</name>
|
||||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
<uuid>12345678-12F4-1234-1234-123456789AFA</uuid>
|
||||||
<genid/>
|
<genid/>
|
||||||
<description>foobar & baz</description>
|
<description>foobar & baz</description>
|
||||||
<metadata>
|
<metadata>
|
||||||
|
@ -450,6 +450,7 @@ c = vinst.add_category("xml-comparsion", "--connect %(URI-KVM)s --noautoconsole
|
|||||||
# Singleton element test #1, for simpler strings
|
# Singleton element test #1, for simpler strings
|
||||||
c.add_compare("""
|
c.add_compare("""
|
||||||
--memory 1024
|
--memory 1024
|
||||||
|
--uuid 12345678-12F4-1234-1234-123456789AFA
|
||||||
--vcpus 4,cores=2,threads=2,sockets=2 --cpuset=1,3-5
|
--vcpus 4,cores=2,threads=2,sockets=2 --cpuset=1,3-5
|
||||||
--cpu host-copy
|
--cpu host-copy
|
||||||
--description \"foobar & baz\"
|
--description \"foobar & baz\"
|
||||||
@ -1175,18 +1176,20 @@ c = vclon.add_category("remote", "--connect %(URI-TEST-REMOTE)s")
|
|||||||
c.add_valid("-o test --auto-clone") # Auto flag, no storage
|
c.add_valid("-o test --auto-clone") # Auto flag, no storage
|
||||||
c.add_valid("--original-xml " + _CLONE_MANAGED + " --auto-clone") # Auto flag w/ managed storage
|
c.add_valid("--original-xml " + _CLONE_MANAGED + " --auto-clone") # Auto flag w/ managed storage
|
||||||
c.add_invalid("--original-xml " + _CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage, which is invalid for remote connection
|
c.add_invalid("--original-xml " + _CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage, which is invalid for remote connection
|
||||||
|
c.add_invalid("--original-xml " + _CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage, which is invalid for remote connection
|
||||||
|
|
||||||
|
|
||||||
c = vclon.add_category("misc", "")
|
c = vclon.add_category("misc", "")
|
||||||
c.add_compare("--connect %(URI-KVM)s -o test-clone --auto-clone --clone-running", "clone-auto1")
|
c.add_compare("--connect %(URI-KVM)s -o test-clone --auto-clone --clone-running", "clone-auto1")
|
||||||
c.add_compare("--connect %(URI-TEST-FULL)s -o test-clone-simple --name newvm --auto-clone --clone-running", "clone-auto2")
|
c.add_compare("--connect %(URI-TEST-FULL)s -o test-clone-simple --name newvm --auto-clone --clone-running", "clone-auto2")
|
||||||
c.add_valid("-o test --auto-clone") # Auto flag, no storage
|
c.add_valid("-o test --auto-clone --uuid 12345678-12F4-1234-1234-123456789AFA --reflink --mac 12:34:56:1A:B2:C3") # Auto flag, no storage
|
||||||
c.add_valid("--original-xml " + _CLONE_MANAGED + " --auto-clone") # Auto flag w/ managed storage
|
c.add_valid("--original-xml " + _CLONE_MANAGED + " --auto-clone") # Auto flag w/ managed storage
|
||||||
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage
|
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --auto-clone") # Auto flag w/ local storage
|
||||||
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone --auto-clone --clone-running") # Auto flag, actual VM, skip state check
|
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone --auto-clone --clone-running") # Auto flag, actual VM, skip state check
|
||||||
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --preserve-data --file %(EXISTIMG1)s") # Preserve data shouldn't complain about existing volume
|
c.add_valid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --preserve-data --file %(EXISTIMG1)s") # Preserve data shouldn't complain about existing volume
|
||||||
c.add_valid("-n clonetest --original-xml " + _CLONE_UNMANAGED + " --file %(EXISTIMG3)s --file %(EXISTIMG4)s --check path_exists=off") # Skip existing file check
|
c.add_valid("-n clonetest --original-xml " + _CLONE_UNMANAGED + " --file %(EXISTIMG3)s --file %(EXISTIMG4)s --check path_exists=off") # Skip existing file check
|
||||||
c.add_invalid("--auto-clone") # Just the auto flag
|
c.add_invalid("--auto-clone") # Just the auto flag
|
||||||
|
c.add_invalid("-o test --file foo") # Didn't specify new name
|
||||||
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-many-devices --auto-clone") # VM is running, but --clone-running isn't passed
|
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-many-devices --auto-clone") # VM is running, but --clone-running isn't passed
|
||||||
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --file %(EXISTIMG1)s --clone-running") # Should complain about overwriting existing file
|
c.add_invalid("--connect %(URI-TEST-FULL)s -o test-clone-simple -n newvm --file %(EXISTIMG1)s --clone-running") # Should complain about overwriting existing file
|
||||||
|
|
||||||
@ -1225,6 +1228,7 @@ _VMX_IMG = "%s/tests/virtconv-files/vmx_input/test1.vmx" % os.getcwd()
|
|||||||
|
|
||||||
vconv = App("virt-convert")
|
vconv = App("virt-convert")
|
||||||
c = vconv.add_category("misc", "--connect %(URI-KVM)s --dry")
|
c = vconv.add_category("misc", "--connect %(URI-KVM)s --dry")
|
||||||
|
c.add_valid(_VMX_IMG + " --disk-format qcow2") # hits some more code paths than print-xml
|
||||||
c.add_invalid(_VMX_IMG + " --input-format foo") # invalid input format
|
c.add_invalid(_VMX_IMG + " --input-format foo") # invalid input format
|
||||||
c.add_invalid("%(EXISTIMG1)s") # invalid input file
|
c.add_invalid("%(EXISTIMG1)s") # invalid input file
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ def get_original_guest(guest_name, origfile, design):
|
|||||||
try:
|
try:
|
||||||
design.original_xml = origxml
|
design.original_xml = origxml
|
||||||
return
|
return
|
||||||
except (ValueError, RuntimeError) as e:
|
except (ValueError, RuntimeError) as e: # pragma: no cover
|
||||||
fail(e)
|
fail(e)
|
||||||
|
|
||||||
if not guest_name:
|
if not guest_name:
|
||||||
@ -153,9 +153,7 @@ def main(conn=None):
|
|||||||
cli.convert_old_force(options)
|
cli.convert_old_force(options)
|
||||||
cli.parse_check(options.check)
|
cli.parse_check(options.check)
|
||||||
cli.set_prompt(options.prompt)
|
cli.set_prompt(options.prompt)
|
||||||
|
conn = cli.getConnection(options.connect, conn=conn)
|
||||||
if conn is None:
|
|
||||||
conn = cli.getConnection(options.connect)
|
|
||||||
|
|
||||||
if (options.new_diskfile is None and
|
if (options.new_diskfile is None and
|
||||||
options.auto_clone is False and
|
options.auto_clone is False and
|
||||||
@ -203,7 +201,7 @@ def main(conn=None):
|
|||||||
logging.debug("end clone")
|
logging.debug("end clone")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__": # pragma: no cover
|
||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
except SystemExit as sys_e:
|
except SystemExit as sys_e:
|
||||||
|
@ -82,8 +82,7 @@ def main(conn=None):
|
|||||||
options = parse_args()
|
options = parse_args()
|
||||||
cli.setupLogging("virt-convert", options.debug, options.quiet)
|
cli.setupLogging("virt-convert", options.debug, options.quiet)
|
||||||
|
|
||||||
if conn is None:
|
conn = cli.getConnection(options.connect, conn=conn)
|
||||||
conn = cli.getConnection(options.connect)
|
|
||||||
if options.xmlonly:
|
if options.xmlonly:
|
||||||
options.dry = True
|
options.dry = True
|
||||||
options.quiet = True
|
options.quiet = True
|
||||||
@ -110,18 +109,18 @@ def main(conn=None):
|
|||||||
if options.xmlonly:
|
if options.xmlonly:
|
||||||
print_stdout(installer.start_install(guest, return_xml=True)[1],
|
print_stdout(installer.start_install(guest, return_xml=True)[1],
|
||||||
do_force=True)
|
do_force=True)
|
||||||
elif not options.dry:
|
elif not options.dry or cli.in_testsuite():
|
||||||
print_stdout(_("Creating guest '%s'.") % guest.name)
|
print_stdout(_("Creating guest '%s'.") % guest.name)
|
||||||
domain = installer.start_install(guest)
|
domain = installer.start_install(guest)
|
||||||
cli.connect_console(guest, domain, conscb, True, False)
|
cli.connect_console(guest, domain, conscb, True, False)
|
||||||
except Exception:
|
except Exception: # pragma: no cover
|
||||||
converter.cleanup()
|
converter.cleanup()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__": # pragma: no cover
|
||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
except SystemExit as sys_e:
|
except SystemExit as sys_e:
|
||||||
|
37
virt-install
37
virt-install
@ -190,12 +190,6 @@ def convert_old_cpuset(options):
|
|||||||
|
|
||||||
def convert_old_networks(options):
|
def convert_old_networks(options):
|
||||||
if options.nonetworks:
|
if options.nonetworks:
|
||||||
if options.mac:
|
|
||||||
fail(_("Cannot use --mac with --nonetworks"))
|
|
||||||
if options.bridge:
|
|
||||||
fail(_("Cannot use --bridge with --nonetworks"))
|
|
||||||
if options.network:
|
|
||||||
fail(_("Cannot use --nonetworks with --network"))
|
|
||||||
options.network = ["none"]
|
options.network = ["none"]
|
||||||
|
|
||||||
macs = virtinst.xmlutil.listify(options.mac)
|
macs = virtinst.xmlutil.listify(options.mac)
|
||||||
@ -649,7 +643,7 @@ def start_install(guest, installer, options):
|
|||||||
print_stdout(_("Domain creation completed."))
|
print_stdout(_("Domain creation completed."))
|
||||||
if not options.transient and not domain.isActive():
|
if not options.transient and not domain.isActive():
|
||||||
if options.noreboot or not installer.has_install_phase():
|
if options.noreboot or not installer.has_install_phase():
|
||||||
print_stdout(
|
print_stdout( # pragma: no cover
|
||||||
_("You can restart your domain by running:\n %s") %
|
_("You can restart your domain by running:\n %s") %
|
||||||
cli.virsh_start_cmd(guest))
|
cli.virsh_start_cmd(guest))
|
||||||
else:
|
else:
|
||||||
@ -658,7 +652,7 @@ def start_install(guest, installer, options):
|
|||||||
cli.connect_console(guest, domain, conscb, True,
|
cli.connect_console(guest, domain, conscb, True,
|
||||||
options.destroy_on_exit)
|
options.destroy_on_exit)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt: # pragma: no cover
|
||||||
logging.debug("", exc_info=True)
|
logging.debug("", exc_info=True)
|
||||||
print_stderr(_("Domain install interrupted."))
|
print_stderr(_("Domain install interrupted."))
|
||||||
raise
|
raise
|
||||||
@ -668,6 +662,10 @@ def start_install(guest, installer, options):
|
|||||||
installer.cleanup_created_disks(guest, meter)
|
installer.cleanup_created_disks(guest, meter)
|
||||||
cli.install_fail(guest)
|
cli.install_fail(guest)
|
||||||
|
|
||||||
|
if cli.in_testsuite() and options.destroy_on_exit:
|
||||||
|
# Helps with unit testing
|
||||||
|
_destroy_on_exit(domain)
|
||||||
|
|
||||||
|
|
||||||
def check_domain(installer, domain, conscb, transient,
|
def check_domain(installer, domain, conscb, transient,
|
||||||
wait_for_install, wait_time, start_time):
|
wait_for_install, wait_time, start_time):
|
||||||
@ -682,14 +680,14 @@ def check_domain(installer, domain, conscb, transient,
|
|||||||
logging.debug("Domain state after install: %s", state)
|
logging.debug("Domain state after install: %s", state)
|
||||||
|
|
||||||
if state == libvirt.VIR_DOMAIN_CRASHED:
|
if state == libvirt.VIR_DOMAIN_CRASHED:
|
||||||
fail(_("Domain has crashed."))
|
fail(_("Domain has crashed.")) # pragma: no cover
|
||||||
|
|
||||||
return not domain.isActive()
|
return not domain.isActive()
|
||||||
except libvirt.libvirtError as e:
|
except libvirt.libvirtError as e:
|
||||||
if transient and e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
|
if transient and e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
|
||||||
logging.debug("transient VM shutdown and disappeared.")
|
logging.debug("transient VM shutdown and disappeared.")
|
||||||
return True
|
return True
|
||||||
raise
|
raise # pragma: no cover
|
||||||
|
|
||||||
if check_domain_inactive():
|
if check_domain_inactive():
|
||||||
return
|
return
|
||||||
@ -700,9 +698,9 @@ def check_domain(installer, domain, conscb, transient,
|
|||||||
# the former case, libvirt may not have caught up yet with the
|
# the former case, libvirt may not have caught up yet with the
|
||||||
# VM having exited, so wait a bit and check again
|
# VM having exited, so wait a bit and check again
|
||||||
if not cli.in_testsuite():
|
if not cli.in_testsuite():
|
||||||
time.sleep(2)
|
time.sleep(2) # pragma: no cover
|
||||||
if check_domain_inactive():
|
if check_domain_inactive():
|
||||||
return
|
return # pragma: no cover
|
||||||
|
|
||||||
# If we reach here, the VM still appears to be running.
|
# If we reach here, the VM still appears to be running.
|
||||||
if not wait_for_install or wait_time == 0:
|
if not wait_for_install or wait_time == 0:
|
||||||
@ -728,15 +726,15 @@ def check_domain(installer, domain, conscb, transient,
|
|||||||
|
|
||||||
# Wait loop
|
# Wait loop
|
||||||
while True:
|
while True:
|
||||||
if not domain.isActive():
|
if not domain.isActive(): # pragma: no cover
|
||||||
print_stdout(_("Domain has shutdown. Continuing."))
|
print_stdout(_("Domain has shutdown. Continuing."))
|
||||||
break
|
break
|
||||||
|
|
||||||
if not cli.in_testsuite():
|
if not cli.in_testsuite(): # pragma: no cover
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
time_elapsed = (time.time() - start_time)
|
time_elapsed = (time.time() - start_time)
|
||||||
if not cli.in_testsuite():
|
if not cli.in_testsuite(): # pragma: no cover
|
||||||
if wait_forever:
|
if wait_forever:
|
||||||
continue
|
continue
|
||||||
if time_elapsed < wait_time:
|
if time_elapsed < wait_time:
|
||||||
@ -919,13 +917,13 @@ def _destroy_on_exit(domain):
|
|||||||
isactive = bool(domain and domain.isActive())
|
isactive = bool(domain and domain.isActive())
|
||||||
if isactive:
|
if isactive:
|
||||||
domain.destroy()
|
domain.destroy()
|
||||||
except libvirt.libvirtError as e:
|
except libvirt.libvirtError as e: # pragma: no cover
|
||||||
if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
|
if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
|
||||||
logging.debug("Error invoking atexit destroy_on_exit",
|
logging.debug("Error invoking atexit destroy_on_exit",
|
||||||
exc_info=True)
|
exc_info=True)
|
||||||
|
|
||||||
|
|
||||||
def set_test_stub_options(options):
|
def set_test_stub_options(options): # pragma: no cover
|
||||||
# Set some basic options that will let virt-install succeed. Helps
|
# Set some basic options that will let virt-install succeed. Helps
|
||||||
# save boiler plate typing when testing new command line additions
|
# save boiler plate typing when testing new command line additions
|
||||||
if not options.test_stub_command:
|
if not options.test_stub_command:
|
||||||
@ -975,8 +973,7 @@ def main(conn=None):
|
|||||||
set_test_stub_options(options)
|
set_test_stub_options(options)
|
||||||
convert_old_os_options(options)
|
convert_old_os_options(options)
|
||||||
|
|
||||||
if conn is None:
|
conn = cli.getConnection(options.connect, conn=conn)
|
||||||
conn = cli.getConnection(options.connect)
|
|
||||||
|
|
||||||
if options.test_media_detection:
|
if options.test_media_detection:
|
||||||
do_test_media_detection(conn, options)
|
do_test_media_detection(conn, options)
|
||||||
@ -992,7 +989,7 @@ def main(conn=None):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__": # pragma: no cover
|
||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
except SystemExit as sys_e:
|
except SystemExit as sys_e:
|
||||||
|
5
virt-xml
5
virt-xml
@ -466,8 +466,7 @@ def main(conn=None):
|
|||||||
if options.confirm and not options.print_xml:
|
if options.confirm and not options.print_xml:
|
||||||
options.print_diff = True
|
options.print_diff = True
|
||||||
|
|
||||||
if conn is None:
|
conn = cli.getConnection(options.connect, conn)
|
||||||
conn = cli.getConnection(options.connect)
|
|
||||||
|
|
||||||
domain = None
|
domain = None
|
||||||
active_xmlobj = None
|
active_xmlobj = None
|
||||||
@ -525,7 +524,7 @@ def main(conn=None):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__": # pragma: no cover
|
||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
except SystemExit as sys_e:
|
except SystemExit as sys_e:
|
||||||
|
@ -12,7 +12,8 @@ Configuration variables that can be set at build time
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info.major != 3 or sys.version_info.minor < 4:
|
if (sys.version_info.major != 3 or
|
||||||
|
sys.version_info.minor < 4): # pragma: no cover
|
||||||
print("python 3.4 or later is required, your's is %s" %
|
print("python 3.4 or later is required, your's is %s" %
|
||||||
sys.version_info)
|
sys.version_info)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -24,7 +25,7 @@ _filepath = os.path.abspath(__file__)
|
|||||||
_srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), ".."))
|
_srcdir = os.path.abspath(os.path.join(os.path.dirname(_filepath), ".."))
|
||||||
_cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg")
|
_cfgpath = os.path.join(os.path.dirname(_filepath), "cli.cfg")
|
||||||
if os.path.exists(_cfgpath):
|
if os.path.exists(_cfgpath):
|
||||||
_cfg.read(_cfgpath)
|
_cfg.read(_cfgpath) # pragma: no cover
|
||||||
|
|
||||||
_istest = "VIRTINST_TEST_SUITE" in os.environ
|
_istest = "VIRTINST_TEST_SUITE" in os.environ
|
||||||
_running_from_srcdir = os.path.exists(
|
_running_from_srcdir = os.path.exists(
|
||||||
@ -35,7 +36,7 @@ def _split_list(commastr):
|
|||||||
return [d for d in commastr.split(",") if d]
|
return [d for d in commastr.split(",") if d]
|
||||||
|
|
||||||
|
|
||||||
def _get_param(name, default):
|
def _get_param(name, default): # pragma: no cover
|
||||||
if _istest:
|
if _istest:
|
||||||
return default
|
return default
|
||||||
try:
|
try:
|
||||||
@ -53,7 +54,7 @@ def _setup_gsettings_path(schemadir):
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
exe = shutil.which("glib-compile-schemas")
|
exe = shutil.which("glib-compile-schemas")
|
||||||
if not exe:
|
if not exe: # pragma: no cover
|
||||||
raise RuntimeError("You must install glib-compile-schemas to run "
|
raise RuntimeError("You must install glib-compile-schemas to run "
|
||||||
"virt-manager from git.")
|
"virt-manager from git.")
|
||||||
subprocess.check_call([exe, "--strict", schemadir])
|
subprocess.check_call([exe, "--strict", schemadir])
|
||||||
@ -87,7 +88,7 @@ class _CLIConfig(object):
|
|||||||
self.icon_dir = os.path.join(_srcdir, "data")
|
self.icon_dir = os.path.join(_srcdir, "data")
|
||||||
self.gsettings_dir = self.icon_dir
|
self.gsettings_dir = self.icon_dir
|
||||||
_setup_gsettings_path(self.gsettings_dir)
|
_setup_gsettings_path(self.gsettings_dir)
|
||||||
else:
|
else: # pragma: no cover
|
||||||
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
self.ui_dir = os.path.join(prefix, "share", "virt-manager", "ui")
|
||||||
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
self.icon_dir = os.path.join(prefix, "share", "virt-manager",
|
||||||
"icons")
|
"icons")
|
||||||
|
@ -210,7 +210,11 @@ def in_testsuite():
|
|||||||
# Libvirt connection helpers #
|
# Libvirt connection helpers #
|
||||||
##############################
|
##############################
|
||||||
|
|
||||||
def getConnection(uri):
|
def getConnection(uri, conn=None):
|
||||||
|
if conn:
|
||||||
|
# preopened connection passed in via test suite
|
||||||
|
return conn
|
||||||
|
|
||||||
logging.debug("Requesting libvirt URI %s", (uri or "default"))
|
logging.debug("Requesting libvirt URI %s", (uri or "default"))
|
||||||
conn = VirtinstConnection(uri)
|
conn = VirtinstConnection(uri)
|
||||||
conn.open(_openauth_cb, None)
|
conn.open(_openauth_cb, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user