storage.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # The Qubes OS Project, https://www.qubes-os.org/
  2. #
  3. # Copyright (C) 2015 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. import qubes.storage
  19. from qubes.qubes import defaults
  20. from qubes.storage.xen import XenPool, XenStorage
  21. from qubes.tests import QubesTestCase, SystemTestsMixin
  22. class TC_00_Storage(SystemTestsMixin, QubesTestCase):
  23. """ This class tests the utility methods from :mod:``qubes.storage`` """
  24. def test_000_dump(self):
  25. """ Dumps storage instance to a storage string """
  26. vmname = self.make_vm_name('appvm')
  27. template = self.qc.get_default_template()
  28. vm = self.qc.add_new_vm('QubesAppVm', name=vmname,
  29. pool_name='default', template=template)
  30. storage = vm.storage
  31. result = qubes.storage.dump(storage)
  32. expected = 'qubes.storage.xen.XenStorage'
  33. self.assertEquals(result, expected)
  34. def test_001_load(self):
  35. """ Loads storage driver from a storage string """
  36. result = qubes.storage.load('qubes.storage.xen.XenStorage')
  37. self.assertTrue(result is XenStorage)
  38. def test_002_default_pool_drivers(self):
  39. """ The only predifined pool driver is xen """
  40. result = defaults['pool_drivers'].keys()
  41. expected = ["xen"]
  42. self.assertEquals(result, expected)
  43. def test_003_get_pool_klass(self):
  44. """ Expect the default pool to be `XenPool` """
  45. result = qubes.storage._get_pool_klass('default')
  46. self.assertTrue(result is XenPool)
  47. def test_004_pool_exists_default(self):
  48. """ Expect the default pool to exists """
  49. self.assertTrue(qubes.storage.pool_exists('default'))
  50. def test_005_pool_exists_random(self):
  51. """ Expect this pool to not a exist """
  52. self.assertFalse(
  53. qubes.storage.pool_exists('asdh312096r832598213iudhas'))
  54. def test_006_add_remove_pool(self):
  55. """ Tries to adding and removing a pool. """
  56. pool_name = 'asdjhrp89132'
  57. # make sure it's really does not exist
  58. qubes.storage.remove_pool(pool_name)
  59. qubes.storage.add_pool(pool_name, driver='xen')
  60. self.assertTrue(qubes.storage.pool_exists(pool_name))
  61. qubes.storage.remove_pool(pool_name)
  62. self.assertFalse(qubes.storage.pool_exists(pool_name))