diff --git a/gns3server/compute/virtualbox/virtualbox_vm.py b/gns3server/compute/virtualbox/virtualbox_vm.py index ecd7ef2c..6f13b8d6 100644 --- a/gns3server/compute/virtualbox/virtualbox_vm.py +++ b/gns3server/compute/virtualbox/virtualbox_vm.py @@ -209,7 +209,12 @@ class VirtualBoxVM(BaseNode): Fix the VM uuid in the case of linked clone """ if os.path.exists(self._linked_vbox_file()): - tree = ET.parse(self._linked_vbox_file()) + try: + tree = ET.parse(self._linked_vbox_file()) + except ET.ParseError: + raise VirtualBoxError("Cannot modify VirtualBox linked nodes file. " + "File {} is corrupted.".format(self._linked_vbox_file())) + machine = tree.getroot().find("{http://www.virtualbox.org/}Machine") if machine is not None and machine.get("uuid") != "{" + self.id + "}": diff --git a/tests/compute/virtualbox/test_virtualbox_vm.py b/tests/compute/virtualbox/test_virtualbox_vm.py index ef617fe4..b2300280 100644 --- a/tests/compute/virtualbox/test_virtualbox_vm.py +++ b/tests/compute/virtualbox/test_virtualbox_vm.py @@ -113,3 +113,15 @@ def test_patch_vm_uuid(vm): with open(vm._linked_vbox_file()) as f: c = f.read() assert "{" + vm.id + "}" in c + + +def test_patch_vm_uuid_with_corrupted_file(vm): + xml = """ + + """ + os.makedirs(os.path.join(vm.working_dir, vm._vmname), exist_ok=True) + with open(vm._linked_vbox_file(), "w+") as f: + f.write(xml) + vm._linked_clone = True + with pytest.raises(VirtualBoxError): + vm._patch_vm_uuid() \ No newline at end of file