From 7200e6153bafc6cebd5ab748d9badc3515718418 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Sat, 30 Apr 2016 20:42:46 +0200 Subject: [PATCH] Rename default storage driver from xen to file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename XenPool ⇒ FilePool - Rename XenVolume ⇒ FileVolume --- qubes/config.py | 2 +- qubes/storage/{xen.py => file.py} | 34 +++++++++---------- qubes/tests/__init__.py | 2 +- qubes/tests/storage.py | 14 ++++---- .../tests/{storage_xen.py => storage_file.py} | 29 +++++++--------- rpm_spec/core-dom0.spec | 4 +-- setup.py | 2 +- tests/Makefile | 4 +-- 8 files changed, 45 insertions(+), 46 deletions(-) rename qubes/storage/{xen.py => file.py} (95%) rename qubes/tests/{storage_xen.py => storage_file.py} (94%) diff --git a/qubes/config.py b/qubes/config.py index 80a2981b..f1c11394 100644 --- a/qubes/config.py +++ b/qubes/config.py @@ -87,7 +87,7 @@ defaults = { 'pool_configs': { 'default': {'dir_path': qubes_base_dir, - 'driver': 'xen', + 'driver': 'file', 'name': 'default'}, 'linux-kernel': { 'dir_path': os.path.join(qubes_base_dir, diff --git a/qubes/storage/xen.py b/qubes/storage/file.py similarity index 95% rename from qubes/storage/xen.py rename to qubes/storage/file.py index 2071e45e..2891cd87 100644 --- a/qubes/storage/xen.py +++ b/qubes/storage/file.py @@ -36,20 +36,20 @@ from qubes.storage import Pool, StoragePoolException, Volume BLKSIZE = 512 -class XenPool(Pool): +class FilePool(Pool): ''' File based 'original' disk implementation ''' - driver = 'xen' + driver = 'file' def __init__(self, name=None, dir_path=None): - super(XenPool, self).__init__(name=name) + super(FilePool, self).__init__(name=name) assert dir_path, "No pool dir_path specified" self.dir_path = os.path.normpath(dir_path) def clone(self, source, target): ''' Clones the volume if the `source.pool` if the source is a - :py:class:`XenVolume`. + :py:class:`FileVolume`. ''' - if issubclass(XenVolume, source.__class__): + if issubclass(FileVolume, source.__class__): raise StoragePoolException('Volumes %s and %s use different pools' % (source.__class__, target.__class__)) @@ -77,7 +77,7 @@ class XenPool(Pool): return { 'name': self.name, 'dir_path': self.dir_path, - 'driver': XenPool.driver, + 'driver': FilePool.driver, } def resize(self, volume, size): @@ -115,7 +115,7 @@ class XenPool(Pool): _remove_if_exists(volume.path_cow) def rename(self, volume, old_name, new_name): - assert issubclass(volume.__class__, XenVolume) + assert issubclass(volume.__class__, FileVolume) old_dir = os.path.dirname(volume.path) new_dir = os.path.join(os.path.dirname(old_dir), new_name) @@ -240,7 +240,7 @@ class XenPool(Pool): if volume_type in ['snapshot', 'read-only']: origin_pool = vm.app.get_pool(volume_config['pool']) assert isinstance(origin_pool, - XenPool), 'Origin volume not a xen volume' + FilePool), 'Origin volume not a xen volume' volume_config['target_dir'] = origin_pool.target_dir(vm.template) name = volume_config['name'] volume_config['size'] = vm.template.volume_config[name]['size'] @@ -250,7 +250,7 @@ class XenPool(Pool): return known_types[volume_type](**volume_config) -class XenVolume(Volume): +class FileVolume(Volume): ''' Parent class for the xen volumes implementation which expects a `target_dir` param on initialization. ''' @@ -258,10 +258,10 @@ class XenVolume(Volume): def __init__(self, target_dir, **kwargs): self.target_dir = target_dir assert self.target_dir, "target_dir not specified" - super(XenVolume, self).__init__(**kwargs) + super(FileVolume, self).__init__(**kwargs) -class SizeMixIn(XenVolume): +class SizeMixIn(FileVolume): ''' A mix in which expects a `size` param to be > 0 on initialization and provides a usage property wrapper. ''' @@ -293,7 +293,7 @@ class ReadWriteFile(SizeMixIn): self.vid = self.path def rename_target_dir(self, new_name, new_dir): - ''' Called by :py:class:`XenPool` when a domain changes it's name ''' + ''' Called by :py:class:`FilePool` when a domain changes it's name ''' old_path = self.path file_name = os.path.basename(self.path) new_path = os.path.join(new_dir, file_name) @@ -304,7 +304,7 @@ class ReadWriteFile(SizeMixIn): self.vid = self.path -class ReadOnlyFile(XenVolume): +class ReadOnlyFile(FileVolume): ''' Represents a readonly file image based volume ''' usage = 0 @@ -313,7 +313,7 @@ class ReadOnlyFile(XenVolume): self.path = self.vid def rename_target_dir(self, old_name, new_dir): - """ Called by :py:class:`XenPool` when a domain changes it's name. + """ Called by :py:class:`FilePool` when a domain changes it's name. Only copies the volume if it belongs to the domain being renamed. Currently if a volume is in a directory named the same as the domain, @@ -351,7 +351,7 @@ class OriginFile(SizeMixIn): raise NotImplementedError def rename_target_dir(self, new_dir): - ''' Called by :py:class:`XenPool` when a domain changes it's name ''' + ''' Called by :py:class:`FilePool` when a domain changes it's name ''' old_path_origin = self.path_origin old_path_cow = self.path_cow new_path_origin = os.path.join(new_dir, self.name + '.img') @@ -374,7 +374,7 @@ class OriginFile(SizeMixIn): return result -class SnapshotFile(XenVolume): +class SnapshotFile(FileVolume): ''' Represents a readonly snapshot of an :py:class:`OriginFile` volume ''' script = 'block-snapshot' rw = False @@ -399,7 +399,7 @@ class VolatileFile(SizeMixIn): self.vid = self.path def rename_target_dir(self, new_dir): - ''' Called by :py:class:`XenPool` when a domain changes it's name ''' + ''' Called by :py:class:`FilePool` when a domain changes it's name ''' _remove_if_exists(self) file_name = os.path.basename(self.path) self.target_dir = new_dir diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 538a02bb..20ae5bbd 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -948,7 +948,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument 'qubes.tests.init1', 'qubes.tests.vm.init', 'qubes.tests.storage', - 'qubes.tests.storage_xen', + 'qubes.tests.storage_file', 'qubes.tests.vm.qubesvm', 'qubes.tests.vm.adminvm', 'qubes.tests.init2', diff --git a/qubes/tests/storage.py b/qubes/tests/storage.py index 5fa82222..9d289712 100644 --- a/qubes/tests/storage.py +++ b/qubes/tests/storage.py @@ -19,7 +19,7 @@ import qubes.log from qubes.exc import QubesException from qubes.storage import pool_drivers -from qubes.storage.xen import XenPool +from qubes.storage.file import FilePool from qubes.tests import QubesTestCase, SystemTestsMixin # :pylint: disable=invalid-name @@ -73,14 +73,14 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase): self.app.get_pool('foo-bar') def test_001_all_pool_drivers(self): - """ The only predefined pool driver is xen """ - self.assertEquals(['linux-kernel', 'xen'], pool_drivers()) + """ The only predefined pool driver is file """ + self.assertEquals(['linux-kernel', 'file'], pool_drivers()) def test_002_get_pool_klass(self): - """ Expect the default pool to be `XenPool` """ + """ Expect the default pool to be `FilePool` """ # :pylint: disable=protected-access result = self.app.get_pool('default') - self.assertIsInstance(result, XenPool) + self.assertIsInstance(result, FilePool) def test_003_pool_exists_default(self): """ Expect the default pool to exists """ @@ -94,7 +94,9 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase): self.app.remove_pool(pool_name) self.assertFalse(self.assertPoolExists(pool_name)) - self.app.add_pool(name=pool_name, driver='xen', dir_path='/tmp/asdjhrp89132') + self.app.add_pool(name=pool_name, + driver='file', + dir_path='/tmp/asdjhrp89132') self.assertTrue(self.assertPoolExists(pool_name)) self.app.remove_pool(pool_name) diff --git a/qubes/tests/storage_xen.py b/qubes/tests/storage_file.py similarity index 94% rename from qubes/tests/storage_xen.py rename to qubes/tests/storage_file.py index 0dd9557c..6adcc0c2 100644 --- a/qubes/tests/storage_xen.py +++ b/qubes/tests/storage_file.py @@ -23,17 +23,15 @@ import qubes.storage import qubes.tests.storage from qubes.config import defaults from qubes.storage import Storage -from qubes.storage.xen import (OriginFile, ReadOnlyFile, ReadWriteFile, - SnapshotFile, VolatileFile) +from qubes.storage.file import (OriginFile, ReadOnlyFile, ReadWriteFile, + SnapshotFile, VolatileFile) from qubes.tests import QubesTestCase, SystemTestsMixin from qubes.tests.storage import TestVM - # :pylint: disable=invalid-name -class TC_00_XenPool(SystemTestsMixin, QubesTestCase): - +class TC_00_FilePool(SystemTestsMixin, QubesTestCase): """ This class tests some properties of the 'default' pool. """ def test000_default_pool_dir(self): @@ -61,21 +59,21 @@ class TC_00_XenPool(SystemTestsMixin, QubesTestCase): label='red') -class TC_01_XenVolumes(SystemTestsMixin, QubesTestCase): +class TC_01_FileVolumes(SystemTestsMixin, QubesTestCase): POOL_DIR = '/var/lib/qubes/test-pool' POOL_NAME = 'test-pool' - POOL_CONF = {'driver': 'xen', 'dir_path': POOL_DIR, 'name': POOL_NAME} + POOL_CONF = {'driver': 'file', 'dir_path': POOL_DIR, 'name': POOL_NAME} def setUp(self): """ Add a test file based storage pool """ - super(TC_01_XenVolumes, self).setUp() + super(TC_01_FileVolumes, self).setUp() self.init_default_template() self.app.add_pool(**self.POOL_CONF) def tearDown(self): """ Remove the file based storage pool after testing """ self.app.remove_pool("test-pool") - super(TC_01_XenVolumes, self).tearDown() + super(TC_01_FileVolumes, self).tearDown() shutil.rmtree(self.POOL_DIR, ignore_errors=True) def test_000_origin_volume(self): @@ -201,9 +199,8 @@ class TC_01_XenVolumes(SystemTestsMixin, QubesTestCase): @qubes.tests.skipUnlessDom0 -class TC_03_XenPool(SystemTestsMixin, QubesTestCase): - - """ Test the paths for the default Xen file based storage (``XenStorage``). +class TC_03_FilePool(SystemTestsMixin, QubesTestCase): + """ Test the paths for the default file based pool (``FilePool``). """ POOL_DIR = '/var/lib/qubes/test-pool' @@ -211,18 +208,18 @@ class TC_03_XenPool(SystemTestsMixin, QubesTestCase): TEMPLATES_DIR = '/var/lib/qubes/test-pool/vm-templates' SERVICE_DIR = '/var/lib/qubes/test-pool/servicevms' POOL_NAME = 'test-pool' - POOL_CONFIG = {'driver': 'xen', 'dir_path': POOL_DIR, 'name': POOL_NAME} + POOL_CONFIG = {'driver': 'file', 'dir_path': POOL_DIR, 'name': POOL_NAME} def setUp(self): """ Add a test file based storage pool """ - super(TC_03_XenPool, self).setUp() + super(TC_03_FilePool, self).setUp() self.init_default_template() self.app.add_pool(**self.POOL_CONFIG) def tearDown(self): """ Remove the file based storage pool after testing """ self.app.remove_pool("test-pool") - super(TC_03_XenPool, self).tearDown() + super(TC_03_FilePool, self).tearDown() shutil.rmtree(self.POOL_DIR, ignore_errors=True) def test_001_pool_exists(self): @@ -239,7 +236,7 @@ class TC_03_XenPool(SystemTestsMixin, QubesTestCase): self.assertFalse(os.path.exists(pool_dir)) - self.app.add_pool(name=pool_name, dir_path=pool_dir, driver='xen') + self.app.add_pool(name=pool_name, dir_path=pool_dir, driver='file') self.assertTrue(os.path.exists(pool_dir)) self.assertTrue(os.path.exists(appvms_dir)) diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 7f0b7b48..c48c8287 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -232,7 +232,7 @@ fi %dir %{python_sitelib}/qubes/storage %{python_sitelib}/qubes/storage/__init__.py* -%{python_sitelib}/qubes/storage/xen.py* +%{python_sitelib}/qubes/storage/file.py* %{python_sitelib}/qubes/storage/kernels.py* %dir %{python_sitelib}/qubes/tools @@ -267,7 +267,7 @@ fi %{python_sitelib}/qubes/tests/init1.py* %{python_sitelib}/qubes/tests/init2.py* %{python_sitelib}/qubes/tests/storage.py* -%{python_sitelib}/qubes/tests/storage_xen.py* +%{python_sitelib}/qubes/tests/storage_file.py* %dir %{python_sitelib}/qubes/tests/vm %{python_sitelib}/qubes/tests/vm/__init__.py* diff --git a/setup.py b/setup.py index ad3a0f90..67226e80 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ if __name__ == '__main__': 'pci = qubes.devices:PCIDevice', ], 'qubes.storage': [ - 'xen = qubes.storage.xen:XenPool', + 'file = qubes.storage.file:FilePool', 'linux-kernel = qubes.storage.kernels:LinuxKernel', ] }) diff --git a/tests/Makefile b/tests/Makefile index 993c741a..2741bb1b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -29,8 +29,8 @@ endif cp run.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp storage.py $(DESTDIR)$(PYTHON_TESTSPATH) cp storage.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) - cp storage_xen.py $(DESTDIR)$(PYTHON_TESTSPATH) - cp storage_xen.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) + cp storage_file.py $(DESTDIR)$(PYTHON_TESTSPATH) + cp storage_file.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp hardware.py $(DESTDIR)$(PYTHON_TESTSPATH) cp hardware.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp extra.py $(DESTDIR)$(PYTHON_TESTSPATH)