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
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-08 02:53:09 +02:00
parent 148d1cda78
commit c32f0db582
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 10 additions and 7 deletions

View File

@ -69,8 +69,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI):
def create_dispvm(self): def create_dispvm(self):
assert not self.arg assert not self.arg
# TODO convert to coroutine dispvm = yield from qubes.vm.dispvm.DispVM.from_appvm(self.dest)
dispvm = qubes.vm.dispvm.DispVM.from_appvm(self.dest)
return dispvm.name return dispvm.name
@qubes.api.method('internal.vm.CleanupDispVM', no_payload=True) @qubes.api.method('internal.vm.CleanupDispVM', no_payload=True)
@ -78,8 +77,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI):
def cleanup_dispvm(self): def cleanup_dispvm(self):
assert not self.arg assert not self.arg
# TODO convert to coroutine yield from self.dest.cleanup()
self.dest.cleanup()
@qubes.api.method('internal.vm.volume.ImportEnd') @qubes.api.method('internal.vm.volume.ImportEnd')
@asyncio.coroutine @asyncio.coroutine

View File

@ -23,6 +23,8 @@
import copy import copy
import asyncio
import qubes.vm.qubesvm import qubes.vm.qubesvm
import qubes.vm.appvm import qubes.vm.appvm
import qubes.config import qubes.config
@ -116,6 +118,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
'Cannot change template of Disposable VM') 'Cannot change template of Disposable VM')
@classmethod @classmethod
@asyncio.coroutine
def from_appvm(cls, appvm, **kwargs): def from_appvm(cls, appvm, **kwargs):
'''Create a new instance from given AppVM '''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() proplist = [prop for prop in dispvm.property_list()
if prop.clone and prop.__name__ not in ['template']] if prop.clone and prop.__name__ not in ['template']]
dispvm.clone_properties(app.domains[appvm], proplist=proplist) dispvm.clone_properties(app.domains[appvm], proplist=proplist)
dispvm.create_on_disk() yield from dispvm.create_on_disk()
app.save() app.save()
return dispvm return dispvm
@asyncio.coroutine
def cleanup(self): def cleanup(self):
'''Clean up after the DispVM '''Clean up after the DispVM
@ -158,9 +162,10 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
This method modifies :file:`qubes.xml` file. This method modifies :file:`qubes.xml` file.
''' '''
try: try:
self.force_shutdown() # pylint: disable=not-an-iterable
yield from self.kill()
except qubes.exc.QubesVMNotStartedError: except qubes.exc.QubesVMNotStartedError:
pass pass
self.remove_from_disk() yield from self.remove_from_disk()
del self.app.domains[self] del self.app.domains[self]
self.app.save() self.app.save()