From 1418555346db11136d97e257b4fc2a222d7ee8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 2 Nov 2016 06:23:43 +0100 Subject: [PATCH] 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 --- qubes/vm/qubesvm.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 3686997d..d6da4f3b 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -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') - shutil.rmtree(self.dir_path) + 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, ):