Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 0f5eef2

Browse files
committed
virt-*: Don't show backtraces for most errors
Additionally, improve some error message cosmetics.
1 parent ae43ef1 commit 0f5eef2

5 files changed

Lines changed: 61 additions & 69 deletions

File tree

virt-clone

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -213,40 +213,33 @@ def main():
213213

214214
design = clmgr.CloneDesign(connection=conn)
215215

216-
try:
217-
design.clone_running = options.clone_running
218-
get_original_guest(options.original_guest, options.original_xml,
219-
design)
220-
get_clone_name(options.new_name, options.auto_clone, design)
221-
222-
get_clone_macaddr(options.new_mac, design)
223-
get_clone_uuid(options.new_uuid, design)
224-
get_clone_sparse(options.sparse, design)
225-
get_force_target(options.target, design)
226-
get_preserve(options.preserve, design)
227-
228-
# This determines the devices that need to be cloned, so that
229-
# get_clone_diskfile knows how many new disk paths it needs
230-
design.setup_original()
231-
232-
get_clone_diskfile(options.new_diskfile, design, conn,
233-
not options.preserve, options.auto_clone)
234-
235-
# setup design object
236-
design.setup()
237-
238-
# start cloning
239-
meter = progress.TextMeter()
240-
clmgr.start_duplicate(design, meter)
241-
242-
print _("\nClone '%s' created successfully.") % design.clone_name
243-
logging.debug("end clone")
244-
except RuntimeError, e:
245-
fail(e)
246-
except SystemExit, e:
247-
sys.exit(e.code)
248-
except Exception, e:
249-
fail(e)
216+
design.clone_running = options.clone_running
217+
get_original_guest(options.original_guest, options.original_xml,
218+
design)
219+
get_clone_name(options.new_name, options.auto_clone, design)
220+
221+
get_clone_macaddr(options.new_mac, design)
222+
get_clone_uuid(options.new_uuid, design)
223+
get_clone_sparse(options.sparse, design)
224+
get_force_target(options.target, design)
225+
get_preserve(options.preserve, design)
226+
227+
# This determines the devices that need to be cloned, so that
228+
# get_clone_diskfile knows how many new disk paths it needs
229+
design.setup_original()
230+
231+
get_clone_diskfile(options.new_diskfile, design, conn,
232+
not options.preserve, options.auto_clone)
233+
234+
# setup design object
235+
design.setup()
236+
237+
# start cloning
238+
meter = progress.TextMeter()
239+
clmgr.start_duplicate(design, meter)
240+
241+
print _("\nClone '%s' created successfully.") % design.clone_name
242+
logging.debug("end clone")
250243

251244
if __name__ == "__main__":
252245
try:
@@ -256,6 +249,5 @@ if __name__ == "__main__":
256249
except KeyboardInterrupt:
257250
print >> sys.stderr, _("Installation aborted at user request")
258251
except Exception, main_e:
259-
logging.exception(main_e)
260-
sys.exit(1)
252+
fail(main_e)
261253

virt-convert

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,5 @@ if __name__ == "__main__":
276276
except KeyboardInterrupt:
277277
print >> sys.stderr, _("Aborted at user request")
278278
except Exception, main_e:
279-
logging.exception(main_e)
280-
sys.exit(1)
279+
fail(main_e)
281280

virt-image

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,26 @@ def main():
232232
guest._prepare_install(meter)
233233
guest._create_devices(meter)
234234
print guest.get_config_xml()
235-
else:
236-
try:
237-
print _("\n\nCreating guest %s...") % guest.name
238-
239-
dom = guest.start_install(None, progresscb)
240-
if dom is None:
241-
print _("Guest creation failed")
242-
sys.exit(1)
243-
244-
except RuntimeError, e:
245-
fail(e)
246-
except Exception, e:
247-
print _("Domain creation may not have been\n"
248-
"successful. If it was, you can restart your domain\n"
249-
"by running 'virsh start %s'; otherwise, please\n"
250-
"restart your installation.") %(guest.name,)
251-
raise
235+
return
236+
237+
try:
238+
print _("\n\nCreating guest %s...") % guest.name
239+
240+
dom = guest.start_install(None, progresscb)
241+
if dom is None:
242+
print _("Guest creation failed")
243+
sys.exit(1)
244+
245+
except RuntimeError:
246+
raise
247+
except Exception, e:
248+
fail(e, do_exit=False)
249+
print
250+
print _("Domain creation may not have been\n"
251+
"successful. If it was, you can restart your domain\n"
252+
"by running 'virsh start %s'; otherwise, please\n"
253+
"restart your installation.") %(guest.name,)
254+
sys.exit(1)
252255

253256
if __name__ == "__main__":
254257
try:
@@ -258,6 +261,5 @@ if __name__ == "__main__":
258261
except KeyboardInterrupt:
259262
print >> sys.stderr, _("Installation aborted at user request")
260263
except Exception, main_e:
261-
logging.exception(main_e)
262-
sys.exit(1)
264+
fail(main_e)
263265

virt-install

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def parse_boot_option(guest, optstring):
123123
if menu == None:
124124
fail(_("--boot menu must be 'on' or 'off'"))
125125

126-
print menu
127126
set_param("enable_bootmenu", "menu", menu)
128127
set_param("kernel", "kernel")
129128
set_param("initrd", "initrd")
@@ -1010,7 +1009,7 @@ def main():
10101009

10111010

10121011
# we've got everything -- try to start the install
1013-
print _("\n\nStarting install...")
1012+
print _("\nStarting install...")
10141013

10151014
try:
10161015
start_time = time.time()
@@ -1048,13 +1047,13 @@ def main():
10481047
except SystemExit, e:
10491048
sys.exit(e.code)
10501049
except Exception, e:
1051-
logging.error(e)
1052-
print _("Domain installation does not appear to have been\n "
1053-
"successful. If it was, you can restart your domain\n "
1054-
"by running 'virsh start %s'; otherwise, please\n "
1050+
fail(e, do_exit=False)
1051+
print
1052+
print _("Domain installation does not appear to have been\n"
1053+
"successful. If it was, you can restart your domain\n"
1054+
"by running 'virsh start %s'; otherwise, please\n"
10551055
"restart your installation.") % guest.name
1056-
raise
1057-
1056+
sys.exit(1)
10581057

10591058
def do_install(guest, conscb, progresscb, wait, wait_time, start_time,
10601059
install_func):
@@ -1141,6 +1140,5 @@ if __name__ == "__main__":
11411140
except KeyboardInterrupt:
11421141
print >> sys.stderr, _("Installation aborted at user request")
11431142
except Exception, main_e:
1144-
logging.exception(main_e)
1145-
sys.exit(1)
1143+
fail(main_e)
11461144

virtinst/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ def exception_log(type, val, tb):
190190
# Log the app command string
191191
logging.debug("Launched with command line:\n%s" % " ".join(sys.argv))
192192

193-
def fail(msg):
193+
def fail(msg, do_exit=True):
194194
"""Convenience function when failing in cli app"""
195195
logging.error(msg)
196196
_util.log_exception()
197-
_fail_exit()
197+
if do_exit:
198+
_fail_exit()
198199

199200
def _fail_exit():
200201
sys.exit(1)

0 commit comments

Comments
 (0)