From 5555662b2c85ab488f3eaae79196ff6e631a88fb Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 27 Sep 2016 11:21:40 +0200 Subject: [PATCH] Fix If I change the content of cloud the cloud no longer work Fix #1540 --- gns3server/compute/builtin/nodes/cloud.py | 7 +++- tests/compute/builtin/nodes/test_cloud.py | 39 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/gns3server/compute/builtin/nodes/cloud.py b/gns3server/compute/builtin/nodes/cloud.py index 54d17ab0..5b5bfdf7 100644 --- a/gns3server/compute/builtin/nodes/cloud.py +++ b/gns3server/compute/builtin/nodes/cloud.py @@ -58,7 +58,7 @@ class Cloud(BaseNode): "name": interface["name"] }) else: - self._ports_mapping = ports + self.ports_mapping = ports def _interfaces(self): return gns3server.utils.interfaces.interfaces() @@ -100,6 +100,11 @@ class Cloud(BaseNode): if len(self._nios) > 0: raise NodeError("Can't modify a cloud already connected.") + port_number = 0 + for port in ports: + port["port_number"] = port_number + port_number += 1 + self._ports_mapping = ports @asyncio.coroutine diff --git a/tests/compute/builtin/nodes/test_cloud.py b/tests/compute/builtin/nodes/test_cloud.py index 361b694a..40036a66 100644 --- a/tests/compute/builtin/nodes/test_cloud.py +++ b/tests/compute/builtin/nodes/test_cloud.py @@ -83,3 +83,42 @@ def test_json_without_ports(on_gns3vm, project): {'name': 'virbr0', 'special': True, 'type': 'ethernet'} ] } + + +def test_update_port_mappings(on_gns3vm, project): + """ + We don't allow an empty interface in the middle of port list + """ + ports1 = [ + { + "interface": "eth0", + "name": "eth0", + "port_number": 0, + "type": "ethernet" + }, + { + "interface": "eth1", + "name": "eth1", + "port_number": 1, + "type": "ethernet" + } + ] + cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports1) + assert cloud.ports_mapping == ports1 + + ports2 = [ + { + "interface": "eth0", + "name": "eth0", + "port_number": 0, + "type": "ethernet" + }, + { + "interface": "eth1", + "name": "eth1", + "port_number": 2, + "type": "ethernet" + } + ] + cloud = Cloud("cloud2", str(uuid.uuid4()), project, MagicMock(), ports=ports2) + assert cloud.ports_mapping == ports1