adminvm.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 qubes
  23. import qubes.exc
  24. import qubes.vm
  25. import qubes.vm.adminvm
  26. import qubes.tests
  27. @qubes.tests.skipUnlessDom0
  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. self.vm = qubes.vm.adminvm.AdminVM(self.app,
  34. xml=None, qid=0, name='dom0')
  35. except: # pylint: disable=bare-except
  36. if self.id().endswith('.test_000_init'):
  37. raise
  38. self.skipTest('setup failed')
  39. def test_000_init(self):
  40. pass
  41. def test_100_xid(self):
  42. self.assertEqual(self.vm.xid, 0)
  43. def test_101_libvirt_domain(self):
  44. self.assertIs(self.vm.libvirt_domain, None)
  45. def test_200_libvirt_netvm(self):
  46. self.assertIs(self.vm.netvm, None)
  47. def test_300_is_running(self):
  48. self.assertTrue(self.vm.is_running())
  49. def test_301_get_power_state(self):
  50. self.assertEqual(self.vm.get_power_state(), 'Running')
  51. def test_302_get_mem(self):
  52. self.assertGreater(self.vm.get_mem(), 0)
  53. @unittest.skip('mock object does not support this')
  54. def test_303_get_mem_static_max(self):
  55. self.assertGreater(self.vm.get_mem_static_max(), 0)
  56. def test_304_get_disk_utilization(self):
  57. self.assertEqual(self.vm.storage.get_disk_utilization(), 0)
  58. def test_305_has_no_private_volume(self):
  59. with self.assertRaises(KeyError):
  60. self.vm.volumes['private']
  61. def test_306_has_no_root_volume(self):
  62. with self.assertRaises(KeyError):
  63. self.vm.volumes['root']
  64. def test_307_has_no_volatile_volume(self):
  65. with self.assertRaises(KeyError):
  66. self.vm.volumes['volatile']
  67. def test_310_start(self):
  68. with self.assertRaises(qubes.exc.QubesException):
  69. self.vm.start()
  70. @unittest.skip('this functionality is undecided')
  71. def test_311_suspend(self):
  72. with self.assertRaises(qubes.exc.QubesException):
  73. self.vm.suspend()