diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index c8aa8a2d..f3566d19 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -204,6 +204,10 @@ class Node: @symbol.setter def symbol(self, val): + # No abs path, fix them (bug of 1.X) + if not val.startswith(":") and os.path.abspath(val): + val = os.path.basename(val) + self._symbol = val try: self._width, self._height, filetype = self._project.controller.symbols.get_size(val) diff --git a/gns3server/controller/symbols.py b/gns3server/controller/symbols.py index f3979adc..24e73257 100644 --- a/gns3server/controller/symbols.py +++ b/gns3server/controller/symbols.py @@ -70,7 +70,12 @@ class Symbols: return directory def get_path(self, symbol_id): - return self._symbols_path[symbol_id] + try: + return self._symbols_path[symbol_id] + # Symbol not found refresh cache + except KeyError: + self.list() + return self._symbols_path[symbol_id] def get_size(self, symbol_id): try: diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index 5e3d06df..6edb8fdb 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import shutil import aiohttp import pytest import uuid @@ -188,7 +189,7 @@ def test_create_image_missing(node, compute, project, async_run): node._upload_missing_image.called is True -def test_symbol(node): +def test_symbol(node, symbols_dir): """ Change symbol should change the node size """ @@ -203,11 +204,22 @@ def test_symbol(node): assert node.symbol == ":/symbols/cloud.svg" assert node.width == 159 assert node.height == 71 - assert node.label["x"] is None assert node.label["y"] == -40 assert node.label["style"] == "font-size: 10;font-familly: Verdana" + shutil.copy(os.path.join("gns3server", "symbols", "cloud.svg"), os.path.join(symbols_dir, "cloud2.svg")) + node.symbol = "cloud2.svg" + assert node.symbol == "cloud2.svg" + assert node.width == 159 + assert node.height == 71 + + # No abs path, fix them (bug of 1.5) + node.symbol = "/tmp/cloud2.svg" + assert node.symbol == "cloud2.svg" + assert node.width == 159 + assert node.height == 71 + def test_label_with_default_label_font(node): """