hvm.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2016 Marek Marczykowski-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (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
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. #
  24. import qubes.tests
  25. from qubes.qubes import QubesException
  26. class TC_10_HVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  27. # TODO: test with some OS inside
  28. # TODO: windows tools tests
  29. def test_000_create_start(self):
  30. testvm1 = self.qc.add_new_vm("QubesHVm",
  31. name=self.make_vm_name('vm1'))
  32. testvm1.create_on_disk(verbose=False)
  33. self.qc.save()
  34. self.qc.unlock_db()
  35. testvm1.start()
  36. self.assertEquals(testvm1.get_power_state(), "Running")
  37. def test_010_create_start_template(self):
  38. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  39. name=self.make_vm_name('template'))
  40. templatevm.create_on_disk(verbose=False)
  41. self.qc.save()
  42. self.qc.unlock_db()
  43. templatevm.start()
  44. self.assertEquals(templatevm.get_power_state(), "Running")
  45. def test_020_create_start_template_vm(self):
  46. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  47. name=self.make_vm_name('template'))
  48. templatevm.create_on_disk(verbose=False)
  49. testvm2 = self.qc.add_new_vm("QubesHVm",
  50. name=self.make_vm_name('vm2'),
  51. template=templatevm)
  52. testvm2.create_on_disk(verbose=False)
  53. self.qc.save()
  54. self.qc.unlock_db()
  55. testvm2.start()
  56. self.assertEquals(testvm2.get_power_state(), "Running")
  57. def test_030_prevent_simultaneus_start(self):
  58. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  59. name=self.make_vm_name('template'))
  60. templatevm.create_on_disk(verbose=False)
  61. testvm2 = self.qc.add_new_vm("QubesHVm",
  62. name=self.make_vm_name('vm2'),
  63. template=templatevm)
  64. testvm2.create_on_disk(verbose=False)
  65. self.qc.save()
  66. self.qc.unlock_db()
  67. templatevm.start()
  68. self.assertEquals(templatevm.get_power_state(), "Running")
  69. self.assertRaises(QubesException, testvm2.start)
  70. templatevm.force_shutdown()
  71. testvm2.start()
  72. self.assertEquals(testvm2.get_power_state(), "Running")
  73. self.assertRaises(QubesException, templatevm.start)
  74. def test_100_resize_root_img(self):
  75. testvm1 = self.qc.add_new_vm("QubesHVm",
  76. name=self.make_vm_name('vm1'))
  77. testvm1.create_on_disk(verbose=False)
  78. self.qc.save()
  79. self.qc.unlock_db()
  80. testvm1.resize_root_img(30*1024**3)
  81. self.assertEquals(testvm1.get_root_img_sz(), 30*1024**3)
  82. testvm1.start()
  83. self.assertEquals(testvm1.get_power_state(), "Running")
  84. # TODO: launch some OS there and check the size
  85. def test_200_start_invalid_drive(self):
  86. """Regression test for #1619"""
  87. testvm1 = self.qc.add_new_vm("QubesHVm",
  88. name=self.make_vm_name('vm1'))
  89. testvm1.create_on_disk(verbose=False)
  90. testvm1.drive = 'hd:dom0:/invalid'
  91. self.qc.save()
  92. self.qc.unlock_db()
  93. try:
  94. testvm1.start()
  95. except Exception as e:
  96. self.assertIsInstance(e, QubesException)
  97. else:
  98. self.fail('No exception raised')
  99. def test_201_start_invalid_drive_cdrom(self):
  100. """Regression test for #1619"""
  101. testvm1 = self.qc.add_new_vm("QubesHVm",
  102. name=self.make_vm_name('vm1'))
  103. testvm1.create_on_disk(verbose=False)
  104. testvm1.drive = 'cdrom:dom0:/invalid'
  105. self.qc.save()
  106. self.qc.unlock_db()
  107. try:
  108. testvm1.start()
  109. except Exception as e:
  110. self.assertIsInstance(e, QubesException)
  111. else:
  112. self.fail('No exception raised')