qubes/vm: don't fail on removing VM without files

VM files may be already removed. Don't fail on this while removing a
VM, it's probably the reason why domain is being removed.

qvm-remove tool have its own guard for this, but it isn't enough - if
rmtree(dir_path) fails, storage.remove() would not be called, so
non-file storages would not be cleaned up.

This is also needed to correctly handle template reinstallation - where
VM directory is moved away to call create_on_disk again.

QubesOS/qubes-issues#2412
This commit is contained in:
Marek Marczykowski-Górecki 2016-11-02 06:23:43 +01:00
parent cc440c62f6
commit 1418555346
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -39,6 +39,8 @@ import uuid
import warnings
import grp
import errno
import lxml
import libvirt # pylint: disable=import-error
@ -1229,7 +1231,13 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
self, self.get_power_state()))
self.fire_event('domain-remove-from-disk')
try:
shutil.rmtree(self.dir_path)
except OSError as e:
if e.errno == errno.ENOENT:
pass
else:
raise
self.storage.remove()
def clone_disk_files(self, src, pool=None, pools=None, ):