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

Disallow running IOU on multiple server

Fix #690
This commit is contained in:
Julien Duponchelle 2016-09-26 15:35:58 +02:00
parent f3596767c1
commit c91999c532
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 53 additions and 23 deletions

View File

@ -322,14 +322,23 @@ class Project:
@open_required @open_required
@asyncio.coroutine @asyncio.coroutine
def add_node(self, compute, name, node_id, **kwargs): def add_node(self, compute, name, node_id, node_type=None, **kwargs):
""" """
Create a node or return an existing node Create a node or return an existing node
:param kwargs: See the documentation of node :param kwargs: See the documentation of node
""" """
if node_id not in self._nodes: if node_id in self._nodes:
node = Node(self, compute, name, node_id=node_id, **kwargs) return self._nodes[node_id]
# Due to a limitation all iou need to run on the same
# compute server otherwise you have mac address conflict
if node_type == "iou":
for node in self._nodes.values():
if node.node_type == node_type and node.compute != compute:
raise aiohttp.web.HTTPConflict(text="All IOU nodes need to run on the same server.")
node = Node(self, compute, name, node_id=node_id, node_type=node_type, **kwargs)
if compute not in self._project_created_on_compute: if compute not in self._project_created_on_compute:
# For a local server we send the project path # For a local server we send the project path
if compute.id == "local": if compute.id == "local":
@ -350,7 +359,6 @@ class Project:
self.controller.notification.emit("node.created", node.__json__()) self.controller.notification.emit("node.created", node.__json__())
self.dump() self.dump()
return node return node
return self._nodes[node_id]
@open_required @open_required
@asyncio.coroutine @asyncio.coroutine

View File

@ -178,6 +178,28 @@ def test_add_node_non_local(async_run, controller):
controller.notification.emit.assert_any_call("node.created", node.__json__()) controller.notification.emit.assert_any_call("node.created", node.__json__())
def test_create_iou_on_multiple_node(async_run, controller):
"""
Due to mac address collision you can't create an IOU node
on two different server
"""
compute = MagicMock()
compute.id = "remote"
compute2 = MagicMock()
compute2.id = "remote2"
project = Project(controller=controller, name="Test")
response = MagicMock()
response.json = {"console": 2048}
compute.post = AsyncioMagicMock(return_value=response)
node1 = async_run(project.add_node(compute, "test", None, node_type="iou"))
with pytest.raises(aiohttp.web_exceptions.HTTPConflict):
async_run(project.add_node(compute2, "test2", None, node_type="iou"))
def test_delete_node(async_run, controller): def test_delete_node(async_run, controller):
""" """
For a local server we send the project path For a local server we send the project path