storage.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.log
  19. from qubes.storage import StoragePoolException, pool_drivers
  20. from qubes.storage.xen import XenPool
  21. from qubes.tests import QubesTestCase
  22. class TestApp(qubes.tests.TestEmitter):
  23. pass
  24. class TestVM(object):
  25. def __init__(self, app, qid, name, pool_name, template=None):
  26. super(TestVM, self).__init__()
  27. self.app = app
  28. self.qid = qid
  29. self.name = name
  30. self.pool_name = pool_name
  31. self.template = template
  32. self.hvm = False
  33. self.storage = qubes.storage.get_pool(self.pool_name,
  34. self).get_storage()
  35. self.log = qubes.log.get_vm_logger(self.name)
  36. def is_template(self):
  37. return False
  38. def is_disposablevm(self):
  39. return False
  40. @property
  41. def dir_path(self):
  42. return self.storage.vmdir
  43. class TestTemplateVM(TestVM):
  44. def is_template(self):
  45. return True
  46. class TestDisposableVM(TestVM):
  47. def is_disposablevm(self):
  48. return True
  49. class TC_00_Pool(QubesTestCase):
  50. """ This class tests the utility methods from :mod:``qubes.storage`` """
  51. def setUp(self):
  52. super(TC_00_Pool, self).setUp()
  53. def test_000_unknown_pool_driver(self):
  54. # :pylint: disable=protected-access
  55. """ Expect an exception when unknown pool is requested"""
  56. with self.assertRaises(StoragePoolException):
  57. qubes.storage._get_pool_klass('foo-bar')
  58. def test_001_all_pool_drivers(self):
  59. """ The only predefined pool driver is file """
  60. self.assertEquals(["xen"], pool_drivers())
  61. def test_002_get_pool_klass(self):
  62. """ Expect the default pool to be `XenPool` """
  63. # :pylint: disable=protected-access
  64. result = qubes.storage._get_pool_klass('default')
  65. self.assertTrue(result is XenPool)
  66. def test_003_pool_exists_default(self):
  67. """ Expect the default pool to exists """
  68. self.assertTrue(qubes.storage.pool_exists('default'))
  69. def test_004_pool_exists_random(self):
  70. """ Expect this pool to not a exist """
  71. self.assertFalse(qubes.storage.pool_exists(
  72. 'asdh312096r832598213iudhas'))
  73. def test_005_add_remove_pool(self):
  74. """ Tries to adding and removing a pool. """
  75. pool_name = 'asdjhrp89132'
  76. # make sure it's really does not exist
  77. qubes.storage.remove_pool(pool_name)
  78. qubes.storage.add_pool(pool_name, driver='xen')
  79. self.assertTrue(qubes.storage.pool_exists(pool_name))
  80. qubes.storage.remove_pool(pool_name)
  81. self.assertFalse(qubes.storage.pool_exists(pool_name))