adminvm.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. import unittest
  24. import qubes
  25. import qubes.exc
  26. import qubes.vm.adminvm
  27. import qubes.tests
  28. class TestVMM(object):
  29. # pylint: disable=too-few-public-methods
  30. def __init__(self, offline_mode=False):
  31. self.offline_mode = offline_mode
  32. class TestHost(object):
  33. # pylint: disable=too-few-public-methods
  34. def __init__(self):
  35. self.memory_total = 1000
  36. # this probably can be shared and not as dummy as is
  37. class TestApp(qubes.tests.TestEmitter):
  38. def __init__(self):
  39. super(TestApp, self).__init__()
  40. self.vmm = TestVMM()
  41. self.host = TestHost()
  42. @qubes.tests.skipUnlessDom0
  43. class TC_00_AdminVM(qubes.tests.QubesTestCase):
  44. def setUp(self):
  45. try:
  46. self.app = TestApp()
  47. self.vm = qubes.vm.adminvm.AdminVM(self.app,
  48. xml=None, qid=0, name='dom0')
  49. except: # pylint: disable=bare-except
  50. if self.id().endswith('.test_000_init'):
  51. raise
  52. self.skipTest('setup failed')
  53. def test_000_init(self):
  54. pass
  55. def test_100_xid(self):
  56. self.assertEqual(self.vm.xid, 0)
  57. def test_101_libvirt_domain(self):
  58. self.assertIs(self.vm.libvirt_domain, None)
  59. def test_200_libvirt_netvm(self):
  60. self.assertIs(self.vm.netvm, None)
  61. def test_300_is_running(self):
  62. self.assertTrue(self.vm.is_running())
  63. def test_301_get_power_state(self):
  64. self.assertEqual(self.vm.get_power_state(), 'Running')
  65. def test_302_get_mem(self):
  66. self.assertGreater(self.vm.get_mem(), 0)
  67. @unittest.skip('mock object does not support this')
  68. def test_303_get_mem_static_max(self):
  69. self.assertGreater(self.vm.get_mem_static_max(), 0)
  70. def test_304_get_disk_utilization(self):
  71. self.assertEqual(self.vm.get_disk_utilization(), 0)
  72. def test_305_get_disk_utilization_private_img(self):
  73. # pylint: disable=invalid-name
  74. self.assertEqual(self.vm.get_disk_utilization_private_img(), 0)
  75. def test_306_get_private_img_sz(self):
  76. self.assertEqual(self.vm.get_private_img_sz(), 0)
  77. def test_307_verify_files(self):
  78. self.assertEqual(self.vm.get_private_img_sz(), 0)
  79. def test_310_start(self):
  80. with self.assertRaises(qubes.exc.QubesException):
  81. self.vm.start()
  82. @unittest.skip('this functionality is undecided')
  83. def test_311_suspend(self):
  84. with self.assertRaises(qubes.exc.QubesException):
  85. self.vm.suspend()