1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Handle invalid appliances files

Fix #1150
This commit is contained in:
Julien Duponchelle 2017-07-28 15:21:35 +02:00
parent 2eead38cd8
commit 6996b7094f
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 10 additions and 3 deletions

View File

@ -78,10 +78,11 @@ class Controller:
try: try:
with open(path, 'r', encoding='utf-8') as f: with open(path, 'r', encoding='utf-8') as f:
appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin) appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin)
except (ValueError, OSError) as e: appliance.__json__() # Check if loaded without error
if appliance.status != 'broken':
self._appliance_templates[appliance.id] = appliance
except (ValueError, OSError, KeyError) as e:
log.warning("Can't load %s: %s", path, str(e)) log.warning("Can't load %s: %s", path, str(e))
if appliance.status != 'broken':
self._appliance_templates[appliance.id] = appliance
self._appliances = {} self._appliances = {}
vms = [] vms = []

View File

@ -481,6 +481,12 @@ def test_appliance_templates(controller, async_run, tmpdir):
} }
with open(str(tmpdir / "my_appliance.gns3a"), 'w+') as f: with open(str(tmpdir / "my_appliance.gns3a"), 'w+') as f:
json.dump(my_appliance, f) json.dump(my_appliance, f)
# A broken appliance
my_appliance = {
"name": "Broken"
}
with open(str(tmpdir / "my_appliance2.gns3a"), 'w+') as f:
json.dump(my_appliance, f)
with patch("gns3server.config.Config.get_section_config", return_value={"appliances_path": str(tmpdir)}): with patch("gns3server.config.Config.get_section_config", return_value={"appliances_path": str(tmpdir)}):
controller.load_appliances() controller.load_appliances()