Skip to content

Commit

Permalink
vm/dispvm: place all volumes in the same pool as DispVM's template
Browse files Browse the repository at this point in the history
Make all volume's pool controlled by DisposableVM Template. This
specifically makes DispVM's volatile volume to be placed directly in the
same pool as its template.

Fixes QubesOS/qubes-issues#5933

(cherry picked from commit 8b76045)
  • Loading branch information
marmarek committed Oct 22, 2020
1 parent 12c5459 commit cbea985
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions qubes/tests/vm/dispvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,28 @@ def test_011_create_direct_reject(self):
self.app.add_new_vm(qubes.vm.dispvm.DispVM,
name='test-dispvm', template=self.appvm)
self.assertFalse(mock_domains.get_new_unused_dispid.called)

@mock.patch('os.symlink')
@mock.patch('os.makedirs')
def test_020_copy_storage_pool(self, mock_makedirs, mock_symlink):
self.app.pools['alternative'] = qubes.tests.vm.appvm.TestPool(name='alternative')
self.appvm.template_for_dispvms = True
self.loop.run_until_complete(self.template.create_on_disk())
self.loop.run_until_complete(self.appvm.create_on_disk(pool='alternative'))
orig_getitem = self.app.domains.__getitem__
with mock.patch.object(self.app, 'domains', wraps=self.app.domains) \
as mock_domains:
mock_domains.configure_mock(**{
'get_new_unused_dispid': mock.Mock(return_value=42),
'__getitem__.side_effect': orig_getitem
})
dispvm = self.app.add_new_vm(qubes.vm.dispvm.DispVM,
name='test-dispvm', template=self.appvm)
self.loop.run_until_complete(dispvm.create_on_disk())
self.assertEqual(dispvm.template, self.appvm)
self.assertEqual(dispvm.volumes['private'].pool,
self.appvm.volumes['private'].pool)
self.assertEqual(dispvm.volumes['root'].pool,
self.appvm.volumes['root'].pool)
self.assertEqual(dispvm.volumes['volatile'].pool,
self.appvm.volumes['volatile'].pool)
6 changes: 6 additions & 0 deletions qubes/vm/dispvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def __init__(self, app, xml, *args, **kwargs):
self.volume_config[name] = config.copy()
if 'vid' in self.volume_config[name]:
del self.volume_config[name]['vid']
# copy pool setting from base AppVM; root and private would be
# in the same pool anyway (because of snap_on_start),
# but not volatile, which could be surprising
elif 'pool' not in self.volume_config[name] \
and 'pool' in config:
self.volume_config[name]['pool'] = config['pool']

super(DispVM, self).__init__(app, xml, *args, **kwargs)

Expand Down

0 comments on commit cbea985

Please sign in to comment.