qvm-remove: improve error message
The code assumes that QubesVMInUseError is thrown for a failed dependency check, but there are also other reasons. We need to handle the case when dependency list is empty, and also display the original message. See also QubesOS/qubes-core-admin#308 for which this was needed.
This commit is contained in:
parent
204c33afd1
commit
bf78aebf7c
@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# The Qubes OS Project, http://www.qubes-os.org
|
# The Qubes OS Project, http://www.qubes-os.org
|
||||||
#
|
#
|
||||||
@ -47,7 +47,8 @@ class TC_00_qvm_remove(qubesadmin.tests.QubesTestCase):
|
|||||||
mock_dependencies.return_value = \
|
mock_dependencies.return_value = \
|
||||||
[(None, 'default_template'), (self.app.domains['some-vm'], 'netvm')]
|
[(None, 'default_template'), (self.app.domains['some-vm'], 'netvm')]
|
||||||
|
|
||||||
qubesadmin.tools.qvm_remove.main(['-f', 'some-vm'], app=self.app)
|
with self.assertRaises(SystemExit):
|
||||||
|
qubesadmin.tools.qvm_remove.main(['-f', 'some-vm'], app=self.app)
|
||||||
|
|
||||||
self.assertTrue(mock_dependencies.called,
|
self.assertTrue(mock_dependencies.called,
|
||||||
"Dependencies check not called.")
|
"Dependencies check not called.")
|
||||||
|
@ -48,15 +48,18 @@ def main(args=None, app=None): # pylint: disable=missing-docstring
|
|||||||
for vm in args.domains:
|
for vm in args.domains:
|
||||||
try:
|
try:
|
||||||
del args.app.domains[vm.name]
|
del args.app.domains[vm.name]
|
||||||
except qubesadmin.exc.QubesVMInUseError:
|
except qubesadmin.exc.QubesVMInUseError as e:
|
||||||
dependencies = qubesadmin.utils.vm_dependencies(vm.app, vm)
|
dependencies = qubesadmin.utils.vm_dependencies(vm.app, vm)
|
||||||
print("VM {} cannot be removed. It is in use as:".format(
|
if dependencies:
|
||||||
vm.name))
|
print("VM {} cannot be removed. It is in use as:".format(
|
||||||
for (holder, prop) in dependencies:
|
vm.name))
|
||||||
if holder:
|
for (holder, prop) in dependencies:
|
||||||
print(" - {} for {}".format(prop, holder.name))
|
if holder:
|
||||||
else:
|
print(" - {} for {}".format(prop, holder.name))
|
||||||
print(" - global property {}".format(prop))
|
else:
|
||||||
|
print(" - global property {}".format(prop))
|
||||||
|
# Display the original message as well
|
||||||
|
parser.error_runtime(e)
|
||||||
except qubesadmin.exc.QubesException as e:
|
except qubesadmin.exc.QubesException as e:
|
||||||
parser.error_runtime(e)
|
parser.error_runtime(e)
|
||||||
retcode = 0
|
retcode = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user