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

Merge branch 'master' into unstable

This commit is contained in:
Julien Duponchelle 2015-10-30 15:17:17 +01:00
commit 6edb41ded7
2 changed files with 25 additions and 7 deletions

View File

@ -203,6 +203,8 @@ class PortManager:
if port in self._used_tcp_ports:
raise HTTPConflict(text="TCP port {} already in use on host".format(port, self._console_host))
if port < self._console_port_range[0] or port > self._console_port_range[1]:
raise HTTPConflict(text="TCP port {} is outside the range {}-{}".format(port, self._console_port_range[0], self._console_port_range[1]))
self._used_tcp_ports.add(port)
project.record_tcp_port(port)
log.debug("TCP port {} has been reserved".format(port))
@ -248,6 +250,8 @@ class PortManager:
if port in self._used_udp_ports:
raise HTTPConflict(text="UDP port {} already in use on host".format(port, self._console_host))
if port < self._udp_port_range[0] or port > self._udp_port_range[1]:
raise HTTPConflict(text="UDP port {} is outside the range {}-{}".format(port, self._udp_port_range[0], self._udp_port_range[1]))
self._used_udp_ports.add(port)
project.record_udp_port(port)
log.debug("UDP port {} has been reserved".format(port))

View File

@ -26,25 +26,39 @@ from gns3server.modules.project import Project
def test_reserve_tcp_port():
pm = PortManager()
project = Project()
pm.reserve_tcp_port(4242, project)
pm.reserve_tcp_port(2001, project)
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_tcp_port(4242, project)
pm.reserve_tcp_port(2001, project)
def test_reserve_tcp_port_outside_range():
pm = PortManager()
project = Project()
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_tcp_port(80, project)
def test_reserve_udp_port():
pm = PortManager()
project = Project()
pm.reserve_udp_port(4242, project)
pm.reserve_udp_port(10000, project)
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_udp_port(4242, project)
pm.reserve_udp_port(10000, project)
def test_reserve_udp_port_outside_range():
pm = PortManager()
project = Project()
with pytest.raises(aiohttp.web.HTTPConflict):
pm.reserve_udp_port(80, project)
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)
pm.reserve_udp_port(10000, project)
pm.release_udp_port(10000, project)
pm.reserve_udp_port(10000, project)
def test_find_unused_port():