adminvm.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  5. # Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. import unittest
  22. import unittest.mock
  23. import qubes
  24. import qubes.exc
  25. import qubes.vm
  26. import qubes.vm.adminvm
  27. import qubes.tests
  28. class TC_00_AdminVM(qubes.tests.QubesTestCase):
  29. def setUp(self):
  30. super().setUp()
  31. try:
  32. self.app = qubes.tests.vm.TestApp()
  33. with unittest.mock.patch.object(
  34. qubes.vm.adminvm.AdminVM, 'start_qdb_watch') as mock_qdb:
  35. self.vm = qubes.vm.adminvm.AdminVM(self.app,
  36. xml=None)
  37. mock_qdb.assert_called_once_with()
  38. self.addCleanup(self.cleanup_adminvm)
  39. except: # pylint: disable=bare-except
  40. if self.id().endswith('.test_000_init'):
  41. raise
  42. self.skipTest('setup failed')
  43. def cleanup_adminvm(self):
  44. self.vm.close()
  45. del self.vm
  46. def test_000_init(self):
  47. pass
  48. def test_100_xid(self):
  49. self.assertEqual(self.vm.xid, 0)
  50. def test_101_libvirt_domain(self):
  51. with unittest.mock.patch.object(self.app, 'vmm') as mock_vmm:
  52. self.assertIsNotNone(self.vm.libvirt_domain)
  53. self.assertEqual(mock_vmm.mock_calls, [
  54. ('libvirt_conn.lookupByID', (0,), {}),
  55. ])
  56. def test_300_is_running(self):
  57. self.assertTrue(self.vm.is_running())
  58. def test_301_get_power_state(self):
  59. self.assertEqual(self.vm.get_power_state(), 'Running')
  60. def test_302_get_mem(self):
  61. self.assertGreater(self.vm.get_mem(), 0)
  62. @unittest.skip('mock object does not support this')
  63. def test_303_get_mem_static_max(self):
  64. self.assertGreater(self.vm.get_mem_static_max(), 0)
  65. def test_310_start(self):
  66. with self.assertRaises(qubes.exc.QubesException):
  67. self.vm.start()
  68. @unittest.skip('this functionality is undecided')
  69. def test_311_suspend(self):
  70. with self.assertRaises(qubes.exc.QubesException):
  71. self.vm.suspend()