1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Fix: #1066 - Catching parsing errors at linked vbox file

This commit is contained in:
ziajka 2017-06-09 09:57:47 +02:00 committed by Julien Duponchelle
parent c1c3a9ed80
commit 5c0d955156
2 changed files with 18 additions and 1 deletions

View File

@ -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 + "}":

View File

@ -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 = """<?xml version="1.0"?>
<VirtualBox>
"""
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()