1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Fix issues with macos X dynamips not freeing UDP port

Fix #133
This commit is contained in:
Julien Duponchelle 2015-04-03 13:32:07 +02:00
parent 1acc9398d5
commit b46e2cf013
3 changed files with 39 additions and 2 deletions

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import socket import socket
import sys
import ipaddress import ipaddress
from aiohttp.web import HTTPConflict from aiohttp.web import HTTPConflict
from gns3server.config import Config from gns3server.config import Config
@ -251,14 +252,19 @@ class PortManager:
project.record_udp_port(port) project.record_udp_port(port)
log.debug("UDP port {} has been reserved".format(port)) log.debug("UDP port {} has been reserved".format(port))
def release_udp_port(self, port, project): def release_udp_port(self, port, project, force_remove=False):
""" """
Release a specific UDP port number Release a specific UDP port number
:param port: UDP port number :param port: UDP port number
:param project: Project instance :param project: Project instance
:param force_remove: Force port removal even on Darwnin
""" """
# A bug with dynamips on darwin doesn't correctly free the port we free it only when changing project
if sys.platform.startswith("darwin") and force_remove is False:
return
if port in self._used_udp_ports: if port in self._used_udp_ports:
self._used_udp_ports.remove(port) self._used_udp_ports.remove(port)
project.remove_udp_port(port) project.remove_udp_port(port)

View File

@ -361,7 +361,7 @@ class Project:
for port in self._used_tcp_ports.copy(): for port in self._used_tcp_ports.copy():
port_manager.release_tcp_port(port, self) port_manager.release_tcp_port(port, self)
for port in self._used_udp_ports.copy(): for port in self._used_udp_ports.copy():
port_manager.release_udp_port(port, self) port_manager.release_udp_port(port, self, force_remove=True)
@asyncio.coroutine @asyncio.coroutine
def commit(self): def commit(self):

View File

@ -17,12 +17,43 @@
import aiohttp import aiohttp
import pytest import pytest
import sys
from unittest.mock import patch
from gns3server.modules.port_manager import PortManager from gns3server.modules.port_manager import PortManager
from gns3server.modules.project import Project from gns3server.modules.project import Project
def test_reserve_tcp_port(): def test_reserve_tcp_port():
pm = PortManager() pm = PortManager()
project = Project() project = Project()
pm.reserve_tcp_port(4242, project) pm.reserve_tcp_port(4242, project)
with pytest.raises(aiohttp.web.HTTPConflict): with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_tcp_port(4242, project) pm.reserve_tcp_port(4242, project)
def test_reserve_udp_port():
pm = PortManager()
project = Project()
pm.reserve_udp_port(4242, project)
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_udp_port(4242, project)
@pytest.mark.skipif(sys.platform == 'darwin', reason="not working on darwin")
def test_release_udp_port():
pm = PortManager()
project = Project()
pm.reserve_udp_port(4242, project)
pm.release_udp_port(4242, project)
pm.reserve_udp_port(4242, project)
@pytest.mark.skipif(sys.platform != 'darwin', reason="requires darwin")
def test_release_darwin_udp_port():
"""Due to dynamips / darwin bug we didn't free the port"""
pm = PortManager()
project = Project()
pm.reserve_udp_port(4242, project)
pm.release_udp_port(4242, project)
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_udp_port(4242, project)