adminvm.py 2.9 KB

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