app: do not create 'default' storage pool

Since we have app.default_pool* properties, create appropriately named
pool and let those properties choose the right pool. This also means we
don't need to specify pool name in default volume config anymore

QubesOS/qubes-issues#2256
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-25 05:23:17 +02:00
parent 73a78ca0db
commit 3a21e1f1b3
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
10 changed files with 27 additions and 33 deletions

View File

@ -577,7 +577,7 @@ def _default_pool(app):
for pool in app.pools.values():
if pool.config.get('driver', None) != 'file':
continue
if pool.config['dir_path'] == '/var/lib/qubes':
if pool.config['dir_path'] == qubes.config.qubes_base_dir:
return pool
raise AttributeError('Cannot determine default storage pool')
@ -966,11 +966,8 @@ class Qubes(qubes.PropertyHolder):
# check if the default LVM Thin pool qubes_dom0/pool00 exists
if os.path.exists('/dev/mapper/qubes_dom0-pool00-tpool'):
self.add_pool(volume_group='qubes_dom0', thin_pool='pool00',
name='default', driver='lvm_thin')
else:
self.pools['default'] = self._get_pool(
dir_path=qubes.config.qubes_base_dir,
name='default', driver='file')
name='lvm', driver='lvm_thin')
# pool based on /var/lib/qubes will be created here:
for name, config in qubes.config.defaults['pool_configs'].items():
self.pools[name] = self._get_pool(**config)

View File

@ -373,15 +373,15 @@ class Storage(object):
def init_volume(self, name, volume_config):
''' Initialize Volume instance attached to this domain '''
assert 'pool' in volume_config, "Pool missing in volume_config " + str(
volume_config)
if 'name' not in volume_config:
volume_config['name'] = name
# if pool still unknown, load default
if 'pool' not in volume_config:
pool = getattr(self.vm.app, 'default_pool_' + name)
else:
pool = self.vm.app.get_pool(volume_config['pool'])
volume_config['pool'] = \
getattr(self.vm.app, 'default_pool_' + name)
pool = self.vm.app.get_pool(volume_config['pool'])
if 'internal' in volume_config:
# migrate old config
del volume_config['internal']

View File

@ -49,8 +49,12 @@ class AdminAPITestCase(qubes.tests.QubesTestCase):
{'qubes_base_dir': self.test_base_dir})
self.base_dir_patch2 = unittest.mock.patch(
'qubes.config.qubes_base_dir', self.test_base_dir)
self.base_dir_patch3 = unittest.mock.patch.dict(
qubes.config.defaults['pool_configs']['varlibqubes'],
{'dir_path': self.test_base_dir})
self.base_dir_patch.start()
self.base_dir_patch2.start()
self.base_dir_patch3.start()
app = qubes.Qubes('/tmp/qubes-test.xml', load=False)
app.vmm = unittest.mock.Mock(spec=qubes.app.VMMConnection)
app.load_initial_values()
@ -62,6 +66,7 @@ class AdminAPITestCase(qubes.tests.QubesTestCase):
with qubes.tests.substitute_entry_points('qubes.storage',
'qubes.tests.storage'):
app.add_pool('test', driver='test')
app.default_pool = 'varlibqubes'
app.save = unittest.mock.Mock()
self.vm = app.add_new_vm('AppVM', label='red', name='test-vm1',
template='test-template')
@ -78,6 +83,7 @@ class AdminAPITestCase(qubes.tests.QubesTestCase):
self.app.domains[0].fire_event = self.emitter.fire_event
def tearDown(self):
self.base_dir_patch3.stop()
self.base_dir_patch2.stop()
self.base_dir_patch.stop()
if os.path.exists(self.test_base_dir):
@ -1155,7 +1161,8 @@ class TC_00_VMs(AdminAPITestCase):
self.assertEqual(vm.template, self.app.domains['test-template'])
# setting pool= affect only volumes actually created for this VM,
# not used from a template or so
self.assertEqual(vm.volume_config['root']['pool'], 'default')
self.assertEqual(vm.volume_config['root']['pool'],
self.template.volumes['root'].pool)
self.assertEqual(vm.volume_config['private']['pool'], 'test')
self.assertEqual(vm.volume_config['volatile']['pool'], 'test')
self.assertEqual(vm.volume_config['kernel']['pool'], 'linux-kernel')
@ -1177,9 +1184,11 @@ class TC_00_VMs(AdminAPITestCase):
vm = self.app.domains['test-vm2']
self.assertEqual(vm.label, self.app.get_label('red'))
self.assertEqual(vm.template, self.app.domains['test-template'])
self.assertEqual(vm.volume_config['root']['pool'], 'default')
self.assertEqual(vm.volume_config['root']['pool'],
self.template.volumes['root'].pool)
self.assertEqual(vm.volume_config['private']['pool'], 'test')
self.assertEqual(vm.volume_config['volatile']['pool'], 'default')
self.assertEqual(vm.volume_config['volatile']['pool'],
self.app.default_pool_volatile)
self.assertEqual(vm.volume_config['kernel']['pool'], 'linux-kernel')
self.assertEqual(storage_mock.mock_calls,
[unittest.mock.call(self.app.domains['test-vm2']).create()])

