diff options
author | Cole Robinson <crobinso@redhat.com> | 2019-06-10 18:13:31 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2019-06-11 17:51:25 -0400 |
commit | cc366fff7dea182750b3ecc6fe3f576f565c4de4 (patch) | |
tree | 7dcaddba5718a083c1006ff2f246a3d37cb9c6d9 /virt-install | |
parent | 75101ce27b7746b86ca3564d816653efa7a8d4fe (diff) | |
download | virt-manager-cc366fff7dea182750b3ecc6fe3f576f565c4de4.tar.gz |
cli: Add more code coverage
Diffstat (limited to 'virt-install')
-rwxr-xr-x | virt-install | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/virt-install b/virt-install index 64105d0b..7c258519 100755 --- a/virt-install +++ b/virt-install @@ -190,12 +190,6 @@ def convert_old_cpuset(options): def convert_old_networks(options): 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"] macs = virtinst.xmlutil.listify(options.mac) @@ -649,7 +643,7 @@ def start_install(guest, installer, options): print_stdout(_("Domain creation completed.")) if not options.transient and not domain.isActive(): 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") % cli.virsh_start_cmd(guest)) else: @@ -658,7 +652,7 @@ def start_install(guest, installer, options): cli.connect_console(guest, domain, conscb, True, options.destroy_on_exit) - except KeyboardInterrupt: + except KeyboardInterrupt: # pragma: no cover logging.debug("", exc_info=True) print_stderr(_("Domain install interrupted.")) raise @@ -668,6 +662,10 @@ def start_install(guest, installer, options): installer.cleanup_created_disks(guest, meter) 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, 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) if state == libvirt.VIR_DOMAIN_CRASHED: - fail(_("Domain has crashed.")) + fail(_("Domain has crashed.")) # pragma: no cover return not domain.isActive() except libvirt.libvirtError as e: if transient and e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: logging.debug("transient VM shutdown and disappeared.") return True - raise + raise # pragma: no cover if check_domain_inactive(): return @@ -700,9 +698,9 @@ def check_domain(installer, domain, conscb, transient, # the former case, libvirt may not have caught up yet with the # VM having exited, so wait a bit and check again if not cli.in_testsuite(): - time.sleep(2) + time.sleep(2) # pragma: no cover if check_domain_inactive(): - return + return # pragma: no cover # If we reach here, the VM still appears to be running. if not wait_for_install or wait_time == 0: @@ -728,15 +726,15 @@ def check_domain(installer, domain, conscb, transient, # Wait loop while True: - if not domain.isActive(): + if not domain.isActive(): # pragma: no cover print_stdout(_("Domain has shutdown. Continuing.")) break - if not cli.in_testsuite(): + if not cli.in_testsuite(): # pragma: no cover time.sleep(1) time_elapsed = (time.time() - start_time) - if not cli.in_testsuite(): + if not cli.in_testsuite(): # pragma: no cover if wait_forever: continue if time_elapsed < wait_time: @@ -919,13 +917,13 @@ def _destroy_on_exit(domain): isactive = bool(domain and domain.isActive()) if isactive: 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: logging.debug("Error invoking atexit destroy_on_exit", 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 # save boiler plate typing when testing new command line additions if not options.test_stub_command: @@ -975,8 +973,7 @@ def main(conn=None): set_test_stub_options(options) convert_old_os_options(options) - if conn is None: - conn = cli.getConnection(options.connect) + conn = cli.getConnection(options.connect, conn=conn) if options.test_media_detection: do_test_media_detection(conn, options) @@ -992,7 +989,7 @@ def main(conn=None): return 0 -if __name__ == "__main__": +if __name__ == "__main__": # pragma: no cover try: sys.exit(main()) except SystemExit as sys_e: |