From 0160d6e2f00ff5e198bb4b77af4d54c005a199e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 13 May 2017 01:25:51 +0200 Subject: [PATCH] admin: fix handling default template in admin.vm.Create.* methods --- qubes/api/admin.py | 5 +++-- qubes/tests/api_admin.py | 19 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/qubes/api/admin.py b/qubes/api/admin.py index 516eaa73..6f20fb90 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -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 diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index f4b475d1..3c60d8a8 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -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):