storage.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.exc import QubesException
  20. from qubes.storage import pool_drivers
  21. from qubes.storage.file import FilePool
  22. from qubes.tests import QubesTestCase, SystemTestsMixin
  23. # :pylint: disable=invalid-name
  24. class TestApp(qubes.tests.TestEmitter):
  25. pass
  26. class TestVM(object):
  27. def __init__(self, test, template=None):
  28. self.app = test.app
  29. self.name = test.make_vm_name('appvm')
  30. self.log = qubes.log.get_vm_logger(self.name)
  31. if template:
  32. self.template = template
  33. def is_template(self):
  34. # :pylint: disable=no-self-use
  35. return False
  36. def is_disposablevm(self):
  37. # :pylint: disable=no-self-use
  38. return False
  39. class TestTemplateVM(TestVM):
  40. dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
  41. def is_template(self):
  42. return True
  43. class TestDisposableVM(TestVM):
  44. def is_disposablevm(self):
  45. return True
  46. class TC_00_Pool(SystemTestsMixin, QubesTestCase):
  47. """ This class tests the utility methods from :mod:``qubes.storage`` """
  48. def setUp(self):
  49. super(TC_00_Pool, self).setUp()
  50. self.init_default_template()
  51. def test_000_unknown_pool_driver(self):
  52. # :pylint: disable=protected-access
  53. """ Expect an exception when unknown pool is requested"""
  54. with self.assertRaises(QubesException):
  55. self.app.get_pool('foo-bar')
  56. def test_001_all_pool_drivers(self):
  57. """ The only predefined pool driver is file """
  58. self.assertEquals(['linux-kernel', 'file'], pool_drivers())
  59. def test_002_get_pool_klass(self):
  60. """ Expect the default pool to be `FilePool` """
  61. # :pylint: disable=protected-access
  62. result = self.app.get_pool('default')
  63. self.assertIsInstance(result, FilePool)
  64. def test_003_pool_exists_default(self):
  65. """ Expect the default pool to exists """
  66. self.assertPoolExists('default')
  67. def test_004_add_remove_pool(self):
  68. """ Tries to adding and removing a pool. """
  69. pool_name = 'asdjhrp89132'
  70. # make sure it's really does not exist
  71. self.app.remove_pool(pool_name)
  72. self.assertFalse(self.assertPoolExists(pool_name))
  73. self.app.add_pool(name=pool_name,
  74. driver='file',
  75. dir_path='/tmp/asdjhrp89132')
  76. self.assertTrue(self.assertPoolExists(pool_name))
  77. self.app.remove_pool(pool_name)
  78. self.assertFalse(self.assertPoolExists(pool_name))
  79. def assertPoolExists(self, pool):
  80. """ Check if specified pool exists """
  81. return pool in self.app.pools.keys()