hvm.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library 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 GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  21. #
  22. #
  23. import qubes.tests
  24. from qubes.qubes import QubesException
  25. class TC_10_HVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  26. # TODO: test with some OS inside
  27. # TODO: windows tools tests
  28. def test_000_create_start(self):
  29. testvm1 = self.qc.add_new_vm("QubesHVm",
  30. name=self.make_vm_name('vm1'))
  31. testvm1.create_on_disk(verbose=False)
  32. self.qc.save()
  33. self.qc.unlock_db()
  34. testvm1.start()
  35. self.assertEquals(testvm1.get_power_state(), "Running")
  36. def test_010_create_start_template(self):
  37. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  38. name=self.make_vm_name('template'))
  39. templatevm.create_on_disk(verbose=False)
  40. self.qc.save()
  41. self.qc.unlock_db()
  42. templatevm.start()
  43. self.assertEquals(templatevm.get_power_state(), "Running")
  44. def test_020_create_start_template_vm(self):
  45. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  46. name=self.make_vm_name('template'))
  47. templatevm.create_on_disk(verbose=False)
  48. testvm2 = self.qc.add_new_vm("QubesHVm",
  49. name=self.make_vm_name('vm2'),
  50. template=templatevm)
  51. testvm2.create_on_disk(verbose=False)
  52. self.qc.save()
  53. self.qc.unlock_db()
  54. testvm2.start()
  55. self.assertEquals(testvm2.get_power_state(), "Running")
  56. def test_030_prevent_simultaneus_start(self):
  57. templatevm = self.qc.add_new_vm("QubesTemplateHVm",
  58. name=self.make_vm_name('template'))
  59. templatevm.create_on_disk(verbose=False)
  60. testvm2 = self.qc.add_new_vm("QubesHVm",
  61. name=self.make_vm_name('vm2'),
  62. template=templatevm)
  63. testvm2.create_on_disk(verbose=False)
  64. self.qc.save()
  65. self.qc.unlock_db()
  66. templatevm.start()
  67. self.assertEquals(templatevm.get_power_state(), "Running")
  68. self.assertRaises(QubesException, testvm2.start)
  69. templatevm.force_shutdown()
  70. testvm2.start()
  71. self.assertEquals(testvm2.get_power_state(), "Running")
  72. self.assertRaises(QubesException, templatevm.start)
  73. def test_100_resize_root_img(self):
  74. testvm1 = self.qc.add_new_vm("QubesHVm",
  75. name=self.make_vm_name('vm1'))
  76. testvm1.create_on_disk(verbose=False)
  77. self.qc.save()
  78. self.qc.unlock_db()
  79. testvm1.resize_root_img(30*1024**3)
  80. self.assertEquals(testvm1.get_root_img_sz(), 30*1024**3)
  81. testvm1.start()
  82. self.assertEquals(testvm1.get_power_state(), "Running")
  83. # TODO: launch some OS there and check the size
  84. def test_200_start_invalid_drive(self):
  85. """Regression test for #1619"""
  86. testvm1 = self.qc.add_new_vm("QubesHVm",
  87. name=self.make_vm_name('vm1'))
  88. testvm1.create_on_disk(verbose=False)
  89. testvm1.drive = 'hd:dom0:/invalid'
  90. self.qc.save()
  91. self.qc.unlock_db()
  92. try:
  93. testvm1.start()
  94. except Exception as e:
  95. self.assertIsInstance(e, QubesException)
  96. else:
  97. self.fail('No exception raised')
  98. def test_201_start_invalid_drive_cdrom(self):
  99. """Regression test for #1619"""
  100. testvm1 = self.qc.add_new_vm("QubesHVm",
  101. name=self.make_vm_name('vm1'))
  102. testvm1.create_on_disk(verbose=False)
  103. testvm1.drive = 'cdrom:dom0:/invalid'
  104. self.qc.save()
  105. self.qc.unlock_db()
  106. try:
  107. testvm1.start()
  108. except Exception as e:
  109. self.assertIsInstance(e, QubesException)
  110. else:
  111. self.fail('No exception raised')