qubesvm: make vm.create_on_disk cleanup after failed attempt

Don't leave half-created VM - it will make harder to retry.
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-27 04:01:07 +02:00
parent 2a25db7eb7
commit ef031d6f0d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -1257,7 +1257,16 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
pools)
self.storage = qubes.storage.Storage(self)
yield from self.storage.create()
try:
yield from self.storage.create()
except:
try:
yield from self.storage.remove()
os.rmdir(self.dir_path)
except: # pylint: disable=bare-except
self.log.exception('failed to cleanup {} after failed VM '
'creation'.format(self.dir_path))
raise
self.log.info('Creating icon symlink: {} -> {}'.format(
self.icon_path, self.label.icon_path))