Rename default storage driver from xen to file

- Rename XenPool   ⇒ FilePool
- Rename XenVolume ⇒ FileVolume
This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-04-30 20:42:46 +02:00
parent b2c1017488
commit 7200e6153b
No known key found for this signature in database
GPG Key ID: 96ED3C3BA19C3DEE
8 changed files with 45 additions and 46 deletions

View File

@ -87,7 +87,7 @@ defaults = {
'pool_configs': { 'pool_configs': {
'default': {'dir_path': qubes_base_dir, 'default': {'dir_path': qubes_base_dir,
'driver': 'xen', 'driver': 'file',
'name': 'default'}, 'name': 'default'},
'linux-kernel': { 'linux-kernel': {
'dir_path': os.path.join(qubes_base_dir, 'dir_path': os.path.join(qubes_base_dir,

View File

@ -36,20 +36,20 @@ from qubes.storage import Pool, StoragePoolException, Volume
BLKSIZE = 512 BLKSIZE = 512
class XenPool(Pool): class FilePool(Pool):
''' File based 'original' disk implementation ''' ''' File based 'original' disk implementation '''
driver = 'xen' driver = 'file'
def __init__(self, name=None, dir_path=None): 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" assert dir_path, "No pool dir_path specified"
self.dir_path = os.path.normpath(dir_path) self.dir_path = os.path.normpath(dir_path)
def clone(self, source, target): def clone(self, source, target):
''' Clones the volume if the `source.pool` if the source is a ''' 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' raise StoragePoolException('Volumes %s and %s use different pools'
% (source.__class__, target.__class__)) % (source.__class__, target.__class__))
@ -77,7 +77,7 @@ class XenPool(Pool):
return { return {
'name': self.name, 'name': self.name,
'dir_path': self.dir_path, 'dir_path': self.dir_path,
'driver': XenPool.driver, 'driver': FilePool.driver,
} }
def resize(self, volume, size): def resize(self, volume, size):
@ -115,7 +115,7 @@ class XenPool(Pool):
_remove_if_exists(volume.path_cow) _remove_if_exists(volume.path_cow)
def rename(self, volume, old_name, new_name): 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) old_dir = os.path.dirname(volume.path)
new_dir = os.path.join(os.path.dirname(old_dir), new_name) 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']: if volume_type in ['snapshot', 'read-only']:
origin_pool = vm.app.get_pool(volume_config['pool']) origin_pool = vm.app.get_pool(volume_config['pool'])
assert isinstance(origin_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) volume_config['target_dir'] = origin_pool.target_dir(vm.template)
name = volume_config['name'] name = volume_config['name']
volume_config['size'] = vm.template.volume_config[name]['size'] volume_config['size'] = vm.template.volume_config[name]['size']
@ -250,7 +250,7 @@ class XenPool(Pool):
return known_types[volume_type](**volume_config) return known_types[volume_type](**volume_config)
class XenVolume(Volume): class FileVolume(Volume):
''' Parent class for the xen volumes implementation which expects a ''' Parent class for the xen volumes implementation which expects a
`target_dir` param on initialization. `target_dir` param on initialization.
''' '''
@ -258,10 +258,10 @@ class XenVolume(Volume):
def __init__(self, target_dir, **kwargs): def __init__(self, target_dir, **kwargs):
self.target_dir = target_dir self.target_dir = target_dir
assert self.target_dir, "target_dir not specified" 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 ''' A mix in which expects a `size` param to be > 0 on initialization and
provides a usage property wrapper. provides a usage property wrapper.
''' '''
@ -293,7 +293,7 @@ class ReadWriteFile(SizeMixIn):
self.vid = self.path self.vid = self.path
def rename_target_dir(self, new_name, new_dir): 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 old_path = self.path
file_name = os.path.basename(self.path) file_name = os.path.basename(self.path)
new_path = os.path.join(new_dir, file_name) new_path = os.path.join(new_dir, file_name)
@ -304,7 +304,7 @@ class ReadWriteFile(SizeMixIn):
self.vid = self.path self.vid = self.path
class ReadOnlyFile(XenVolume): class ReadOnlyFile(FileVolume):
''' Represents a readonly file image based volume ''' ''' Represents a readonly file image based volume '''
usage = 0 usage = 0
@ -313,7 +313,7 @@ class ReadOnlyFile(XenVolume):
self.path = self.vid self.path = self.vid
def rename_target_dir(self, old_name, new_dir): 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. 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, Currently if a volume is in a directory named the same as the domain,
@ -351,7 +351,7 @@ class OriginFile(SizeMixIn):
raise NotImplementedError raise NotImplementedError
def rename_target_dir(self, new_dir): 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_origin = self.path_origin
old_path_cow = self.path_cow old_path_cow = self.path_cow
new_path_origin = os.path.join(new_dir, self.name + '.img') new_path_origin = os.path.join(new_dir, self.name + '.img')
@ -374,7 +374,7 @@ class OriginFile(SizeMixIn):
return result return result
class SnapshotFile(XenVolume): class SnapshotFile(FileVolume):
''' Represents a readonly snapshot of an :py:class:`OriginFile` volume ''' ''' Represents a readonly snapshot of an :py:class:`OriginFile` volume '''
script = 'block-snapshot' script = 'block-snapshot'
rw = False rw = False
@ -399,7 +399,7 @@ class VolatileFile(SizeMixIn):
self.vid = self.path self.vid = self.path
def rename_target_dir(self, new_dir): 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) _remove_if_exists(self)
file_name = os.path.basename(self.path) file_name = os.path.basename(self.path)
self.target_dir = new_dir self.target_dir = new_dir

View File

@ -948,7 +948,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
'qubes.tests.init1', 'qubes.tests.init1',
'qubes.tests.vm.init', 'qubes.tests.vm.init',
'qubes.tests.storage', 'qubes.tests.storage',
'qubes.tests.storage_xen', 'qubes.tests.storage_file',
'qubes.tests.vm.qubesvm', 'qubes.tests.vm.qubesvm',
'qubes.tests.vm.adminvm', 'qubes.tests.vm.adminvm',
'qubes.tests.init2', 'qubes.tests.init2',

View File

@ -19,7 +19,7 @@
import qubes.log import qubes.log
from qubes.exc import QubesException from qubes.exc import QubesException
from qubes.storage import pool_drivers from qubes.storage import pool_drivers
from qubes.storage.xen import XenPool from qubes.storage.file import FilePool
from qubes.tests import QubesTestCase, SystemTestsMixin from qubes.tests import QubesTestCase, SystemTestsMixin
# :pylint: disable=invalid-name # :pylint: disable=invalid-name
@ -73,14 +73,14 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase):
self.app.get_pool('foo-bar') self.app.get_pool('foo-bar')
def test_001_all_pool_drivers(self): def test_001_all_pool_drivers(self):
""" The only predefined pool driver is xen """ """ The only predefined pool driver is file """
self.assertEquals(['linux-kernel', 'xen'], pool_drivers()) self.assertEquals(['linux-kernel', 'file'], pool_drivers())
def test_002_get_pool_klass(self): 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 # :pylint: disable=protected-access
result = self.app.get_pool('default') result = self.app.get_pool('default')
self.assertIsInstance(result, XenPool) self.assertIsInstance(result, FilePool)
def test_003_pool_exists_default(self): def test_003_pool_exists_default(self):
""" Expect the default pool to exists """ """ Expect the default pool to exists """
@ -94,7 +94,9 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase):
self.app.remove_pool(pool_name) self.app.remove_pool(pool_name)
self.assertFalse(self.assertPoolExists(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.assertTrue(self.assertPoolExists(pool_name))
self.app.remove_pool(pool_name) self.app.remove_pool(pool_name)

View File

@ -23,17 +23,15 @@ import qubes.storage
import qubes.tests.storage import qubes.tests.storage
from qubes.config import defaults from qubes.config import defaults
from qubes.storage import Storage from qubes.storage import Storage
from qubes.storage.xen import (OriginFile, ReadOnlyFile, ReadWriteFile, from qubes.storage.file import (OriginFile, ReadOnlyFile, ReadWriteFile,
SnapshotFile, VolatileFile) SnapshotFile, VolatileFile)
from qubes.tests import QubesTestCase, SystemTestsMixin from qubes.tests import QubesTestCase, SystemTestsMixin
from qubes.tests.storage import TestVM from qubes.tests.storage import TestVM
# :pylint: disable=invalid-name # :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. """ """ This class tests some properties of the 'default' pool. """
def test000_default_pool_dir(self): def test000_default_pool_dir(self):
@ -61,21 +59,21 @@ class TC_00_XenPool(SystemTestsMixin, QubesTestCase):
label='red') label='red')
class TC_01_XenVolumes(SystemTestsMixin, QubesTestCase): class TC_01_FileVolumes(SystemTestsMixin, QubesTestCase):
POOL_DIR = '/var/lib/qubes/test-pool' POOL_DIR = '/var/lib/qubes/test-pool'
POOL_NAME = '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): def setUp(self):
""" Add a test file based storage pool """ """ Add a test file based storage pool """
super(TC_01_XenVolumes, self).setUp() super(TC_01_FileVolumes, self).setUp()
self.init_default_template() self.init_default_template()
self.app.add_pool(**self.POOL_CONF) self.app.add_pool(**self.POOL_CONF)
def tearDown(self): def tearDown(self):
""" Remove the file based storage pool after testing """ """ Remove the file based storage pool after testing """
self.app.remove_pool("test-pool") 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) shutil.rmtree(self.POOL_DIR, ignore_errors=True)
def test_000_origin_volume(self): def test_000_origin_volume(self):
@ -201,9 +199,8 @@ class TC_01_XenVolumes(SystemTestsMixin, QubesTestCase):
@qubes.tests.skipUnlessDom0 @qubes.tests.skipUnlessDom0
class TC_03_XenPool(SystemTestsMixin, QubesTestCase): class TC_03_FilePool(SystemTestsMixin, QubesTestCase):
""" Test the paths for the default file based pool (``FilePool``).
""" Test the paths for the default Xen file based storage (``XenStorage``).
""" """
POOL_DIR = '/var/lib/qubes/test-pool' 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' TEMPLATES_DIR = '/var/lib/qubes/test-pool/vm-templates'
SERVICE_DIR = '/var/lib/qubes/test-pool/servicevms' SERVICE_DIR = '/var/lib/qubes/test-pool/servicevms'
POOL_NAME = 'test-pool' 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): def setUp(self):
""" Add a test file based storage pool """ """ Add a test file based storage pool """
super(TC_03_XenPool, self).setUp() super(TC_03_FilePool, self).setUp()
self.init_default_template() self.init_default_template()
self.app.add_pool(**self.POOL_CONFIG) self.app.add_pool(**self.POOL_CONFIG)
def tearDown(self): def tearDown(self):
""" Remove the file based storage pool after testing """ """ Remove the file based storage pool after testing """
self.app.remove_pool("test-pool") 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) shutil.rmtree(self.POOL_DIR, ignore_errors=True)
def test_001_pool_exists(self): def test_001_pool_exists(self):
@ -239,7 +236,7 @@ class TC_03_XenPool(SystemTestsMixin, QubesTestCase):
self.assertFalse(os.path.exists(pool_dir)) 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(pool_dir))
self.assertTrue(os.path.exists(appvms_dir)) self.assertTrue(os.path.exists(appvms_dir))

View File

@ -232,7 +232,7 @@ fi
%dir %{python_sitelib}/qubes/storage %dir %{python_sitelib}/qubes/storage
%{python_sitelib}/qubes/storage/__init__.py* %{python_sitelib}/qubes/storage/__init__.py*
%{python_sitelib}/qubes/storage/xen.py* %{python_sitelib}/qubes/storage/file.py*
%{python_sitelib}/qubes/storage/kernels.py* %{python_sitelib}/qubes/storage/kernels.py*
%dir %{python_sitelib}/qubes/tools %dir %{python_sitelib}/qubes/tools
@ -267,7 +267,7 @@ fi
%{python_sitelib}/qubes/tests/init1.py* %{python_sitelib}/qubes/tests/init1.py*
%{python_sitelib}/qubes/tests/init2.py* %{python_sitelib}/qubes/tests/init2.py*
%{python_sitelib}/qubes/tests/storage.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 %dir %{python_sitelib}/qubes/tests/vm
%{python_sitelib}/qubes/tests/vm/__init__.py* %{python_sitelib}/qubes/tests/vm/__init__.py*

View File

@ -44,7 +44,7 @@ if __name__ == '__main__':
'pci = qubes.devices:PCIDevice', 'pci = qubes.devices:PCIDevice',
], ],
'qubes.storage': [ 'qubes.storage': [
'xen = qubes.storage.xen:XenPool', 'file = qubes.storage.file:FilePool',
'linux-kernel = qubes.storage.kernels:LinuxKernel', 'linux-kernel = qubes.storage.kernels:LinuxKernel',
] ]
}) })

View File

@ -29,8 +29,8 @@ endif
cp run.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp run.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
cp storage.py $(DESTDIR)$(PYTHON_TESTSPATH) cp storage.py $(DESTDIR)$(PYTHON_TESTSPATH)
cp storage.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp storage.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
cp storage_xen.py $(DESTDIR)$(PYTHON_TESTSPATH) cp storage_file.py $(DESTDIR)$(PYTHON_TESTSPATH)
cp storage_xen.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp storage_file.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
cp hardware.py $(DESTDIR)$(PYTHON_TESTSPATH) cp hardware.py $(DESTDIR)$(PYTHON_TESTSPATH)
cp hardware.py[co] $(DESTDIR)$(PYTHON_TESTSPATH) cp hardware.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
cp extra.py $(DESTDIR)$(PYTHON_TESTSPATH) cp extra.py $(DESTDIR)$(PYTHON_TESTSPATH)