1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix forwarding properties

Fix #2005, #2002
This commit is contained in:
Julien Duponchelle 2017-05-16 10:22:55 +02:00
parent c231e2bbf1
commit 2a159c06c5
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 22 additions and 6 deletions

View File

@ -36,7 +36,8 @@ log = logging.getLogger(__name__)
class Node: class Node:
# This properties are used only on controller and are not forwarded to the compute # This properties are used only on controller and are not forwarded to the compute
CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "width", "height", "symbol", "label", "console_host", CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "width", "height", "symbol", "label", "console_host",
"port_name_format", "first_port_name", "port_segment_size", "ports"] "port_name_format", "first_port_name", "port_segment_size", "ports",
"category"]
def __init__(self, project, compute, name, node_id=None, node_type=None, **kwargs): def __init__(self, project, compute, name, node_id=None, node_type=None, **kwargs):
""" """
@ -90,11 +91,14 @@ class Node:
# Update node properties with additional elements # Update node properties with additional elements
for prop in kwargs: for prop in kwargs:
if prop not in ignore_properties: if prop not in ignore_properties:
if hasattr(self, prop):
try: try:
setattr(self, prop, kwargs[prop]) setattr(self, prop, kwargs[prop])
except AttributeError as e: except AttributeError as e:
log.critical("Can't set attribute %s", prop) log.critical("Can't set attribute %s", prop)
raise e raise e
else:
self.properties[prop] = kwargs[prop]
if self._symbol is None: if self._symbol is None:
self.symbol = ":/symbols/computer.svg" self.symbol = ":/symbols/computer.svg"

View File

@ -81,6 +81,18 @@ def test_name(compute, project):
assert node.name == "PC2" assert node.name == "PC2"
def test_vmname(compute, project):
"""
Additionnal properties should add to the properties
field
"""
node = Node(project, compute, "PC",
node_id=str(uuid.uuid4()),
node_type="virtualbox",
vmname="test")
assert node.properties["vmname"] == "test"
def test_eq(compute, project, node, controller): def test_eq(compute, project, node, controller):
assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu") assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")
assert node != "a" assert node != "a"