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

Code cleanup

This commit is contained in:
Julien Duponchelle 2016-02-05 10:06:34 +01:00
parent 5bee927481
commit 373113545f
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
5 changed files with 34 additions and 35 deletions

View File

@ -403,9 +403,9 @@ class IOUVM(BaseVM):
raise IOUError("Hostname \"{}\" not found in iourc file {}".format(hostname, self.iourc_path))
user_ioukey = config["license"][hostname]
if user_ioukey[-1:] != ';':
raise IOUError("IOU key not ending with ; in iourc file".format(self.iourc_path))
raise IOUError("IOU key not ending with ; in iourc file {}".format(self.iourc_path))
if len(user_ioukey) != 17:
raise IOUError("IOU key length is not 16 characters in iourc file".format(self.iourc_path))
raise IOUError("IOU key length is not 16 characters in iourc file {}".format(self.iourc_path))
user_ioukey = user_ioukey[:16]
# We can't test this because it's mean distributing a valid licence key
@ -1255,10 +1255,10 @@ class IOUVM(BaseVM):
nio.startPacketCapture(output_file, data_link_type)
log.info('IOU "{name}" [{id}]: starting packet capture on {adapter_number}/{port_number} to {output_file}'.format(name=self._name,
id=self._id,
adapter_number=adapter_number,
port_number=port_number,
output_file=output_file))
id=self._id,
adapter_number=adapter_number,
port_number=port_number,
output_file=output_file))
if self.is_iouyap_running():
self._update_iouyap_config()

View File

@ -142,16 +142,14 @@ class PortManager:
if end_port < start_port:
raise HTTPConflict(text="Invalid port range {}-{}".format(start_port, end_port))
last_exception = None
for port in range(start_port, end_port + 1):
if port in ignore_ports:
continue
last_exception
try:
PortManager._check_port(host, port, socket_type)
return port
PortManager._check_port(host, port, socket_type)
return port
except OSError as e:
last_exception = e
if port + 1 == end_port:
@ -163,6 +161,7 @@ class PortManager:
end_port,
host,
last_exception))
@staticmethod
def _check_port(host, port, socket_type):
"""
@ -182,7 +181,6 @@ class PortManager:
s.bind(sa) # the port is available if bind is a success
return True
def get_free_tcp_port(self, project, port_range_start=None, port_range_end=None):
"""
Get an available TCP port and reserve it
@ -291,7 +289,7 @@ class PortManager:
"""
if port in self._used_udp_ports:
raise HTTPConflict(text="UDP port {} already in use on host".format(port, self._console_host))
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)

View File

@ -1084,24 +1084,24 @@ class QemuVM(BaseVM):
raise QemuError("Sorry, adding a link to a started Qemu VM is not supported.")
# FIXME: does the code below work? very undocumented feature...
# dynamically configure an UDP tunnel on the QEMU VM adapter
if nio and isinstance(nio, NIOUDP):
if self._legacy_networking:
yield from self._control_vm("host_net_remove {} gns3-{}".format(adapter_number, adapter_number))
yield from self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
adapter_number,
nio.lport,
nio.rport,
nio.rhost))
else:
# Apparently there is a bug in Qemu...
# netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add host network device
# netdev_del id -- remove host network device
yield from self._control_vm("netdev_del gns3-{}".format(adapter_number))
yield from self._control_vm("netdev_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
nio.rhost,
nio.rport,
self._host,
nio.lport))
# if nio and isinstance(nio, NIOUDP):
# if self._legacy_networking:
# yield from self._control_vm("host_net_remove {} gns3-{}".format(adapter_number, adapter_number))
# yield from self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
# adapter_number,
# nio.lport,
# nio.rport,
# nio.rhost))
# else:
# # Apparently there is a bug in Qemu...
# # netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add host network device
# # netdev_del id -- remove host network device
# yield from self._control_vm("netdev_del gns3-{}".format(adapter_number))
# yield from self._control_vm("netdev_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
# nio.rhost,
# nio.rport,
# self._host,
# nio.lport))
adapter.add_nio(0, nio)
log.info('QEMU VM "{name}" [{id}]: {nio} added to adapter {adapter_number}'.format(name=self._name,

View File

@ -61,20 +61,20 @@ class Query:
body = json.dumps(body)
@asyncio.coroutine
def go(future):
def go_request(future):
response = yield from aiohttp.request(method, self.get_url(path, api_version), data=body)
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future))
asyncio.async(go_request(future))
self._loop.run_until_complete(future)
response = future.result()
@asyncio.coroutine
def go(future, response):
def go_read(future, response):
response = yield from response.read()
future.set_result(response)
future = asyncio.Future()
asyncio.async(go(future, response))
asyncio.async(go_read(future, response))
self._loop.run_until_complete(future)
response.body = future.result()
x_route = response.headers.get('X-Route', None)

View File

@ -42,7 +42,7 @@ def test_reserve_tcp_port_outside_range():
assert mock_emit.call_args[0][0] == "log.warning"
def test_reserve_tcp_port_already_used():
def test_reserve_tcp_port_already_used_by_another_program():
"""
This test simulate a scenario where the port is already taken
by another programm on the server
@ -65,6 +65,7 @@ def test_reserve_tcp_port_already_used():
assert port != 2001
assert mock_emit.call_args[0][0] == "log.warning"
def test_reserve_tcp_port_already_used():
"""
This test simulate a scenario where the port is already taken