adminvm.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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('dom0')
  38. except: # pylint: disable=bare-except
  39. if self.id().endswith('.test_000_init'):
  40. raise
  41. self.skipTest('setup failed')
  42. def test_000_init(self):
  43. pass
  44. def test_100_xid(self):
  45. self.assertEqual(self.vm.xid, 0)
  46. def test_101_libvirt_domain(self):
  47. with unittest.mock.patch.object(self.app, 'vmm') as mock_vmm:
  48. self.assertIsNotNone(self.vm.libvirt_domain)
  49. self.assertEqual(mock_vmm.mock_calls, [
  50. ('libvirt_conn.lookupByID', (0,), {}),
  51. ])
  52. def test_300_is_running(self):
  53. self.assertTrue(self.vm.is_running())
  54. def test_301_get_power_state(self):
  55. self.assertEqual(self.vm.get_power_state(), 'Running')
  56. def test_302_get_mem(self):
  57. self.assertGreater(self.vm.get_mem(), 0)
  58. @unittest.skip('mock object does not support this')
  59. def test_303_get_mem_static_max(self):
  60. self.assertGreater(self.vm.get_mem_static_max(), 0)
  61. def test_310_start(self):
  62. with self.assertRaises(qubes.exc.QubesException):
  63. self.vm.start()
  64. @unittest.skip('this functionality is undecided')
  65. def test_311_suspend(self):
  66. with self.assertRaises(qubes.exc.QubesException):
  67. self.vm.suspend()