adminvm.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library 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 GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  19. #
  20. import unittest
  21. import unittest.mock
  22. import qubes
  23. import qubes.exc
  24. import qubes.vm
  25. import qubes.vm.adminvm
  26. import qubes.tests
  27. class TC_00_AdminVM(qubes.tests.QubesTestCase):
  28. def setUp(self):
  29. super().setUp()
  30. try:
  31. self.app = qubes.tests.vm.TestApp()
  32. with unittest.mock.patch.object(
  33. qubes.vm.adminvm.AdminVM, 'start_qdb_watch') as mock_qdb:
  34. self.vm = qubes.vm.adminvm.AdminVM(self.app,
  35. xml=None)
  36. mock_qdb.assert_called_once_with()
  37. self.addCleanup(self.cleanup_adminvm)
  38. except: # pylint: disable=bare-except
  39. if self.id().endswith('.test_000_init'):
  40. raise
  41. self.skipTest('setup failed')
  42. def cleanup_adminvm(self):
  43. self.vm.close()
  44. del self.vm
  45. def test_000_init(self):
  46. pass
  47. def test_100_xid(self):
  48. self.assertEqual(self.vm.xid, 0)
  49. def test_101_libvirt_domain(self):
  50. with unittest.mock.patch.object(self.app, 'vmm') as mock_vmm:
  51. self.assertIsNotNone(self.vm.libvirt_domain)
  52. self.assertEqual(mock_vmm.mock_calls, [
  53. ('libvirt_conn.lookupByID', (0,), {}),
  54. ])
  55. def test_300_is_running(self):
  56. self.assertTrue(self.vm.is_running())
  57. def test_301_get_power_state(self):
  58. self.assertEqual(self.vm.get_power_state(), 'Running')
  59. def test_302_get_mem(self):
  60. self.assertGreater(self.vm.get_mem(), 0)
  61. @unittest.skip('mock object does not support this')
  62. def test_303_get_mem_static_max(self):
  63. self.assertGreater(self.vm.get_mem_static_max(), 0)
  64. def test_310_start(self):
  65. with self.assertRaises(qubes.exc.QubesException):
  66. self.vm.start()
  67. @unittest.skip('this functionality is undecided')
  68. def test_311_suspend(self):
  69. with self.assertRaises(qubes.exc.QubesException):
  70. self.vm.suspend()