From c32f0db5821f44b204181681faf555dd112a9ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 8 Jul 2017 02:53:09 +0200 Subject: [PATCH] vm/dispvm: convert DispVM related function to coroutines Some functions used there (create_on_disk, remove_from_disk, kill) are coroutines, so callers needs to be too. Fixes QubesOS/qubes-issues#2896 --- qubes/api/internal.py | 6 ++---- qubes/vm/dispvm.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/qubes/api/internal.py b/qubes/api/internal.py index c58c5964..97232d02 100644 --- a/qubes/api/internal.py +++ b/qubes/api/internal.py @@ -69,8 +69,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI): def create_dispvm(self): assert not self.arg - # TODO convert to coroutine - dispvm = qubes.vm.dispvm.DispVM.from_appvm(self.dest) + dispvm = yield from qubes.vm.dispvm.DispVM.from_appvm(self.dest) return dispvm.name @qubes.api.method('internal.vm.CleanupDispVM', no_payload=True) @@ -78,8 +77,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI): def cleanup_dispvm(self): assert not self.arg - # TODO convert to coroutine - self.dest.cleanup() + yield from self.dest.cleanup() @qubes.api.method('internal.vm.volume.ImportEnd') @asyncio.coroutine diff --git a/qubes/vm/dispvm.py b/qubes/vm/dispvm.py index 55b2f48c..24b65892 100644 --- a/qubes/vm/dispvm.py +++ b/qubes/vm/dispvm.py @@ -23,6 +23,8 @@ import copy +import asyncio + import qubes.vm.qubesvm import qubes.vm.appvm import qubes.config @@ -116,6 +118,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM): 'Cannot change template of Disposable VM') @classmethod + @asyncio.coroutine def from_appvm(cls, appvm, **kwargs): '''Create a new instance from given AppVM @@ -147,10 +150,11 @@ class DispVM(qubes.vm.qubesvm.QubesVM): proplist = [prop for prop in dispvm.property_list() if prop.clone and prop.__name__ not in ['template']] dispvm.clone_properties(app.domains[appvm], proplist=proplist) - dispvm.create_on_disk() + yield from dispvm.create_on_disk() app.save() return dispvm + @asyncio.coroutine def cleanup(self): '''Clean up after the DispVM @@ -158,9 +162,10 @@ class DispVM(qubes.vm.qubesvm.QubesVM): This method modifies :file:`qubes.xml` file. ''' try: - self.force_shutdown() + # pylint: disable=not-an-iterable + yield from self.kill() except qubes.exc.QubesVMNotStartedError: pass - self.remove_from_disk() + yield from self.remove_from_disk() del self.app.domains[self] self.app.save()