From 0187588531c41b00ba59d35bfbf96425fb18d845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 8 Oct 2017 18:17:03 +0200 Subject: [PATCH] tools: adjust qvm-start message and logic, update tests QubesOS/qubes-issues#3130 --- qubesadmin/tests/tools/qvm_start.py | 32 ++++++++++++++++++++++++----- qubesadmin/tools/qvm_start.py | 9 ++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_start.py b/qubesadmin/tests/tools/qvm_start.py index 4433cfb..9ac5d98 100644 --- a/qubesadmin/tests/tools/qvm_start.py +++ b/qubesadmin/tests/tools/qvm_start.py @@ -32,6 +32,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('some-vm', 'admin.vm.Start', None, None)] = b'0\x00' qubesadmin.tools.qvm_start.main(['some-vm'], app=self.app) @@ -56,14 +59,12 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): self.assertAllCalled() def test_003_already_running(self): - # TODO: some option to ignore this error? - self.app.expected_calls[ - ('some-vm', 'admin.vm.Start', None, None)] = \ - b'2\x00QubesVMNotHaltedError\x00\x00Domain is running: ' \ - b'some-vm\x00' self.app.expected_calls[ ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Runnin\n' self.assertEqual( qubesadmin.tools.qvm_start.main(['some-vm'], app=self.app), 1) @@ -74,6 +75,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00dom0 class=AdminVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('dom0', 'admin.vm.device.block.Available', None, None)] = \ b'0\x00sr0\n' @@ -94,6 +98,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00dom0 class=AdminVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('dom0', 'admin.vm.device.block.Available', None, None)] = \ b'0\x00sdb1\n' @@ -114,6 +121,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00dom0 class=AdminVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('dom0', 'admin.vm.device.block.Available', None, None)] = \ b'0\x00sdb1\n' @@ -135,6 +145,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): ('dom0', 'admin.vm.List', None, None)] = \ b'0\x00dom0 class=AdminVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('dom0', 'admin.vm.device.block.Available', None, None)] = \ b'0\x00loop12\n' @@ -161,6 +174,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): b'0\x00dom0 class=AdminVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('other-vm', 'admin.vm.device.block.Available', None, None)] = \ b'0\x00loop7\n' @@ -191,6 +207,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): b'0\x00dom0 class=AdminVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7', b'devtype=cdrom persistent=True read-only=True')] = b'0\x00' @@ -212,6 +231,9 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase): b'0\x00dom0 class=AdminVM state=Running\n' \ b'other-vm class=AppVM state=Running\n' \ b'some-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('some-vm', 'admin.vm.List', None, None)] = \ + b'0\x00some-vm class=AppVM state=Halted\n' self.app.expected_calls[ ('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7', b'devtype=cdrom persistent=True read-only=True')] = \ diff --git a/qubesadmin/tools/qvm_start.py b/qubesadmin/tools/qvm_start.py index 24611f4..702206b 100644 --- a/qubesadmin/tools/qvm_start.py +++ b/qubesadmin/tools/qvm_start.py @@ -147,11 +147,12 @@ def main(args=None, app=None): exit_code = 0 for domain in args.domains: - if args.skip_if_running and domain.is_running(): - continue - elif domain.is_running(): + if domain.is_running(): + if args.skip_if_running: + continue exit_code = 1 - parser.print_error("domain is already running") + parser.print_error( + 'domain {} is already running'.format(domain.name)) return exit_code drive_assignment = None try: