mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 09:00:57 +00:00
Fix: #1066 - Catching parsing errors at linked vbox file
This commit is contained in:
parent
c1c3a9ed80
commit
5c0d955156
@ -209,7 +209,12 @@ class VirtualBoxVM(BaseNode):
|
|||||||
Fix the VM uuid in the case of linked clone
|
Fix the VM uuid in the case of linked clone
|
||||||
"""
|
"""
|
||||||
if os.path.exists(self._linked_vbox_file()):
|
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")
|
machine = tree.getroot().find("{http://www.virtualbox.org/}Machine")
|
||||||
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
|
if machine is not None and machine.get("uuid") != "{" + self.id + "}":
|
||||||
|
|
||||||
|
@ -113,3 +113,15 @@ def test_patch_vm_uuid(vm):
|
|||||||
with open(vm._linked_vbox_file()) as f:
|
with open(vm._linked_vbox_file()) as f:
|
||||||
c = f.read()
|
c = f.read()
|
||||||
assert "{" + vm.id + "}" in c
|
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()
|
Loading…
Reference in New Issue
Block a user