mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
parent
3df3aa84ff
commit
1e73962e33
@ -501,7 +501,7 @@ class Node:
|
||||
if self._node_type == "atm_switch":
|
||||
atm_port = set()
|
||||
# Mapping is like {"1:0:100": "10:0:200"}
|
||||
for source, dest in self.properties["mappings"].items():
|
||||
for source, dest in self._properties["mappings"].items():
|
||||
atm_port.add(int(source.split(":")[0]))
|
||||
atm_port.add(int(dest.split(":")[0]))
|
||||
atm_port = sorted(atm_port)
|
||||
@ -512,7 +512,7 @@ class Node:
|
||||
elif self._node_type == "frame_relay_switch":
|
||||
frame_relay_port = set()
|
||||
# Mapping is like {"1:101": "10:202"}
|
||||
for source, dest in self.properties["mappings"].items():
|
||||
for source, dest in self._properties["mappings"].items():
|
||||
frame_relay_port.add(int(source.split(":")[0]))
|
||||
frame_relay_port.add(int(dest.split(":")[0]))
|
||||
frame_relay_port = sorted(frame_relay_port)
|
||||
@ -520,15 +520,15 @@ class Node:
|
||||
self._ports.append(PortFactory("{}".format(port), 0, 0, port, "frame_relay"))
|
||||
return
|
||||
elif self._node_type == "dynamips":
|
||||
self._ports = DynamipsPortFactory(self.properties)
|
||||
self._ports = DynamipsPortFactory(self._properties)
|
||||
return
|
||||
elif self._node_type in ("cloud", "nat", "ethernet_switch", "ethernet_hub"):
|
||||
port_number = 0
|
||||
for port in self.properties["ports_mapping"]:
|
||||
for port in self._properties["ports_mapping"]:
|
||||
self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet"))
|
||||
port_number += 1
|
||||
else:
|
||||
self._ports = StandardPortFactory(self.properties, self._port_by_adapter, self._first_port_name, self._port_name_format, self._port_segment_size)
|
||||
self._ports = StandardPortFactory(self._properties, self._port_by_adapter, self._first_port_name, self._port_name_format, self._port_segment_size)
|
||||
return
|
||||
|
||||
def __repr__(self):
|
||||
@ -539,6 +539,17 @@ class Node:
|
||||
return False
|
||||
return self.id == other.id and other.project.id == self.project.id
|
||||
|
||||
def _filter_properties(self):
|
||||
"""
|
||||
Some properties are private and should not be exposed
|
||||
"""
|
||||
PRIVATE_PROPERTIES = ("iourc_content", )
|
||||
prop = copy.copy(self._properties)
|
||||
for k in list(prop.keys()):
|
||||
if k in PRIVATE_PROPERTIES:
|
||||
del prop[k]
|
||||
return prop
|
||||
|
||||
def __json__(self, topology_dump=False):
|
||||
"""
|
||||
:param topology_dump: Filter to keep only properties require for saving on disk
|
||||
@ -551,7 +562,7 @@ class Node:
|
||||
"name": self._name,
|
||||
"console": self._console,
|
||||
"console_type": self._console_type,
|
||||
"properties": self._properties,
|
||||
"properties": self._filter_properties(),
|
||||
"label": self._label,
|
||||
"x": self._x,
|
||||
"y": self._y,
|
||||
@ -574,7 +585,7 @@ class Node:
|
||||
"console_host": str(self._compute.console_host),
|
||||
"console_type": self._console_type,
|
||||
"command_line": self._command_line,
|
||||
"properties": self._properties,
|
||||
"properties": self._filter_properties(),
|
||||
"status": self._status,
|
||||
"label": self._label,
|
||||
"x": self._x,
|
||||
|
@ -20,6 +20,7 @@ import aiohttp
|
||||
import pytest
|
||||
import uuid
|
||||
import asyncio
|
||||
import copy
|
||||
import os
|
||||
from unittest.mock import MagicMock, ANY
|
||||
|
||||
@ -83,6 +84,19 @@ def test_eq(compute, project, node, controller):
|
||||
assert node != Node(Project(str(uuid.uuid4()), controller=controller), compute, "demo3", node_id=node.id, node_type="qemu")
|
||||
|
||||
|
||||
def test_properties_filter(project, compute):
|
||||
"""
|
||||
Some properties are private and should not be exposed
|
||||
"""
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
console_type="vnc",
|
||||
properties={"startup_script": "echo test", "iourc_content": "test"})
|
||||
assert node._properties == {"startup_script": "echo test", "iourc_content": "test"}
|
||||
assert node._filter_properties() == {"startup_script": "echo test"}
|
||||
|
||||
|
||||
def test_json(node, compute):
|
||||
assert node.__json__() == {
|
||||
"compute_id": str(compute.id),
|
||||
@ -283,8 +297,8 @@ def test_update_properties(node, compute, project, async_run, controller):
|
||||
|
||||
# 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"
|
||||
node_notif = copy.deepcopy(node.__json__())
|
||||
node_notif["properties"]["startup_script"] = "echo test"
|
||||
controller._notification.emit.assert_called_with("node.updated", node_notif)
|
||||
|
||||
|
||||
@ -436,7 +450,7 @@ def test_update_label(node):
|
||||
|
||||
|
||||
def test_get_port(node):
|
||||
node.properties["adapters"] = 2
|
||||
node._properties["adapters"] = 2
|
||||
node._list_ports()
|
||||
port = node.get_port(0, 0)
|
||||
assert port.adapter_number == 0
|
||||
|
Loading…
Reference in New Issue
Block a user