mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-18 20:37:57 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e4735308f8
13
README.rst
13
README.rst
@ -113,4 +113,17 @@ and homebrew: http://brew.sh/.
|
||||
python3 setup.py install
|
||||
gns3server
|
||||
|
||||
Running tests
|
||||
*************
|
||||
|
||||
Just run:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
py.test -vv
|
||||
|
||||
If you want test coverage:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
py.test --cov=gns3server
|
||||
|
@ -91,7 +91,7 @@ class PortManager:
|
||||
|
||||
return self._console_port_range
|
||||
|
||||
@console_host.setter
|
||||
@console_port_range.setter
|
||||
def console_port_range(self, new_range):
|
||||
|
||||
assert isinstance(new_range, tuple)
|
||||
@ -112,7 +112,7 @@ class PortManager:
|
||||
|
||||
return self._udp_port_range
|
||||
|
||||
@udp_host.setter
|
||||
@udp_port_range.setter
|
||||
def udp_port_range(self, new_range):
|
||||
|
||||
assert isinstance(new_range, tuple)
|
||||
@ -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))
|
||||
@ -249,6 +251,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))
|
||||
|
@ -94,7 +94,6 @@ class WinStreamHandler(logging.StreamHandler):
|
||||
stream.write(msg.encode(stream.encoding, errors="replace").decode(stream.encoding))
|
||||
stream.write(self.terminator)
|
||||
self.flush()
|
||||
pass
|
||||
except Exception:
|
||||
self.handleError(record)
|
||||
|
||||
|
@ -73,7 +73,7 @@ def _get_unused_port():
|
||||
return port
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@pytest.fixture
|
||||
def server(request, loop, port_manager, monkeypatch):
|
||||
"""A GNS3 server"""
|
||||
|
||||
|
@ -144,10 +144,10 @@ def test_backup_images(server, tmpdir, loop):
|
||||
tar.close()
|
||||
|
||||
assert os.path.exists(os.path.join('QEMU', 'a.img'))
|
||||
open(os.path.join('QEMU', 'a.img')).read() == 'hello'
|
||||
assert open(os.path.join('QEMU', 'a.img')).read() == 'hello'
|
||||
|
||||
assert os.path.exists(os.path.join('QEMU', 'b.img'))
|
||||
open(os.path.join('QEMU', 'b.img')).read() == 'world'
|
||||
assert open(os.path.join('QEMU', 'b.img')).read() == 'world'
|
||||
|
||||
|
||||
def test_backup_projects(server, tmpdir, loop):
|
||||
@ -176,7 +176,7 @@ def test_backup_projects(server, tmpdir, loop):
|
||||
tar.close()
|
||||
|
||||
assert os.path.exists(os.path.join('a', 'a.gns3'))
|
||||
open(os.path.join('a', 'a.gns3')).read() == 'hello'
|
||||
assert open(os.path.join('a', 'a.gns3')).read() == 'hello'
|
||||
|
||||
assert os.path.exists(os.path.join('b', 'b.gns3'))
|
||||
open(os.path.join('b', 'b.gns3')).read() == 'world'
|
||||
assert open(os.path.join('b', 'b.gns3')).read() == 'world'
|
||||
|
@ -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():
|
||||
|
@ -171,15 +171,6 @@ def test_update_startup_script(vm):
|
||||
assert f.read() == content
|
||||
|
||||
|
||||
def test_update_startup_script(vm):
|
||||
content = "echo GNS3 VPCS\nip 192.168.1.2\n"
|
||||
vm.startup_script = content
|
||||
filepath = os.path.join(vm.working_dir, 'startup.vpc')
|
||||
assert os.path.exists(filepath)
|
||||
with open(filepath) as f:
|
||||
assert f.read() == content
|
||||
|
||||
|
||||
def test_update_startup_script_h(vm):
|
||||
content = "setname %h\n"
|
||||
vm.name = "pc1"
|
||||
|
Loading…
Reference in New Issue
Block a user