basic.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/python
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2014-2015
  7. # Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import multiprocessing
  25. import os
  26. import shutil
  27. import unittest
  28. import time
  29. from qubes.qubes import QubesVmCollection, QubesException, system_path
  30. import qubes.qubes
  31. import qubes.tests
  32. class TC_00_Basic(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  33. def test_000_create(self):
  34. vmname = self.make_vm_name('appvm')
  35. vm = self.qc.add_new_vm('QubesAppVm',
  36. name=vmname, template=self.qc.get_default_template())
  37. self.assertIsNotNone(vm)
  38. self.assertEqual(vm.name, vmname)
  39. self.assertEqual(vm.template, self.qc.get_default_template())
  40. vm.create_on_disk(verbose=False)
  41. with self.assertNotRaises(qubes.qubes.QubesException):
  42. vm.verify_files()
  43. class TC_01_Properties(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  44. def setUp(self):
  45. super(TC_01_Properties, self).setUp()
  46. self.vmname = self.make_vm_name('appvm')
  47. self.vm = self.qc.add_new_vm('QubesAppVm',
  48. name=self.vmname, template=self.qc.get_default_template())
  49. self.vm.create_on_disk(verbose=False)
  50. def save_and_reload_db(self):
  51. super(TC_01_Properties, self).save_and_reload_db()
  52. if hasattr(self, 'vm'):
  53. self.vm = self.qc.get(self.vm.qid, None)
  54. if hasattr(self, 'netvm'):
  55. self.netvm = self.qc.get(self.netvm.qid, None)
  56. def test_000_rename(self):
  57. newname = self.make_vm_name('newname')
  58. self.assertEqual(self.vm.name, self.vmname)
  59. #TODO: change to setting property when implemented
  60. self.vm.set_name(newname)
  61. self.assertEqual(self.vm.name, newname)
  62. self.assertEqual(self.vm.dir_path,
  63. os.path.join(system_path['qubes_appvms_dir'], newname))
  64. self.assertEqual(self.vm.conf_file,
  65. os.path.join(self.vm.dir_path, newname + '.conf'))
  66. self.assertTrue(os.path.exists(
  67. os.path.join(self.vm.dir_path, "apps", newname + "-vm.directory")))
  68. # FIXME: set whitelisted-appmenus.list first
  69. self.assertTrue(os.path.exists(
  70. os.path.join(self.vm.dir_path, "apps", newname + "-firefox.desktop")))
  71. self.assertTrue(os.path.exists(
  72. os.path.join(os.getenv("HOME"), ".local/share/desktop-directories",
  73. newname + "-vm.directory")))
  74. self.assertTrue(os.path.exists(
  75. os.path.join(os.getenv("HOME"), ".local/share/applications",
  76. newname + "-firefox.desktop")))
  77. self.assertFalse(os.path.exists(
  78. os.path.join(os.getenv("HOME"), ".local/share/desktop-directories",
  79. self.vmname + "-vm.directory")))
  80. self.assertFalse(os.path.exists(
  81. os.path.join(os.getenv("HOME"), ".local/share/applications",
  82. self.vmname + "-firefox.desktop")))
  83. def test_010_netvm(self):
  84. if self.qc.get_default_netvm() is None:
  85. self.skip("Set default NetVM before running this test")
  86. self.netvm = self.qc.add_new_vm("QubesNetVm",
  87. name=self.make_vm_name('netvm'),
  88. template=self.qc.get_default_template())
  89. self.netvm.create_on_disk(verbose=False)
  90. # TODO: remove this line after switching to core3
  91. self.save_and_reload_db()
  92. self.assertEquals(self.vm.netvm, self.qc.get_default_netvm())
  93. self.vm.uses_default_netvm = False
  94. self.vm.netvm = None
  95. self.assertIsNone(self.vm.netvm)
  96. self.save_and_reload_db()
  97. self.assertIsNone(self.vm.netvm)
  98. self.vm.netvm = self.qc[self.netvm.qid]
  99. self.assertEquals(self.vm.netvm.qid, self.netvm.qid)
  100. self.save_and_reload_db()
  101. self.assertEquals(self.vm.netvm.qid, self.netvm.qid)
  102. self.vm.uses_default_netvm = True
  103. # TODO: uncomment when properly implemented
  104. # self.assertEquals(self.vm.netvm.qid, self.qc.get_default_netvm().qid)
  105. self.save_and_reload_db()
  106. self.assertEquals(self.vm.netvm.qid, self.qc.get_default_netvm().qid)
  107. with self.assertRaises(ValueError):
  108. self.vm.netvm = self.vm
  109. def test_020_dispvm_netvm(self):
  110. if self.qc.get_default_netvm() is None:
  111. self.skip("Set default NetVM before running this test")
  112. self.netvm = self.qc.add_new_vm("QubesNetVm",
  113. name=self.make_vm_name('netvm'),
  114. template=self.qc.get_default_template())
  115. self.netvm.create_on_disk(verbose=False)
  116. self.assertEquals(self.vm.netvm, self.vm.dispvm_netvm)
  117. self.vm.uses_default_dispvm_netvm = False
  118. self.vm.dispvm_netvm = None
  119. self.assertIsNone(self.vm.dispvm_netvm)
  120. self.save_and_reload_db()
  121. self.assertIsNone(self.vm.dispvm_netvm)
  122. self.vm.dispvm_netvm = self.netvm
  123. self.assertEquals(self.vm.dispvm_netvm, self.netvm)
  124. self.save_and_reload_db()
  125. self.assertEquals(self.vm.dispvm_netvm, self.netvm)
  126. self.vm.uses_default_dispvm_netvm = True
  127. self.assertEquals(self.vm.dispvm_netvm, self.vm.netvm)
  128. self.save_and_reload_db()
  129. self.assertEquals(self.vm.dispvm_netvm, self.vm.netvm)
  130. with self.assertRaises(ValueError):
  131. self.vm.dispvm_netvm = self.vm
  132. # vim: ts=4 sw=4 et