Merge remote-tracking branch 'origin/pr/134'
* origin/pr/134: qvm-kill: make error message more clear qvm-kill: ignore already off domains
This commit is contained in:
commit
9b70e54719
@ -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
|
||||||
#
|
#
|
||||||
@ -52,7 +52,6 @@ class TC_00_qvm_kill(qubesadmin.tests.QubesTestCase):
|
|||||||
self.assertAllCalled()
|
self.assertAllCalled()
|
||||||
|
|
||||||
def test_003_not_running(self):
|
def test_003_not_running(self):
|
||||||
# TODO: some option to ignore this error?
|
|
||||||
self.app.expected_calls[
|
self.app.expected_calls[
|
||||||
('some-vm', 'admin.vm.Kill', None, None)] = \
|
('some-vm', 'admin.vm.Kill', None, None)] = \
|
||||||
b'2\x00QubesVMNotStartedError\x00\x00Domain is powered off: ' \
|
b'2\x00QubesVMNotStartedError\x00\x00Domain is powered off: ' \
|
||||||
@ -62,6 +61,20 @@ class TC_00_qvm_kill(qubesadmin.tests.QubesTestCase):
|
|||||||
b'0\x00some-vm class=AppVM state=Halted\n'
|
b'0\x00some-vm class=AppVM state=Halted\n'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
qubesadmin.tools.qvm_kill.main(['some-vm'], app=self.app),
|
qubesadmin.tools.qvm_kill.main(['some-vm'], app=self.app),
|
||||||
1)
|
0)
|
||||||
self.assertAllCalled()
|
self.assertAllCalled()
|
||||||
|
|
||||||
|
def test_004_other_error(self):
|
||||||
|
self.app.expected_calls[
|
||||||
|
('some-vm', 'admin.vm.Kill', None, None)] = \
|
||||||
|
b'2\x00QubesVMError\x00\x00Error message\x00'
|
||||||
|
self.app.expected_calls[
|
||||||
|
('dom0', 'admin.vm.List', None, None)] = \
|
||||||
|
b'0\x00some-vm class=AppVM state=Running\n'
|
||||||
|
with qubesadmin.tests.tools.StderrBuffer() as stderr:
|
||||||
|
self.assertEqual(
|
||||||
|
qubesadmin.tools.qvm_kill.main(['some-vm'], app=self.app),
|
||||||
|
1)
|
||||||
|
self.assertAllCalled()
|
||||||
|
self.assertIn("Failed to kill 'some-vm': Error message",
|
||||||
|
stderr.getvalue())
|
||||||
|
@ -28,7 +28,6 @@ import qubesadmin.tools
|
|||||||
parser = qubesadmin.tools.QubesArgumentParser(
|
parser = qubesadmin.tools.QubesArgumentParser(
|
||||||
description='forceful shutdown of a domain', vmname_nargs='+')
|
description='forceful shutdown of a domain', vmname_nargs='+')
|
||||||
|
|
||||||
|
|
||||||
def main(args=None, app=None):
|
def main(args=None, app=None):
|
||||||
'''Main routine of :program:`qvm-kill`.
|
'''Main routine of :program:`qvm-kill`.
|
||||||
|
|
||||||
@ -42,9 +41,12 @@ def main(args=None, app=None):
|
|||||||
for domain in args.domains:
|
for domain in args.domains:
|
||||||
try:
|
try:
|
||||||
domain.kill()
|
domain.kill()
|
||||||
|
except qubesadmin.exc.QubesVMNotStartedError:
|
||||||
|
pass
|
||||||
except (IOError, OSError, qubesadmin.exc.QubesException) as e:
|
except (IOError, OSError, qubesadmin.exc.QubesException) as e:
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
parser.print_error(str(e))
|
parser.print_error("Failed to kill '{}': {}".format(
|
||||||
|
domain.name, e))
|
||||||
|
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user