2020-01-15 17:27:49 +01:00
|
|
|
# -*- encoding: utf-8 -*-
|
2017-04-15 20:35:30 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2017-05-24 12:44:46 +02:00
|
|
|
import functools
|
2017-04-15 20:35:30 +02:00
|
|
|
import os
|
2017-05-24 12:44:46 +02:00
|
|
|
import signal
|
2017-04-15 20:35:30 +02:00
|
|
|
import tempfile
|
|
|
|
import unittest.mock
|
2020-06-25 16:30:27 +02:00
|
|
|
import re
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
2017-05-11 23:21:04 +02:00
|
|
|
import qubesadmin.tests
|
2019-11-17 23:54:05 +01:00
|
|
|
import qubesadmin.tools.qvm_start_daemon
|
2020-06-25 16:30:27 +02:00
|
|
|
from qubesadmin.tools.qvm_start_daemon import GUI_DAEMON_OPTIONS
|
2017-05-24 12:44:46 +02:00
|
|
|
import qubesadmin.vm
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
|
2017-05-11 23:21:04 +02:00
|
|
|
class TC_00_qvm_start_gui(qubesadmin.tests.QubesTestCase):
|
2017-04-15 20:35:30 +02:00
|
|
|
def setUp(self):
|
|
|
|
super(TC_00_qvm_start_gui, self).setUp()
|
2019-11-17 23:54:05 +01:00
|
|
|
self.launcher = \
|
|
|
|
qubesadmin.tools.qvm_start_daemon.DAEMONLauncher(self.app)
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.check_output')
|
|
|
|
def test_000_kde_args(self, proc_mock):
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'label', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=label red'
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
proc_mock.side_effect = [
|
|
|
|
b'KWIN_RUNNING = 0x1\n',
|
|
|
|
b'access control enabled, only authorized clients can connect\n'
|
|
|
|
b'SI:localuser:root\n'
|
2017-04-30 22:54:20 +02:00
|
|
|
b'SI:localuser:' + os.environ['USER'].encode() + b'\n',
|
2017-04-15 20:35:30 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
args = self.launcher.kde_guid_args(self.app.domains['test-vm'])
|
2020-06-26 12:05:18 +02:00
|
|
|
self.launcher.kde = True
|
2017-04-15 20:35:30 +02:00
|
|
|
self.assertEqual(args, ['-T', '-p',
|
2019-10-20 19:25:21 +02:00
|
|
|
'_KDE_NET_WM_COLOR_SCHEME=s:' +
|
|
|
|
os.path.expanduser(
|
|
|
|
'~/.local/share/qubes-kde/red.colors')])
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
2020-06-25 16:30:27 +02:00
|
|
|
def setup_common_args(self):
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2020-06-25 16:30:27 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n' \
|
|
|
|
b'gui-vm class=AppVM state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'label', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=label red'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'debug', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=bool False'
|
2020-06-25 16:30:27 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.label.Get', 'red', None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x000xff0000'
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.label.Index', 'red', None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x001'
|
2018-07-09 19:46:01 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'rpc-clipboard', None)] = \
|
2018-07-09 19:46:01 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
2017-04-15 20:35:30 +02:00
|
|
|
|
2020-06-25 16:30:27 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
|
|
|
b'0\x00default=99 type=int 99'
|
|
|
|
|
|
|
|
for name, _kind in GUI_DAEMON_OPTIONS:
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.Get',
|
|
|
|
'gui-' + name.replace('_', '-'), None)] = \
|
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('gui-vm', 'admin.vm.feature.Get',
|
|
|
|
'gui-default-' + name.replace('_', '-'), None)] = \
|
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
|
|
|
|
def run_common_args(self):
|
|
|
|
with unittest.mock.patch.object(
|
|
|
|
self.launcher, 'kde_guid_args') as kde_mock, \
|
|
|
|
unittest.mock.patch.object(
|
|
|
|
self.launcher, 'write_guid_config') as write_config_mock:
|
2017-04-15 20:35:30 +02:00
|
|
|
kde_mock.return_value = []
|
|
|
|
|
|
|
|
args = self.launcher.common_guid_args(self.app.domains['test-vm'])
|
2020-06-25 16:30:27 +02:00
|
|
|
|
|
|
|
self.assertEqual(len(write_config_mock.mock_calls), 1)
|
|
|
|
|
|
|
|
config_args = write_config_mock.mock_calls[0][1]
|
|
|
|
self.assertEqual(config_args[0], '/var/run/qubes/guid-conf.99')
|
|
|
|
config = config_args[1]
|
|
|
|
|
|
|
|
# Strip comments and empty lines
|
|
|
|
config = re.sub(r'^#.*\n', '', config)
|
|
|
|
config = re.sub(r'^\n', '', config)
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
self.assertAllCalled()
|
2020-06-25 16:30:27 +02:00
|
|
|
return args, config
|
|
|
|
|
|
|
|
def test_010_common_args(self):
|
|
|
|
self.setup_common_args()
|
|
|
|
|
|
|
|
args, config = self.run_common_args()
|
|
|
|
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',
|
|
|
|
'-C', '/var/run/qubes/guid-conf.99',
|
|
|
|
])
|
|
|
|
|
|
|
|
self.assertEqual(config, '''\
|
|
|
|
global: {
|
|
|
|
}
|
|
|
|
''')
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
def test_011_common_args_debug(self):
|
2020-06-25 16:30:27 +02:00
|
|
|
self.setup_common_args()
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'debug', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=bool True'
|
2017-04-15 20:35:30 +02:00
|
|
|
|
2020-06-25 16:30:27 +02:00
|
|
|
args, config = self.run_common_args()
|
|
|
|
self.assertEqual(args, [
|
|
|
|
'/usr/bin/qubes-guid', '-N', 'test-vm',
|
|
|
|
'-c', '0xff0000',
|
|
|
|
'-i', '/usr/share/icons/hicolor/128x128/devices/appvm-red.png',
|
|
|
|
'-l', '1', '-v', '-v',
|
|
|
|
'-C', '/var/run/qubes/guid-conf.99',
|
|
|
|
])
|
|
|
|
self.assertEqual(config, '''\
|
|
|
|
global: {
|
|
|
|
}
|
|
|
|
''')
|
2017-04-15 20:35:30 +02:00
|
|
|
|
2018-07-09 19:46:01 +02:00
|
|
|
def test_012_common_args_rpc_clipboard(self):
|
2020-06-25 16:30:27 +02:00
|
|
|
self.setup_common_args()
|
2018-07-09 19:46:01 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'rpc-clipboard', None)] = \
|
2018-07-09 19:46:01 +02:00
|
|
|
b'0\x001'
|
|
|
|
|
2020-06-25 16:30:27 +02:00
|
|
|
args, config = self.run_common_args()
|
|
|
|
|
|
|
|
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',
|
|
|
|
'-C', '/var/run/qubes/guid-conf.99',
|
|
|
|
])
|
|
|
|
self.assertEqual(config, '''\
|
|
|
|
global: {
|
|
|
|
}
|
|
|
|
''')
|
|
|
|
|
|
|
|
def test_013_common_args_guid_config(self):
|
|
|
|
self.setup_common_args()
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.Get',
|
|
|
|
'gui-allow-fullscreen', None)] = \
|
|
|
|
b'0\x001'
|
|
|
|
# The template will not be asked for this feature
|
|
|
|
del self.app.expected_calls[
|
|
|
|
('gui-vm', 'admin.vm.feature.Get',
|
|
|
|
'gui-default-allow-fullscreen', None)]
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('gui-vm', 'admin.vm.feature.Get',
|
|
|
|
'gui-default-secure-copy-sequence', None)] = \
|
|
|
|
b'0\x00Ctrl-Alt-Shift-c'
|
|
|
|
|
|
|
|
_args, config = self.run_common_args()
|
|
|
|
self.assertEqual(config, '''\
|
|
|
|
global: {
|
|
|
|
allow_fullscreen = true;
|
|
|
|
secure_copy_sequence = "Ctrl-Alt-Shift-c";
|
|
|
|
}
|
|
|
|
''')
|
2018-07-09 19:46:01 +02:00
|
|
|
|
2017-04-15 20:35:30 +02:00
|
|
|
@unittest.mock.patch('asyncio.create_subprocess_exec')
|
|
|
|
def test_020_start_gui_for_vm(self, proc_mock):
|
2017-06-21 05:06:16 +02:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-07-18 04:22:34 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'virt_mode', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=str pv'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-06-21 05:06:16 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
2017-04-15 20:35:30 +02:00
|
|
|
with unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'common_guid_args', lambda vm: []):
|
2017-06-21 05:06:16 +02:00
|
|
|
loop.run_until_complete(self.launcher.start_gui_for_vm(
|
|
|
|
self.app.domains['test-vm']))
|
2017-04-15 20:35:30 +02:00
|
|
|
# common arguments dropped for simplicity
|
|
|
|
proc_mock.assert_called_once_with('-d', '3000')
|
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
@unittest.mock.patch('asyncio.create_subprocess_exec')
|
|
|
|
def test_021_start_gui_for_vm_hvm(self, proc_mock):
|
2017-06-21 05:06:16 +02:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3001'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-07-18 04:22:34 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'virt_mode', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=str hvm'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'debug', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=bool False'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-06-21 05:06:16 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
2017-04-15 20:35:30 +02:00
|
|
|
with unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'common_guid_args', lambda vm: []):
|
2017-06-21 05:06:16 +02:00
|
|
|
loop.run_until_complete(self.launcher.start_gui_for_vm(
|
|
|
|
self.app.domains['test-vm']))
|
2017-04-15 20:35:30 +02:00
|
|
|
# common arguments dropped for simplicity
|
2018-07-09 19:46:01 +02:00
|
|
|
proc_mock.assert_called_once_with('-d', '3000', '-n')
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_022_start_gui_for_vm_hvm_stubdom(self):
|
2017-06-21 05:06:16 +02:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3001'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-07-18 04:22:34 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'virt_mode', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=str hvm'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'debug', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=bool False'
|
2017-06-21 05:06:16 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-06-21 05:06:16 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
2017-04-15 20:35:30 +02:00
|
|
|
pidfile = tempfile.NamedTemporaryFile()
|
|
|
|
pidfile.write(b'1234\n')
|
|
|
|
pidfile.flush()
|
|
|
|
self.addCleanup(pidfile.close)
|
|
|
|
|
|
|
|
patch_proc = unittest.mock.patch('asyncio.create_subprocess_exec')
|
|
|
|
patch_args = unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'common_guid_args',
|
|
|
|
lambda vm: [])
|
2017-04-15 20:35:30 +02:00
|
|
|
patch_pidfile = unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'guid_pidfile',
|
|
|
|
lambda vm: pidfile.name)
|
2017-04-15 20:35:30 +02:00
|
|
|
try:
|
|
|
|
mock_proc = patch_proc.start()
|
|
|
|
patch_args.start()
|
|
|
|
patch_pidfile.start()
|
2017-06-21 05:06:16 +02:00
|
|
|
loop.run_until_complete(self.launcher.start_gui_for_vm(
|
|
|
|
self.app.domains['test-vm']))
|
2017-04-15 20:35:30 +02:00
|
|
|
# common arguments dropped for simplicity
|
|
|
|
mock_proc.assert_called_once_with(
|
2018-07-09 19:46:01 +02:00
|
|
|
'-d', '3000', '-n', '-K', '1234')
|
2017-04-15 20:35:30 +02:00
|
|
|
finally:
|
|
|
|
unittest.mock.patch.stopall()
|
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_030_start_gui_for_stubdomain(self):
|
2017-07-30 18:54:08 +02:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3001'
|
2017-07-30 18:54:08 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui', None)] = \
|
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
2018-07-09 20:00:05 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui-emulated',
|
2019-10-20 19:25:21 +02:00
|
|
|
None)] = \
|
2018-07-09 20:00:05 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
proc_mock = unittest.mock.Mock()
|
|
|
|
with unittest.mock.patch('asyncio.create_subprocess_exec',
|
2019-10-20 19:25:21 +02:00
|
|
|
lambda *args: self.mock_coroutine(proc_mock,
|
|
|
|
*args)):
|
2018-07-09 20:00:05 +02:00
|
|
|
with unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'common_guid_args', lambda vm: []):
|
2018-07-09 20:00:05 +02:00
|
|
|
loop.run_until_complete(self.launcher.start_gui_for_stubdomain(
|
|
|
|
self.app.domains['test-vm']))
|
|
|
|
# common arguments dropped for simplicity
|
|
|
|
proc_mock.assert_called_once_with('-d', '3001', '-t', '3000')
|
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_031_start_gui_for_stubdomain_forced(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
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', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2018-07-09 20:00:05 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3001'
|
2018-07-09 20:00:05 +02:00
|
|
|
# self.app.expected_calls[
|
2019-10-20 19:25:21 +02:00
|
|
|
# ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui', None)] = \
|
|
|
|
# b'0\x00'
|
2018-07-09 20:00:05 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui-emulated',
|
2019-10-20 19:25:21 +02:00
|
|
|
None)] = \
|
2018-07-09 20:00:05 +02:00
|
|
|
b'0\x001'
|
2017-07-30 18:54:08 +02:00
|
|
|
proc_mock = unittest.mock.Mock()
|
|
|
|
with unittest.mock.patch('asyncio.create_subprocess_exec',
|
2019-10-20 19:25:21 +02:00
|
|
|
lambda *args: self.mock_coroutine(proc_mock,
|
|
|
|
*args)):
|
2017-04-15 20:35:30 +02:00
|
|
|
with unittest.mock.patch.object(self.launcher,
|
2019-10-20 19:25:21 +02:00
|
|
|
'common_guid_args', lambda vm: []):
|
2017-07-30 18:54:08 +02:00
|
|
|
loop.run_until_complete(self.launcher.start_gui_for_stubdomain(
|
|
|
|
self.app.domains['test-vm']))
|
2017-04-15 20:35:30 +02:00
|
|
|
# common arguments dropped for simplicity
|
|
|
|
proc_mock.assert_called_once_with('-d', '3001', '-t', '3000')
|
|
|
|
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2017-06-21 05:06:16 +02:00
|
|
|
def mock_coroutine(self, mock, *args, **kwargs):
|
|
|
|
mock(*args, **kwargs)
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
def test_040_start_gui(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
2019-10-20 19:20:58 +02:00
|
|
|
b'0\x00test-vm class=AppVM state=Running\n' \
|
|
|
|
b'gui-vm class=AppVM state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui', None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'0\x00True'
|
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-04-15 20:35:30 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
self.app.expected_calls[
|
2017-07-18 04:22:34 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'virt_mode', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=str hvm'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3000'
|
2017-04-15 20:35:30 +02:00
|
|
|
self.app.expected_calls[
|
2017-05-12 19:36:03 +02:00
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
2019-10-20 19:25:21 +02:00
|
|
|
b'0\x00default=False type=int 3001'
|
2019-10-20 19:20:58 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
2017-04-15 20:35:30 +02:00
|
|
|
|
2019-10-20 21:12:31 +02:00
|
|
|
self.app._local_name = 'gui-vm'
|
2017-04-15 20:35:30 +02:00
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
mock_start_vm = unittest.mock.Mock()
|
|
|
|
mock_start_stubdomain = unittest.mock.Mock()
|
|
|
|
patch_start_vm = unittest.mock.patch.object(
|
2017-06-21 05:06:16 +02:00
|
|
|
self.launcher, 'start_gui_for_vm', functools.partial(
|
|
|
|
self.mock_coroutine, mock_start_vm))
|
2017-04-15 20:35:30 +02:00
|
|
|
patch_start_stubdomain = unittest.mock.patch.object(
|
2017-07-30 18:54:08 +02:00
|
|
|
self.launcher, 'start_gui_for_stubdomain', lambda vm_, force:
|
2017-04-15 20:35:30 +02:00
|
|
|
self.mock_coroutine(mock_start_stubdomain, vm_))
|
|
|
|
try:
|
|
|
|
patch_start_vm.start()
|
|
|
|
patch_start_stubdomain.start()
|
|
|
|
loop.run_until_complete(self.launcher.start_gui(vm))
|
2017-06-21 05:06:16 +02:00
|
|
|
mock_start_vm.assert_called_once_with(vm, monitor_layout=None)
|
2017-04-15 20:35:30 +02:00
|
|
|
mock_start_stubdomain.assert_called_once_with(vm)
|
|
|
|
finally:
|
|
|
|
unittest.mock.patch.stopall()
|
|
|
|
|
|
|
|
def test_041_start_gui_running(self):
|
|
|
|
# simulate existing pidfiles, should not start processes
|
|
|
|
self.skipTest('todo')
|
|
|
|
|
|
|
|
def test_042_start_gui_pvh(self):
|
|
|
|
# PVH - no stubdomain
|
|
|
|
self.skipTest('todo')
|
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.Popen')
|
|
|
|
def test_050_get_monitor_layout1(self, proc_mock):
|
|
|
|
proc_mock().stdout = b'''Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
|
|
|
|
HDMI1 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
|
|
|
|
1920x1200 59.95*+
|
|
|
|
1920x1080 60.00 50.00 59.94
|
|
|
|
1920x1080i 60.00 50.00 59.94
|
|
|
|
1600x1200 60.00
|
|
|
|
1680x1050 59.88
|
|
|
|
1280x1024 60.02
|
|
|
|
1440x900 59.90
|
|
|
|
1280x960 60.00
|
|
|
|
1280x720 60.00 50.00 59.94
|
|
|
|
1024x768 60.00
|
|
|
|
800x600 60.32
|
|
|
|
720x576 50.00
|
|
|
|
720x480 60.00 59.94
|
|
|
|
720x480i 60.00 59.94
|
|
|
|
640x480 60.00 59.94
|
|
|
|
HDMI2 disconnected (normal left inverted right x axis y axis)
|
|
|
|
VGA1 disconnected (normal left inverted right x axis y axis)
|
|
|
|
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
|
|
|
|
'''.splitlines()
|
2019-11-17 23:54:05 +01:00
|
|
|
self.assertEqual(qubesadmin.tools.qvm_start_daemon.get_monitor_layout(),
|
2019-10-20 19:25:21 +02:00
|
|
|
['1920 1200 0 0\n'])
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.Popen')
|
|
|
|
def test_051_get_monitor_layout_multiple(self, proc_mock):
|
|
|
|
proc_mock().stdout = b'''Screen 0: minimum 8 x 8, current 2880 x 1024, maximum 32767 x 32767
|
|
|
|
LVDS1 connected 1600x900+0+0 (normal left inverted right x axis y axis)
|
|
|
|
VGA1 connected 1280x1024+1600+0 (normal left inverted right x axis y axis)
|
|
|
|
'''.splitlines()
|
2019-11-17 23:54:05 +01:00
|
|
|
self.assertEqual(qubesadmin.tools.qvm_start_daemon.get_monitor_layout(),
|
2019-10-20 19:25:21 +02:00
|
|
|
['1600 900 0 0\n', '1280 1024 1600 0\n'])
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.Popen')
|
|
|
|
def test_052_get_monitor_layout_hidpi1(self, proc_mock):
|
|
|
|
proc_mock().stdout = b'''Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
|
|
|
|
HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 372mm x 208mm
|
|
|
|
1920x1200 60.00*+
|
|
|
|
'''.splitlines()
|
|
|
|
dpi = 150
|
2019-11-17 23:54:05 +01:00
|
|
|
self.assertEqual(qubesadmin.tools.qvm_start_daemon.get_monitor_layout(),
|
2019-10-20 19:25:21 +02:00
|
|
|
['2560 1920 0 0 {} {}\n'.format(
|
|
|
|
int(2560 / dpi * 254 / 10),
|
|
|
|
int(1920 / dpi * 254 / 10))])
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.Popen')
|
|
|
|
def test_052_get_monitor_layout_hidpi2(self, proc_mock):
|
|
|
|
proc_mock().stdout = b'''Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
|
|
|
|
HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 310mm x 174mm
|
|
|
|
1920x1200 60.00*+
|
|
|
|
'''.splitlines()
|
|
|
|
dpi = 200
|
2019-11-17 23:54:05 +01:00
|
|
|
self.assertEqual(qubesadmin.tools.qvm_start_daemon.get_monitor_layout(),
|
2019-10-20 19:25:21 +02:00
|
|
|
['2560 1920 0 0 {} {}\n'.format(
|
|
|
|
int(2560 / dpi * 254 / 10),
|
|
|
|
int(1920 / dpi * 254 / 10))])
|
2017-04-15 20:35:30 +02:00
|
|
|
|
|
|
|
@unittest.mock.patch('subprocess.Popen')
|
|
|
|
def test_052_get_monitor_layout_hidpi3(self, proc_mock):
|
|
|
|
proc_mock().stdout = b'''Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 32767 x 32767
|
|
|
|
HDMI1 connected 2560x1920+0+0 (normal left inverted right x axis y axis) 206mm x 116mm
|
|
|
|
1920x1200 60.00*+
|
|
|
|
'''.splitlines()
|
|
|
|
dpi = 300
|
2019-11-17 23:54:05 +01:00
|
|
|
self.assertEqual(qubesadmin.tools.qvm_start_daemon.get_monitor_layout(),
|
2019-10-20 19:25:21 +02:00
|
|
|
['2560 1920 0 0 {} {}\n'.format(
|
|
|
|
int(2560 / dpi * 254 / 10),
|
|
|
|
int(1920 / dpi * 254 / 10))])
|
2017-05-24 12:44:46 +02:00
|
|
|
|
|
|
|
def test_060_send_monitor_layout(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
|
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
mock_run_service = unittest.mock.Mock(spec={})
|
|
|
|
patch_run_service = unittest.mock.patch.object(
|
|
|
|
qubesadmin.vm.QubesVM, 'run_service_for_stdio',
|
|
|
|
mock_run_service)
|
|
|
|
patch_run_service.start()
|
|
|
|
self.addCleanup(patch_run_service.stop)
|
|
|
|
monitor_layout = ['1920 1080 0 0\n']
|
|
|
|
loop.run_until_complete(self.launcher.send_monitor_layout(
|
|
|
|
vm, layout=monitor_layout, startup=True))
|
|
|
|
mock_run_service.assert_called_once_with(
|
2019-09-21 04:51:43 +02:00
|
|
|
'qubes.SetMonitorLayout', autostart=False, input=b'1920 1080 0 0\n')
|
2017-05-24 12:44:46 +02:00
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_061_send_monitor_layout_exclude(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
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.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'0\x00True'
|
|
|
|
|
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
mock_run_service = unittest.mock.Mock()
|
|
|
|
patch_run_service = unittest.mock.patch.object(
|
|
|
|
qubesadmin.vm.QubesVM, 'run_service_for_stdio',
|
|
|
|
mock_run_service)
|
|
|
|
patch_run_service.start()
|
|
|
|
self.addCleanup(patch_run_service.stop)
|
|
|
|
monitor_layout = ['1920 1080 0 0\n']
|
|
|
|
loop.run_until_complete(self.launcher.send_monitor_layout(
|
|
|
|
vm, layout=monitor_layout, startup=True))
|
|
|
|
self.assertFalse(mock_run_service.called)
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_062_send_monitor_layout_not_running(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
|
|
b'0\x00test-vm class=AppVM state=Halted\n'
|
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Halted'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
|
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
mock_run_service = unittest.mock.Mock()
|
|
|
|
patch_run_service = unittest.mock.patch.object(
|
|
|
|
qubesadmin.vm.QubesVM, 'run_service_for_stdio',
|
|
|
|
mock_run_service)
|
|
|
|
patch_run_service.start()
|
|
|
|
self.addCleanup(patch_run_service.stop)
|
|
|
|
monitor_layout = ['1920 1080 0 0\n']
|
|
|
|
loop.run_until_complete(self.launcher.send_monitor_layout(
|
|
|
|
vm, layout=monitor_layout, startup=True))
|
|
|
|
self.assertFalse(mock_run_service.called)
|
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_063_send_monitor_layout_signal_existing(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'xid', None)] = \
|
|
|
|
b'0\x00default=False type=int 123'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'stubdom_xid', None)] = \
|
|
|
|
b'0\x00default=False type=int 124'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'no-monitor-layout', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
|
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
self.addCleanup(unittest.mock.patch.stopall)
|
|
|
|
|
|
|
|
with tempfile.NamedTemporaryFile() as pidfile:
|
|
|
|
pidfile.write(b'1234\n')
|
|
|
|
pidfile.flush()
|
|
|
|
|
|
|
|
patch_guid_pidfile = unittest.mock.patch.object(
|
|
|
|
self.launcher, 'guid_pidfile')
|
|
|
|
mock_guid_pidfile = patch_guid_pidfile.start()
|
|
|
|
mock_guid_pidfile.return_value = pidfile.name
|
|
|
|
|
|
|
|
mock_kill = unittest.mock.patch('os.kill').start()
|
|
|
|
|
|
|
|
monitor_layout = ['1920 1080 0 0\n']
|
|
|
|
loop.run_until_complete(self.launcher.send_monitor_layout(
|
|
|
|
vm, layout=monitor_layout, startup=False))
|
|
|
|
self.assertEqual(mock_guid_pidfile.mock_calls,
|
2019-10-20 19:25:21 +02:00
|
|
|
[unittest.mock.call(123),
|
|
|
|
unittest.mock.call(124)])
|
2017-05-24 12:44:46 +02:00
|
|
|
self.assertEqual(mock_kill.mock_calls,
|
2019-10-20 19:25:21 +02:00
|
|
|
[unittest.mock.call(1234, signal.SIGHUP),
|
|
|
|
unittest.mock.call(1234, signal.SIGHUP)])
|
2017-05-24 12:44:46 +02:00
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
|
|
def test_070_send_monitor_layout_all(self):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
self.addCleanup(loop.close)
|
|
|
|
|
|
|
|
self.app.expected_calls[
|
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
|
|
b'0\x00test-vm class=AppVM state=Running\n' \
|
|
|
|
b'test-vm2 class=AppVM state=Running\n' \
|
2019-10-20 19:20:58 +02:00
|
|
|
b'test-vm3 class=AppVM state=Running\n' \
|
|
|
|
b'test-vm4 class=AppVM state=Halted\n' \
|
|
|
|
b'gui-vm class=AppVM state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm2', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm3', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Running'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
2020-01-15 17:27:49 +01:00
|
|
|
('test-vm4', 'admin.vm.CurrentState', None, None)] = \
|
|
|
|
b'0\x00power_state=Halted'
|
2017-05-24 12:44:46 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'gui', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm2', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'gui', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'0\x00True'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm3', 'admin.vm.feature.CheckWithTemplate',
|
2019-10-20 19:25:21 +02:00
|
|
|
'gui', None)] = \
|
2017-05-24 12:44:46 +02:00
|
|
|
b'0\x00'
|
2019-10-20 19:20:58 +02:00
|
|
|
self.app.expected_calls[
|
|
|
|
('gui-vm', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=True type=vm '
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm2', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm3', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
|
|
|
self.app.expected_calls[
|
|
|
|
('test-vm4', 'admin.vm.property.Get', 'guivm', None)] = \
|
|
|
|
b'0\x00default=False type=vm gui-vm'
|
|
|
|
|
2019-10-20 21:12:31 +02:00
|
|
|
self.app._local_name = 'gui-vm'
|
2017-05-24 12:44:46 +02:00
|
|
|
|
|
|
|
vm = self.app.domains['test-vm']
|
|
|
|
vm2 = self.app.domains['test-vm2']
|
|
|
|
|
|
|
|
self.addCleanup(unittest.mock.patch.stopall)
|
|
|
|
|
|
|
|
mock_send_monitor_layout = unittest.mock.Mock()
|
|
|
|
patch_send_monitor_layout = unittest.mock.patch.object(
|
|
|
|
self.launcher, 'send_monitor_layout',
|
|
|
|
functools.partial(self.mock_coroutine, mock_send_monitor_layout))
|
|
|
|
patch_send_monitor_layout.start()
|
|
|
|
monitor_layout = ['1920 1080 0 0\n']
|
|
|
|
mock_get_monior_layout = unittest.mock.patch(
|
2019-11-17 23:54:05 +01:00
|
|
|
'qubesadmin.tools.qvm_start_daemon.get_monitor_layout').start()
|
2017-05-24 12:44:46 +02:00
|
|
|
mock_get_monior_layout.return_value = monitor_layout
|
|
|
|
|
|
|
|
self.launcher.send_monitor_layout_all()
|
|
|
|
loop.stop()
|
|
|
|
loop.run_forever()
|
|
|
|
|
|
|
|
# test-vm3 not called b/c feature 'gui' set to false
|
|
|
|
# test-vm4 not called b/c not running
|
|
|
|
self.assertCountEqual(mock_send_monitor_layout.mock_calls,
|
2019-10-20 19:25:21 +02:00
|
|
|
[unittest.mock.call(vm, monitor_layout),
|
|
|
|
unittest.mock.call(vm2, monitor_layout)])
|
2017-05-24 12:44:46 +02:00
|
|
|
mock_get_monior_layout.assert_called_once_with()
|
|
|
|
self.assertAllCalled()
|