1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Send node.updated notif only if object changed

This commit is contained in:
Julien Duponchelle 2016-06-30 18:29:17 +02:00
parent 758a427a76
commit fe7bcae6a1
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 24 additions and 11 deletions

View File

@ -214,6 +214,8 @@ class Node:
# When updating properties used only on controller we don't need to call the compute # When updating properties used only on controller we don't need to call the compute
update_compute = False update_compute = False
old_json = self.__json__()
compute_properties = None compute_properties = None
# Update node properties with additional elements # Update node properties with additional elements
for prop in kwargs: for prop in kwargs:
@ -227,6 +229,8 @@ class Node:
else: else:
setattr(self, prop, kwargs[prop]) setattr(self, prop, kwargs[prop])
# We send notif only if object has changed
if old_json != self.__json__():
self.project.controller.notification.emit("node.updated", self.__json__()) self.project.controller.notification.emit("node.updated", self.__json__())
if update_compute: if update_compute:
data = self._node_data(properties=compute_properties) data = self._node_data(properties=compute_properties)
@ -392,9 +396,9 @@ class Node:
"console_type": self._console_type, "console_type": self._console_type,
"properties": self._properties, "properties": self._properties,
"label": self._label, "label": self._label,
"x": self._x, "x": int(self._x),
"y": self._y, "y": int(self._y),
"z": self._z, "z": int(self._z),
"symbol": self._symbol "symbol": self._symbol
} }
return { return {
@ -411,8 +415,8 @@ class Node:
"properties": self._properties, "properties": self._properties,
"status": self._status, "status": self._status,
"label": self._label, "label": self._label,
"x": self._x, "x": int(self._x),
"y": self._y, "y": int(self._y),
"z": self._z, "z": int(self._z),
"symbol": self._symbol "symbol": self._symbol
} }

View File

@ -146,15 +146,15 @@ NODE_OBJECT_SCHEMA = {
}, },
"x": { "x": {
"description": "X position of the node", "description": "X position of the node",
"type": "number" "type": "integer"
}, },
"y": { "y": {
"description": "Y position of the node", "description": "Y position of the node",
"type": "number" "type": "integer"
}, },
"z": { "z": {
"description": "Z position of the node", "description": "Z position of the node",
"type": "number" "type": "integer"
} }
}, },
"additionalProperties": False, "additionalProperties": False,

View File

@ -186,16 +186,25 @@ def test_update_properties(node, compute, project, async_run, controller):
controller._notification.emit.assert_called_with("node.updated", node_notif) 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 When updating property used only on controller we don't need to
call the compute call the compute
""" """
compute.put = AsyncioMagicMock() compute.put = AsyncioMagicMock()
controller._notification = AsyncioMagicMock()
async_run(node.update(x=42)) async_run(node.update(x=42))
assert not compute.put.called assert not compute.put.called
assert node.x == 42 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): def test_update_no_changes(node, compute, project, async_run):