From e6149b09cef8a6e2343021596c6d5d619cbf64c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 6 Jul 2017 14:17:15 +0200 Subject: [PATCH] Fix VM creation with default template Fixes QubesOS/qubes-issues#2866 --- qubesadmin/app.py | 4 +++- qubesadmin/tests/app.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qubesadmin/app.py b/qubesadmin/app.py index 4bf844c..f8a5424 100644 --- a/qubesadmin/app.py +++ b/qubesadmin/app.py @@ -248,7 +248,9 @@ class QubesBase(qubesadmin.base.PropertyHolder): if not isinstance(cls, str): cls = cls.__name__ - if template is not None: + if template is qubesadmin.DEFAULT: + template = None + elif template is not None: template = str(template) if pool and pools: diff --git a/qubesadmin/tests/app.py b/qubesadmin/tests/app.py index d5b0ce9..74f9226 100644 --- a/qubesadmin/tests/app.py +++ b/qubesadmin/tests/app.py @@ -148,6 +148,17 @@ class TC_10_QubesBase(qubesadmin.tests.QubesTestCase): self.assertEqual(vm.__class__.__name__, 'AppVM') self.assertAllCalled() + def test_016_new_template_based_default(self): + self.app.expected_calls[('dom0', 'admin.vm.Create.AppVM', + None, b'name=new-vm label=red')] = b'0\x00' + self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00new-vm class=AppVM state=Running\n' + vm = self.app.add_new_vm('AppVM', 'new-vm', 'red', + template=qubesadmin.DEFAULT) + self.assertEqual(vm.name, 'new-vm') + self.assertEqual(vm.__class__.__name__, 'AppVM') + self.assertAllCalled() + def test_020_get_label(self): self.app.expected_calls[('dom0', 'admin.label.List', None, None)] = \ b'0\x00red\nblue\n'