admin: fix handling default template in admin.vm.Create.* methods

This commit is contained in:
Marek Marczykowski-Górecki 2017-05-13 01:25:51 +02:00
parent fcfb2e004a
commit 0160d6e2f0
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 12 additions and 12 deletions

View File

@ -584,6 +584,7 @@ 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'):
if self.arg:
assert self.arg in self.app.domains
kwargs['template'] = self.app.domains[self.arg]
else:

View File

@ -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.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):