test_vm_settings.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2016 Marta Marczykowska-Górecka
  6. # <marmarta@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. #
  22. import logging.handlers
  23. import unittest
  24. import unittest.mock
  25. from PyQt5 import QtTest, QtCore
  26. from qubesadmin import Qubes
  27. import qubesmanager.settings as vm_settings
  28. from qubesmanager.tests import init_qtapp
  29. class VMSettingsTest(unittest.TestCase):
  30. def setUp(self):
  31. super(VMSettingsTest, self).setUp()
  32. self.qtapp, self.loop = init_qtapp()
  33. self.mock_qprogress = unittest.mock.patch(
  34. 'PyQt5.QtWidgets.QProgressDialog')
  35. self.mock_qprogress.start()
  36. self.addCleanup(self.mock_qprogress.stop)
  37. self.qapp = Qubes()
  38. if "test-vm" in self.qapp.domains:
  39. del self.qapp.domains["test-vm"]
  40. def tearDown(self):
  41. if "test-vm" in self.qapp.domains:
  42. del self.qapp.domains["test-vm"]
  43. super(VMSettingsTest, self).tearDown()
  44. def test_00_load_correct_tab(self):
  45. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "red")
  46. self.dialog = vm_settings.VMSettingsWindow(
  47. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  48. self.assertTrue(
  49. self.dialog.tabWidget.currentWidget() is self.dialog.basic_tab)
  50. self.dialog.deleteLater()
  51. self.qtapp.processEvents()
  52. self.dialog = vm_settings.VMSettingsWindow(
  53. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  54. self.assertTrue(
  55. self.dialog.tabWidget.currentWidget() is self.dialog.advanced_tab)
  56. self.dialog.deleteLater()
  57. self.qtapp.processEvents()
  58. self.dialog = vm_settings.VMSettingsWindow(
  59. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="firewall")
  60. self.assertTrue(
  61. self.dialog.tabWidget.currentWidget() is self.dialog.firewall_tab)
  62. self.dialog.deleteLater()
  63. self.qtapp.processEvents()
  64. self.dialog = vm_settings.VMSettingsWindow(
  65. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="devices")
  66. self.assertTrue(
  67. self.dialog.tabWidget.currentWidget() is self.dialog.devices_tab)
  68. self.dialog.deleteLater()
  69. self.qtapp.processEvents()
  70. self.dialog = vm_settings.VMSettingsWindow(
  71. self.vm, qapp=self.qtapp, qubesapp=self.qapp,
  72. init_page="applications")
  73. self.assertTrue(
  74. self.dialog.tabWidget.currentWidget() is self.dialog.apps_tab)
  75. self.dialog.deleteLater()
  76. self.qtapp.processEvents()
  77. self.dialog = vm_settings.VMSettingsWindow(
  78. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="services")
  79. self.assertTrue(
  80. self.dialog.tabWidget.currentWidget() is self.dialog.services_tab)
  81. self.dialog.deleteLater()
  82. self.qtapp.processEvents()
  83. def test_01_basic_tab_default(self):
  84. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  85. # set the vm to have a default template and netvm
  86. self.dialog = vm_settings.VMSettingsWindow(
  87. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  88. self.assertEqual(self.dialog.vmname.text(), "test-vm",
  89. "Name displayed incorrectly")
  90. self.assertTrue("blue" in self.dialog.vmlabel.currentText(),
  91. "Incorrect label displayed")
  92. displayed_template = self.dialog.template_name.currentText()
  93. correct_template = self.vm.template.name
  94. self.assertTrue("current" in displayed_template,
  95. "Template incorrectly not shown as current")
  96. self.assertTrue(correct_template in displayed_template,
  97. "Template not displayed correctly")
  98. displayed_netvm = self.dialog.netVM.currentText()
  99. correct_netvm = self.vm.netvm.name
  100. self.assertTrue("current" in displayed_netvm,
  101. "NetVM incorrectly not shown as current")
  102. self.assertTrue(correct_netvm in displayed_netvm,
  103. "NetVM not displayed correctly")
  104. self.assertEqual(self.dialog.include_in_backups.isChecked(),
  105. self.vm.include_in_backups,
  106. "Incorrect 'include in backups' state")
  107. self.assertEqual(self.dialog.autostart_vm.isChecked(),
  108. self.vm.autostart,
  109. "Incorrect 'autostart' state")
  110. self.assertEqual(self.dialog.type_label.text(),
  111. self.vm.klass,
  112. "Incorrect class displayed")
  113. self.assertEqual(self.dialog.ip_label.text(),
  114. self.vm.ip,
  115. "Incorrect IP displayed")
  116. self.assertEqual(self.dialog.netmask_label.text(),
  117. self.vm.visible_netmask,
  118. "Incorrect netmask displayed")
  119. self.assertEqual(self.dialog.gateway_label.text(),
  120. self.vm.visible_gateway,
  121. "Incorrect gateway displayed")
  122. self.assertEqual(self.dialog.max_priv_storage.value(),
  123. self.vm.volumes['private'].size // 1024 ** 2,
  124. "Incorrect max private storage size")
  125. self.assertEqual(self.dialog.root_resize.value(),
  126. self.vm.volumes['root'].size // 1024 ** 2,
  127. "Incorrect max private root size")
  128. def test_02_basic_tab_nones(self):
  129. self.vm = self.qapp.add_new_vm("StandaloneVM", "test-vm", "blue")
  130. # set the vm to have a default template and netvm
  131. self.vm.netvm = None
  132. self.dialog = vm_settings.VMSettingsWindow(
  133. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  134. self.assertEqual("", self.dialog.template_name.currentText(),
  135. "No template incorrectly displayed")
  136. displayed_netvm = self.dialog.netVM.currentText()
  137. self.assertTrue("current" in displayed_netvm,
  138. "None NetVM incorrectly not shown as current")
  139. self.assertTrue("none" in displayed_netvm,
  140. "None NetVM not displayed correctly")
  141. self.assertEqual(self.dialog.type_label.text(), "StandaloneVM",
  142. "Type displayed incorrectly for standaloneVM")
  143. self.assertEqual(self.dialog.ip_label.text(),
  144. "---",
  145. "Incorrect IP displayed")
  146. self.assertEqual(self.dialog.netmask_label.text(),
  147. "---",
  148. "Incorrect netmask displayed")
  149. self.assertEqual(self.dialog.gateway_label.text(),
  150. "---",
  151. "Incorrect gateway displayed")
  152. def test_03_change_label(self):
  153. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  154. self.dialog = vm_settings.VMSettingsWindow(
  155. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  156. self.dialog.show()
  157. new_label = self._set_noncurrent(self.dialog.vmlabel)
  158. self._click_ok()
  159. self.assertEqual(str(self.vm.label), new_label,
  160. "Label is not set correctly")
  161. def test_04_change_template(self):
  162. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  163. self.dialog = vm_settings.VMSettingsWindow(
  164. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  165. new_template = self._set_noncurrent(self.dialog.template_name)
  166. self._click_ok()
  167. self.assertEqual(self.vm.template.name, new_template,
  168. "Template is not set correctly")
  169. def test_05_change_networking(self):
  170. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  171. self.dialog = vm_settings.VMSettingsWindow(
  172. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  173. new_netvm = self._set_noncurrent(self.dialog.netVM)
  174. self._click_ok()
  175. self.assertEqual(self.vm.netvm.name, new_netvm,
  176. "NetVM is not set correctly")
  177. def test_06_change_networking_none(self):
  178. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  179. self.dialog = vm_settings.VMSettingsWindow(
  180. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  181. self._set_none(self.dialog.netVM)
  182. self._click_ok()
  183. self.assertIsNone(self.vm.netvm,
  184. "None netVM is not set correctly")
  185. def test_07_change_networking_to_default(self):
  186. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  187. for vm in self.qapp.domains:
  188. if getattr(vm, 'provides_network', False)\
  189. and vm != self.qapp.default_netvm:
  190. self.vm.netvm = vm
  191. break
  192. self.dialog = vm_settings.VMSettingsWindow(
  193. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  194. new_netvm = self._set_default(self.dialog.netVM)
  195. self._click_ok()
  196. self.assertTrue(self.vm.netvm.name in new_netvm,
  197. "NetVM is not set correctly")
  198. self.assertTrue(self.vm.property_is_default('netvm'))
  199. def test_08_basic_checkboxes_true(self):
  200. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  201. self.dialog = vm_settings.VMSettingsWindow(
  202. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  203. self.dialog.show()
  204. self.dialog.include_in_backups.setChecked(True)
  205. self.dialog.autostart_vm.setChecked(True)
  206. self._click_ok()
  207. self.assertTrue(self.vm.include_in_backups,
  208. "Include in backups not set to true")
  209. self.assertTrue(self.vm.autostart,
  210. "Autostart not set to true")
  211. def test_09_basic_checkboxes_false(self):
  212. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  213. self.dialog = vm_settings.VMSettingsWindow(
  214. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  215. self.dialog.show()
  216. self.dialog.include_in_backups.setChecked(False)
  217. self.dialog.autostart_vm.setChecked(False)
  218. self._click_ok()
  219. self.assertFalse(self.vm.include_in_backups,
  220. "Include in backups not set to false")
  221. self.assertFalse(self.vm.autostart,
  222. "Autostart not set to false")
  223. def test_10_increase_private_storage(self):
  224. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  225. self.dialog = vm_settings.VMSettingsWindow(
  226. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  227. current_storage = self.vm.volumes['private'].size // 1024**2
  228. new_storage = current_storage + 512
  229. self.dialog.max_priv_storage.setValue(new_storage)
  230. self._click_ok()
  231. self.assertEqual(self.vm.volumes['private'].size // 1024**2,
  232. new_storage)
  233. # TODO are dependencies correctly processed
  234. @unittest.mock.patch('PyQt5.QtWidgets.QProgressDialog')
  235. @unittest.mock.patch('PyQt5.QtWidgets.QInputDialog.getText')
  236. @unittest.mock.patch('qubesmanager.settings.RenameVMThread')
  237. def test_11_rename_vm(self, mock_thread, mock_input, _):
  238. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  239. self.dialog = vm_settings.VMSettingsWindow(
  240. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  241. self.assertTrue(self.dialog.rename_vm_button.isEnabled())
  242. mock_input.return_value = ("test-vm2", True)
  243. self.dialog.rename_vm_button.click()
  244. mock_thread.assert_called_with(self.vm, "test-vm2", unittest.mock.ANY)
  245. mock_thread().start.assert_called_with()
  246. # TODO: thread tests for rename
  247. @unittest.mock.patch('PyQt5.QtWidgets.QProgressDialog')
  248. @unittest.mock.patch('PyQt5.QtWidgets.QInputDialog.getText')
  249. @unittest.mock.patch('qubesmanager.common_threads.CloneVMThread')
  250. def test_12_clone_vm(self, mock_thread, mock_input, _):
  251. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  252. self.dialog = vm_settings.VMSettingsWindow(
  253. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  254. self.assertTrue(self.dialog.clone_vm_button.isEnabled())
  255. mock_input.return_value = ("test-vm2", True)
  256. self.dialog.clone_vm_button.click()
  257. mock_thread.assert_called_with(self.vm, "test-vm2")
  258. mock_thread().start.assert_called_with()
  259. @unittest.mock.patch('PyQt5.QtWidgets.QMessageBox.warning')
  260. @unittest.mock.patch('PyQt5.QtWidgets.QProgressDialog')
  261. @unittest.mock.patch('PyQt5.QtWidgets.QInputDialog.getText')
  262. @unittest.mock.patch('qubesmanager.common_threads.RemoveVMThread')
  263. def test_13_remove_vm(self, mock_thread, mock_input, _, mock_warning):
  264. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  265. self.dialog = vm_settings.VMSettingsWindow(
  266. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="basic")
  267. self.assertTrue(self.dialog.delete_vm_button.isEnabled())
  268. # try with a wrong name
  269. mock_input.return_value = ("test-vm2", True)
  270. self.dialog.delete_vm_button.click()
  271. self.assertEqual(mock_warning.call_count, 1)
  272. # and now correct one
  273. mock_input.return_value = ("test-vm", True)
  274. self.dialog.delete_vm_button.click()
  275. mock_thread.assert_called_with(self.vm)
  276. mock_thread().start.assert_called_with()
  277. # Advanced Tab
  278. def test_20_advanced_loads(self):
  279. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  280. self.dialog = vm_settings.VMSettingsWindow(
  281. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  282. self.assertEqual(self.dialog.init_mem.value(), self.vm.memory,
  283. "Incorrect initial memory")
  284. # default maxmem
  285. self.assertEqual(self.dialog.max_mem_size.value(),
  286. self.vm.property_get_default('maxmem'),
  287. "Maxmem incorrectly displayed for default value")
  288. self.assertEqual(self.dialog.vcpus.value(), self.vm.vcpus,
  289. "Incorrect number of VCPUs")
  290. self.assertTrue(self.dialog.include_in_balancing.isChecked(),
  291. "Include in memory balancing incorrectly not checked")
  292. # debug mode
  293. self.assertEqual(self.dialog.run_in_debug_mode.isChecked(),
  294. self.vm.debug,
  295. "Incorrect 'run in debug mode' state")
  296. # kernel
  297. self.assertTrue(self.vm.kernel in self.dialog.kernel.currentText(),
  298. "Kernel displayed incorrectly")
  299. # default dispvm
  300. self.assertTrue(
  301. str(self.vm.default_dispvm) in
  302. self.dialog.default_dispvm.currentText(),
  303. "Default dispVM incorrectly displayed")
  304. self.assertEqual(self.vm.template_for_dispvms,
  305. self.dialog.dvm_template_checkbox.isChecked(),
  306. "Incorrectly shown to be template for dispvms")
  307. # virtmode
  308. self.assertTrue("default" in self.dialog.virt_mode.currentText())
  309. self.assertTrue("PVH" in self.dialog.virt_mode.currentText())
  310. def test_21_nondefaultmaxmem(self):
  311. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  312. self.vm.maxmem = 5000
  313. self.dialog = vm_settings.VMSettingsWindow(
  314. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  315. self.assertEqual(self.dialog.max_mem_size.value(), 5000)
  316. self.dialog.include_in_balancing.setChecked(False)
  317. self._click_ok()
  318. self.assertEqual(self.vm.maxmem, 0)
  319. self.dialog.deleteLater()
  320. self.qtapp.processEvents()
  321. self.dialog = vm_settings.VMSettingsWindow(
  322. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  323. self.assertFalse(self.dialog.include_in_balancing.isChecked())
  324. self.dialog.include_in_balancing.setChecked(True)
  325. self.assertEqual(self.dialog.max_mem_size.value(), 5000)
  326. self._click_ok()
  327. self.assertEqual(self.vm.maxmem, 5000)
  328. def test_22_initmem(self):
  329. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  330. self.vm.memory = 500
  331. self.dialog = vm_settings.VMSettingsWindow(
  332. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  333. self.assertEqual(self.dialog.init_mem.value(), 500,
  334. "Incorrect initial memory")
  335. self.dialog.init_mem.setValue(600)
  336. self._click_ok()
  337. self.assertEqual(self.vm.memory, 600, "Setting initial memory failed")
  338. def test_23_vcpus(self):
  339. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  340. self.vm.vcpus = 1
  341. self.dialog = vm_settings.VMSettingsWindow(
  342. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  343. self.assertEqual(self.dialog.vcpus.value(), 1,
  344. "Incorrect number of VCPUs")
  345. self.dialog.vcpus.setValue(2)
  346. self._click_ok()
  347. self.assertEqual(self.vm.vcpus, 2,
  348. "Incorrect number of VCPUs")
  349. def test_24_kernel(self):
  350. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  351. self.dialog = vm_settings.VMSettingsWindow(
  352. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  353. self.dialog.show()
  354. new_kernel = self._set_noncurrent(self.dialog.kernel)
  355. self._click_ok()
  356. self.assertEqual(self.vm.kernel, new_kernel)
  357. self.dialog.deleteLater()
  358. self.qtapp.processEvents()
  359. self.dialog = vm_settings.VMSettingsWindow(
  360. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  361. self.dialog.show()
  362. self._set_default(self.dialog.kernel)
  363. self._click_ok()
  364. self.assertTrue(self.vm.property_is_default('kernel'))
  365. def test_25_virtmode_change(self):
  366. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  367. modes = ["HVM", "PVH", "PV"]
  368. for mode in modes:
  369. self.dialog = vm_settings.VMSettingsWindow(
  370. self.vm, qapp=self.qtapp, qubesapp=self.qapp,
  371. init_page="advanced")
  372. self._set_value(self.dialog.virt_mode, mode)
  373. self._click_ok()
  374. self.assertEqual(self.vm.virt_mode.upper(), mode)
  375. self.dialog.deleteLater()
  376. self.qtapp.processEvents()
  377. self.dialog = vm_settings.VMSettingsWindow(
  378. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  379. self._set_default(self.dialog.virt_mode)
  380. self._click_ok()
  381. self.assertTrue(self.vm.property_is_default('virt_mode'))
  382. def test_26_default_dispvm(self):
  383. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  384. self.dialog = vm_settings.VMSettingsWindow(
  385. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  386. new_dvm = self._set_noncurrent(self.dialog.default_dispvm)
  387. self._click_ok()
  388. self.assertEqual(self.vm.default_dispvm.name, new_dvm)
  389. self.dialog.deleteLater()
  390. self.qtapp.processEvents()
  391. self.dialog = vm_settings.VMSettingsWindow(
  392. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  393. self._set_default(self.dialog.default_dispvm)
  394. self._click_ok()
  395. self.assertTrue(self.vm.property_is_default('default_dispvm'))
  396. @unittest.mock.patch('subprocess.check_call')
  397. def test_27_boot_cdrom(self, mock_call):
  398. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  399. self.dialog = vm_settings.VMSettingsWindow(
  400. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  401. self.dialog.boot_from_device_button.click()
  402. mock_call.assert_called_with(['qubes-vm-boot-from-device', "test-vm"])
  403. def test_28_advanced_debug_false(self):
  404. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  405. self.dialog = vm_settings.VMSettingsWindow(
  406. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  407. self.dialog.show()
  408. self.dialog.run_in_debug_mode.setChecked(False)
  409. self._click_ok()
  410. self.assertFalse(self.vm.debug,
  411. "Debug mode not set to false")
  412. def test_28_advanced_debug_true(self):
  413. self.vm = self.qapp.add_new_vm("AppVM", "test-vm", "blue")
  414. self.dialog = vm_settings.VMSettingsWindow(
  415. self.vm, qapp=self.qtapp, qubesapp=self.qapp, init_page="advanced")
  416. self.dialog.show()
  417. self.dialog.run_in_debug_mode.setChecked(True)
  418. self._click_ok()
  419. self.assertTrue(self.vm.debug,
  420. "Debug mode not set to true")
  421. def _click_ok(self):
  422. okwidget = self.dialog.buttonBox.button(
  423. self.dialog.buttonBox.Ok)
  424. QtTest.QTest.mouseClick(okwidget, QtCore.Qt.LeftButton)
  425. def _click_cancel(self):
  426. cancelwidget = self.dialog.buttonBox.button(
  427. self.dialog.buttonBox.Cancel)
  428. QtTest.QTest.mouseClick(cancelwidget, QtCore.Qt.LeftButton)
  429. def _set_noncurrent(self, widget):
  430. if widget.count() < 2:
  431. self.skipTest("not enough choices for " + widget.objectName())
  432. widget.setCurrentIndex(0)
  433. while widget.currentText().endswith("(current)") \
  434. or widget.currentText().startswith("(none)"):
  435. widget.setCurrentIndex(widget.currentIndex() + 1)
  436. return widget.currentText()
  437. def _set_default(self, widget):
  438. if widget.count() < 2:
  439. self.skipTest("not enough choices for " + widget.objectName())
  440. widget.setCurrentIndex(0)
  441. while "default" not in widget.currentText():
  442. widget.setCurrentIndex(widget.currentIndex() + 1)
  443. return widget.currentText()
  444. def _set_none(self, widget):
  445. if widget.count() < 2:
  446. self.skipTest("not enough choices for " + widget.objectName())
  447. widget.setCurrentIndex(0)
  448. while "none" not in widget.currentText():
  449. widget.setCurrentIndex(widget.currentIndex() + 1)
  450. return widget.currentText()
  451. def _set_value(self, widget, value):
  452. if widget.count() < 2:
  453. self.skipTest("not enough choices for " + widget.objectName())
  454. widget.setCurrentIndex(0)
  455. while value != widget.currentText():
  456. widget.setCurrentIndex(widget.currentIndex() + 1)
  457. return widget.currentText()
  458. if __name__ == "__main__":
  459. ha_syslog = logging.handlers.SysLogHandler('/dev/log')
  460. ha_syslog.setFormatter(
  461. logging.Formatter('%(name)s[%(process)d]: %(message)s'))
  462. logging.root.addHandler(ha_syslog)
  463. unittest.main()