admin: fix handling default template in admin.vm.Create.* methods
This commit is contained in:
parent
fcfb2e004a
commit
0160d6e2f0
@ -584,8 +584,9 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
|
||||
# if argument is given, it needs to be a valid template, and only
|
||||
# when given VM class do need a template
|
||||
if hasattr(vm_class, 'template'):
|
||||
assert self.arg in self.app.domains
|
||||
kwargs['template'] = self.app.domains[self.arg]
|
||||
if self.arg:
|
||||
assert self.arg in self.app.domains
|
||||
kwargs['template'] = self.app.domains[self.arg]
|
||||
else:
|
||||
assert not self.arg
|
||||
|
||||
|
@ -1052,19 +1052,18 @@ class TC_00_VMs(AdminAPITestCase):
|
||||
self.assertTrue(self.app.save.called)
|
||||
|
||||
@unittest.mock.patch('qubes.storage.Storage.create')
|
||||
def test_333_vm_create_app_missing_template(self, storage_mock):
|
||||
def test_333_vm_create_app_default_template(self, storage_mock):
|
||||
storage_mock.side_effect = self.dummy_coro
|
||||
with self.assertRaises(AssertionError):
|
||||
self.call_mgmt_func(b'admin.vm.Create.AppVM',
|
||||
b'dom0', b'', b'name=test-vm2 label=red')
|
||||
self.call_mgmt_func(b'admin.vm.Create.AppVM',
|
||||
b'dom0', b'', b'name=test-vm2 label=red')
|
||||
|
||||
self.assertNotIn('test-vm2', self.app.domains)
|
||||
self.assertEqual(storage_mock.mock_calls, [])
|
||||
self.assertFalse(os.path.exists(os.path.join(
|
||||
self.test_base_dir, 'appvms', 'test-vm2')))
|
||||
self.assertEqual(storage_mock.mock_calls,
|
||||
[unittest.mock.call(self.app.domains['test-vm2']).create()])
|
||||
|
||||
self.assertNotIn('test-vm2', self.app.domains)
|
||||
self.assertFalse(self.app.save.called)
|
||||
self.assertIn('test-vm2', self.app.domains)
|
||||
self.assertEqual(self.app.domains['test-vm2'].template,
|
||||
self.app.default_template)
|
||||
self.assertTrue(self.app.save.called)
|
||||
|
||||
@unittest.mock.patch('qubes.storage.Storage.create')
|
||||
def test_334_vm_create_invalid_name(self, storage_mock):
|
||||
|
Loading…
Reference in New Issue
Block a user