1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +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:
with open(path, 'r', encoding='utf-8') as f:
appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin)
except (ValueError, OSError) as e:
log.warning("Can't load %s: %s", path, str(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))
self._appliances = {}
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:
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)}):
controller.load_appliances()