diff --git a/gns3server/controller/appliance.py b/gns3server/controller/appliance.py index 82c4064c..2d9986ef 100644 --- a/gns3server/controller/appliance.py +++ b/gns3server/controller/appliance.py @@ -73,12 +73,16 @@ class Appliance: """ Appliance data (a hash) """ + try: + category = ID_TO_CATEGORY[self._data["category"]] + except KeyError: + category = self._data["category"] return { "appliance_id": self._id, "node_type": self._data["node_type"], "name": self._data["name"], "default_name_format": self._data.get("default_name_format", "{name}-{0}"), - "category": ID_TO_CATEGORY[self._data["category"]], + "category": category, "symbol": self._data.get("symbol", ":/symbols/computer.svg"), "compute_id": self.compute_id, "builtin": self._builtin diff --git a/tests/controller/test_appliance.py b/tests/controller/test_appliance.py index ce35e29e..3ed325a0 100644 --- a/tests/controller/test_appliance.py +++ b/tests/controller/test_appliance.py @@ -39,6 +39,27 @@ def test_appliance_json(): } +def test_appliance_json_with_not_known_category(): + a = Appliance(None, { + "node_type": "qemu", + "name": "Test", + "default_name_format": "{name}-{0}", + "category": 'Not known', + "symbol": "qemu.svg", + "server": "local" + }) + assert a.__json__() == { + "appliance_id": a.id, + "node_type": "qemu", + "builtin": False, + "name": "Test", + "default_name_format": "{name}-{0}", + "category": "Not known", + "symbol": "qemu.svg", + "compute_id": "local" + } + + def test_appliance_fix_linked_base(): """ Version of the gui before 2.1 use linked_base and the server