diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index 8f63f393..16141a73 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -214,6 +214,8 @@ class Node: # When updating properties used only on controller we don't need to call the compute update_compute = False + old_json = self.__json__() + compute_properties = None # Update node properties with additional elements for prop in kwargs: @@ -227,7 +229,9 @@ class Node: else: setattr(self, prop, kwargs[prop]) - self.project.controller.notification.emit("node.updated", self.__json__()) + # We send notif only if object has changed + if old_json != self.__json__(): + self.project.controller.notification.emit("node.updated", self.__json__()) if update_compute: data = self._node_data(properties=compute_properties) response = yield from self.put(None, data=data) @@ -392,9 +396,9 @@ class Node: "console_type": self._console_type, "properties": self._properties, "label": self._label, - "x": self._x, - "y": self._y, - "z": self._z, + "x": int(self._x), + "y": int(self._y), + "z": int(self._z), "symbol": self._symbol } return { @@ -411,8 +415,8 @@ class Node: "properties": self._properties, "status": self._status, "label": self._label, - "x": self._x, - "y": self._y, - "z": self._z, + "x": int(self._x), + "y": int(self._y), + "z": int(self._z), "symbol": self._symbol } diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index a18da641..5cf2653f 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -146,15 +146,15 @@ NODE_OBJECT_SCHEMA = { }, "x": { "description": "X position of the node", - "type": "number" + "type": "integer" }, "y": { "description": "Y position of the node", - "type": "number" + "type": "integer" }, "z": { "description": "Z position of the node", - "type": "number" + "type": "integer" } }, "additionalProperties": False, diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index 7f1296e4..c431c9fa 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -186,16 +186,25 @@ def test_update_properties(node, compute, project, async_run, controller): controller._notification.emit.assert_called_with("node.updated", node_notif) -def test_update_only_controller(node, compute, project, async_run): + +def test_update_only_controller(node, controller, compute, project, async_run): """ When updating property used only on controller we don't need to call the compute """ compute.put = AsyncioMagicMock() + controller._notification = AsyncioMagicMock() async_run(node.update(x=42)) assert not compute.put.called assert node.x == 42 + controller._notification.emit.assert_called_with("node.updated", node.__json__()) + + # If nothing change a second notif should not be send + controller._notification = AsyncioMagicMock() + async_run(node.update(x=42)) + assert not controller._notification.emit.called + def test_update_no_changes(node, compute, project, async_run):