View File

@ -95,12 +95,12 @@ class TC_00_Pool(SystemTestCase):
def test_002_get_pool_klass(self):
""" Expect the default pool to be `FilePool` """
# :pylint: disable=protected-access
result = self.app.get_pool('default')
result = self.app.get_pool('varlibqubes')
self.assertIsInstance(result, FilePool)
def test_003_pool_exists_default(self):
""" Expect the default pool to exists """
self.assertPoolExists('default')
self.assertPoolExists('varlibqubes')
def test_004_add_remove_pool(self):
""" Tries to adding and removing a pool. """

View File

@ -80,7 +80,7 @@ class TC_00_FilePool(qubes.tests.QubesTestCase):
.. sealso::
Data :data:``qubes.qubes.defaults['pool_config']``.
"""
result = self.app.get_pool("default").dir_path
result = self.app.get_pool("varlibqubes").dir_path
expected = '/var/lib/qubes'
self.assertEqual(result, expected)

View File

@ -60,6 +60,10 @@ class TestApp(qubes.tests.TestEmitter):
self.vmm = TestVMM()
self.host = TestHost()
self.pools = {}
self.default_pool_volatile = 'default'
self.default_pool_root = 'default'
self.default_pool_private = 'default'
self.default_pool_kernel = 'linux-kernel'
self.domains = {}
#: jinja2 environment for libvirt XML templates
self.env = jinja2.Environment(

View File

@ -44,7 +44,6 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
default_volume_config = {
'root': {
'name': 'root',
'pool': 'default',
'snap_on_start': True,
'save_on_stop': False,
'rw': False,
@ -52,7 +51,6 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
},
'private': {
'name': 'private',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': True,
'rw': True,
@ -60,7 +58,6 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
},
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'size': defaults['root_img_size'],
@ -68,7 +65,6 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,

View File

@ -43,7 +43,6 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
self.volume_config = {
'root': {
'name': 'root',
'pool': 'default',
'snap_on_start': True,
'save_on_stop': False,
'rw': False,
@ -51,7 +50,6 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
},
'private': {
'name': 'private',
'pool': 'default',
'snap_on_start': True,
'save_on_stop': False,
'rw': True,
@ -59,7 +57,6 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
},
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'rw': True,
@ -68,7 +65,6 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,

View File

@ -30,7 +30,6 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
self.volume_config = {
'root': {
'name': 'root',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': True,
'rw': True,
@ -39,7 +38,6 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
},
'private': {
'name': 'private',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': True,
'rw': True,
@ -48,7 +46,6 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
},
'volatile': {
'name': 'volatile',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': False,
'rw': True,
@ -56,7 +53,6 @@ class StandaloneVM(qubes.vm.qubesvm.QubesVM):
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False,

View File

@ -65,7 +65,6 @@ class TemplateVM(QubesVM):
self.volume_config = {
'root': {
'name': 'root',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': True,
'rw': True,
@ -74,7 +73,6 @@ class TemplateVM(QubesVM):
},
'private': {
'name': 'private',
'pool': 'default',
'snap_on_start': False,
'save_on_stop': True,
'rw': True,
@ -84,7 +82,6 @@ class TemplateVM(QubesVM):
},
'volatile': {
'name': 'volatile',
'pool': 'default',
'size': defaults['root_img_size'],
'snap_on_start': False,
'save_on_stop': False,
@ -92,7 +89,6 @@ class TemplateVM(QubesVM):
},
'kernel': {
'name': 'kernel',
'pool': 'linux-kernel',
'snap_on_start': False,
'save_on_stop': False,
'rw': False