From 95ce30a9e3b62cbd4975213110fb03014059aa11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 9 Jul 2018 19:46:01 +0200 Subject: [PATCH] qvm-start-gui: fix handlign rpc-clipboard feature Pass -Q option to both stubdoman's gui daemon and actual VM's gui daemon. QubesOS/qubes-issues#3585 --- qubesadmin/tests/tools/qvm_start_gui.py | 54 ++++++++++++++++++++----- qubesadmin/tools/qvm_start_gui.py | 6 +-- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_start_gui.py b/qubesadmin/tests/tools/qvm_start_gui.py index d9e2e83..f62b74d 100644 --- a/qubesadmin/tests/tools/qvm_start_gui.py +++ b/qubesadmin/tests/tools/qvm_start_gui.py @@ -87,6 +87,10 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'admin.label.Index', 'red', None)] = \ b'0\x001' + self.app.expected_calls[ + ('test-vm', 'admin.vm.feature.CheckWithTemplate', + 'rpc-clipboard', None)] = \ + b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00' with unittest.mock.patch.object(self.launcher, 'kde_guid_args') as \ kde_mock: @@ -117,6 +121,10 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('dom0', 'admin.label.Index', 'red', None)] = \ b'0\x001' + self.app.expected_calls[ + ('test-vm', 'admin.vm.feature.CheckWithTemplate', + 'rpc-clipboard', None)] = \ + b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00' with unittest.mock.patch.object(self.launcher, 'kde_guid_args') as \ kde_mock: @@ -131,6 +139,40 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.assertAllCalled() + def test_012_common_args_rpc_clipboard(self): + self.app.expected_calls[ + ('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00test-vm class=AppVM state=Running\n' + self.app.expected_calls[ + ('test-vm', 'admin.vm.property.Get', 'label', None)] = \ + b'0\x00default=False type=label red' + self.app.expected_calls[ + ('test-vm', 'admin.vm.property.Get', 'debug', None)] = \ + b'0\x00default=False type=bool False' + self.app.expected_calls[ + ('dom0', 'admin.label.Get', 'red', None)] = \ + b'0\x000xff0000' + self.app.expected_calls[ + ('dom0', 'admin.label.Index', 'red', None)] = \ + b'0\x001' + self.app.expected_calls[ + ('test-vm', 'admin.vm.feature.CheckWithTemplate', + 'rpc-clipboard', None)] = \ + b'0\x001' + + with unittest.mock.patch.object(self.launcher, 'kde_guid_args') as \ + kde_mock: + kde_mock.return_value = [] + + args = self.launcher.common_guid_args(self.app.domains['test-vm']) + self.assertEqual(args, [ + '/usr/bin/qubes-guid', '-N', 'test-vm', + '-c', '0xff0000', + '-i', '/usr/share/icons/hicolor/128x128/devices/appvm-red.png', + '-l', '1', '-q', '-Q']) + + self.assertAllCalled() + @unittest.mock.patch('asyncio.create_subprocess_exec') def test_020_start_gui_for_vm(self, proc_mock): loop = asyncio.new_event_loop() @@ -186,10 +228,6 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'admin.vm.property.Get', 'debug', None)] = \ b'0\x00default=False type=bool False' - self.app.expected_calls[ - ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'rpc-clipboard', - None)] = \ - b'0\x00True' self.app.expected_calls[ ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'no-monitor-layout', None)] = \ @@ -199,7 +237,7 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): loop.run_until_complete(self.launcher.start_gui_for_vm( self.app.domains['test-vm'])) # common arguments dropped for simplicity - proc_mock.assert_called_once_with('-d', '3000', '-n', '-Q') + proc_mock.assert_called_once_with('-d', '3000', '-n') self.assertAllCalled() @@ -226,10 +264,6 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'admin.vm.property.Get', 'debug', None)] = \ b'0\x00default=False type=bool False' - self.app.expected_calls[ - ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'rpc-clipboard', - None)] = \ - b'0\x00True' self.app.expected_calls[ ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'no-monitor-layout', None)] = \ @@ -252,7 +286,7 @@ class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase): self.app.domains['test-vm'])) # common arguments dropped for simplicity mock_proc.assert_called_once_with( - '-d', '3000', '-n', '-Q', '-K', '1234') + '-d', '3000', '-n', '-K', '1234') finally: unittest.mock.patch.stopall() diff --git a/qubesadmin/tools/qvm_start_gui.py b/qubesadmin/tools/qvm_start_gui.py index 86ae27e..1229680 100644 --- a/qubesadmin/tools/qvm_start_gui.py +++ b/qubesadmin/tools/qvm_start_gui.py @@ -166,6 +166,9 @@ class GUILauncher(object): else: guid_cmd += ['-q'] + if vm.features.check_with_template('rpc-clipboard', False): + guid_cmd.extend(['-Q']) + guid_cmd += self.kde_guid_args(vm) return guid_cmd @@ -190,9 +193,6 @@ class GUILauncher(object): if vm.virt_mode == 'hvm': guid_cmd.extend(['-n']) - if vm.features.check_with_template('rpc-clipboard', False): - guid_cmd.extend(['-Q']) - stubdom_guid_pidfile = self.guid_pidfile(vm.stubdom_xid) if not vm.debug and os.path.exists(stubdom_guid_pidfile): # Terminate stubdom guid once "real" gui agent connects