mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Merge remote-tracking branch 'origin/2.0' into 2.0
This commit is contained in:
commit
7beadd03a6
@ -84,6 +84,7 @@ class Node:
|
|||||||
|
|
||||||
@name.setter
|
@name.setter
|
||||||
def name(self, new_name):
|
def name(self, new_name):
|
||||||
|
self._project.update_node_name(self, new_name)
|
||||||
self._name = new_name
|
self._name = new_name
|
||||||
# The text in label need to be always the node name
|
# The text in label need to be always the node name
|
||||||
self._label["text"] = new_name
|
self._label["text"] = new_name
|
||||||
@ -205,19 +206,22 @@ 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
|
||||||
|
|
||||||
# update the node name if present
|
compute_properties = None
|
||||||
self._project.update_node_name(self, kwargs.get("name"))
|
|
||||||
|
|
||||||
# Update node properties with additional elements
|
# Update node properties with additional elements
|
||||||
for prop in kwargs:
|
for prop in kwargs:
|
||||||
if getattr(self, prop) != kwargs[prop]:
|
if getattr(self, prop) != kwargs[prop]:
|
||||||
if prop not in self.CONTROLLER_ONLY_PROPERTIES:
|
if prop not in self.CONTROLLER_ONLY_PROPERTIES:
|
||||||
update_compute = True
|
update_compute = True
|
||||||
|
|
||||||
|
# We update properties on the compute and wait for the anwser from the compute node
|
||||||
|
if prop == "properties":
|
||||||
|
compute_properties = kwargs[prop]
|
||||||
|
else:
|
||||||
setattr(self, prop, kwargs[prop])
|
setattr(self, prop, kwargs[prop])
|
||||||
|
|
||||||
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()
|
data = self._node_data(properties=compute_properties)
|
||||||
response = yield from self.put(None, data=data)
|
response = yield from self.put(None, data=data)
|
||||||
self.parse_node_response(response.json)
|
self.parse_node_response(response.json)
|
||||||
|
|
||||||
@ -243,10 +247,15 @@ class Node:
|
|||||||
else:
|
else:
|
||||||
self._properties[key] = value
|
self._properties[key] = value
|
||||||
|
|
||||||
def _node_data(self):
|
def _node_data(self, properties=None):
|
||||||
"""
|
"""
|
||||||
Prepare node data to send to the remote controller
|
Prepare node data to send to the remote controller
|
||||||
|
|
||||||
|
:param properties: If properties is None use actual property otherwise use the parameter
|
||||||
"""
|
"""
|
||||||
|
if properties:
|
||||||
|
data = copy.copy(properties)
|
||||||
|
else:
|
||||||
data = copy.copy(self._properties)
|
data = copy.copy(self._properties)
|
||||||
data["name"] = self._name
|
data["name"] = self._name
|
||||||
if self._console:
|
if self._console:
|
||||||
|
@ -138,6 +138,34 @@ def test_update(node, compute, project, async_run, controller):
|
|||||||
controller._notification.emit.assert_called_with("node.updated", node.__json__())
|
controller._notification.emit.assert_called_with("node.updated", node.__json__())
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_properties(node, compute, project, async_run, controller):
|
||||||
|
"""
|
||||||
|
properties will be updated by the answer from compute
|
||||||
|
"""
|
||||||
|
response = MagicMock()
|
||||||
|
response.json = {"console": 2048}
|
||||||
|
compute.put = AsyncioMagicMock(return_value=response)
|
||||||
|
controller._notification = AsyncioMagicMock()
|
||||||
|
|
||||||
|
async_run(node.update(x=42, console=2048, console_type="vnc", properties={"startup_script": "hello world"}, name="demo"))
|
||||||
|
data = {
|
||||||
|
"console": 2048,
|
||||||
|
"console_type": "vnc",
|
||||||
|
"startup_script": "hello world",
|
||||||
|
"name": "demo"
|
||||||
|
}
|
||||||
|
compute.put.assert_called_with("/projects/{}/vpcs/nodes/{}".format(node.project.id, node.id), data=data)
|
||||||
|
assert node._console == 2048
|
||||||
|
assert node.x == 42
|
||||||
|
assert node._properties == {"startup_script": "echo test"}
|
||||||
|
|
||||||
|
# The notif should contain the old properties because it's the compute that will emit
|
||||||
|
# the correct info
|
||||||
|
node_notif = node.__json__()
|
||||||
|
node_notif["properties"]["startup_config"] = "echo test"
|
||||||
|
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, 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
|
||||||
|
Loading…
Reference in New Issue
Block a user