diff --git a/gns3server/builtins/server_version.py b/gns3server/builtins/server_version.py index b637bbf3..aaf294fb 100644 --- a/gns3server/builtins/server_version.py +++ b/gns3server/builtins/server_version.py @@ -23,6 +23,7 @@ Sends version to requesting clients in JSON-RPC Websocket handler. from ..version import __version__ from ..jsonrpc import JSONRPCResponse + def server_version(handler, request_id, params): """ Builtin destination to return the server version. diff --git a/gns3server/handlers/file_upload_handler.py b/gns3server/handlers/file_upload_handler.py index d73f12d6..93e9158c 100644 --- a/gns3server/handlers/file_upload_handler.py +++ b/gns3server/handlers/file_upload_handler.py @@ -38,15 +38,14 @@ class FileUploadHandler(tornado.web.RequestHandler): :param request: Tornado Request instance """ - def __init__(self, application, request): + def __init__(self, application, request, **kwargs): - # get the upload directory from the configuration file + super().__init__(application, request, **kwargs) config = Config.instance() server_config = config.get_default_section() - # default projects directory is "~/Documents/GNS3/images" - self._upload_dir = os.path.expandvars(os.path.expanduser(server_config.get("upload_directory", "~/Documents/GNS3/images"))) + self._upload_dir = os.path.expandvars( + os.path.expanduser(server_config.get("upload_directory", "~/Documents/GNS3/images"))) self._host = request.host - try: os.makedirs(self._upload_dir) log.info("upload directory '{}' created".format(self._upload_dir)) @@ -55,8 +54,6 @@ class FileUploadHandler(tornado.web.RequestHandler): except OSError as e: log.error("could not create the upload directory {}: {}".format(self._upload_dir, e)) - tornado.websocket.WebSocketHandler.__init__(self, application, request) - def get(self): """ Invoked on GET request. diff --git a/gns3server/handlers/jsonrpc_websocket.py b/gns3server/handlers/jsonrpc_websocket.py index f09d0040..fdab3cad 100644 --- a/gns3server/handlers/jsonrpc_websocket.py +++ b/gns3server/handlers/jsonrpc_websocket.py @@ -106,8 +106,7 @@ class JSONRPCWebSocket(tornado.websocket.WebSocketHandler): if destination.startswith("builtin"): log.debug("registering {} as a built-in destination".format(destination)) else: - log.debug("registering {} as a destination for the {} module".format(destination, - module)) + log.debug("registering {} as a destination for the {} module".format(destination, module)) cls.destinations[destination] = module def open(self): diff --git a/gns3server/jsonrpc.py b/gns3server/jsonrpc.py index ce9813b8..c4251aad 100644 --- a/gns3server/jsonrpc.py +++ b/gns3server/jsonrpc.py @@ -161,7 +161,7 @@ class JSONRPCRequest(JSONRPCObject): def __init__(self, method, params=None, request_id=None): JSONRPCObject.__init__(self) - if request_id == None: + if request_id is None: request_id = str(uuid.uuid4()) self.id = request_id self.method = method diff --git a/gns3server/module_manager.py b/gns3server/module_manager.py index cf3814be..878f0852 100644 --- a/gns3server/module_manager.py +++ b/gns3server/module_manager.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import imp import inspect import pkgutil from .modules import IModule diff --git a/gns3server/modules/attic.py b/gns3server/modules/attic.py index d0ebf1ed..8b4a0714 100644 --- a/gns3server/modules/attic.py +++ b/gns3server/modules/attic.py @@ -96,7 +96,7 @@ def wait_socket_is_ready(host, port, wait=2.0, socket_timeout=10): connection_success = False begin = time.time() last_exception = None - while (time.time() - begin < wait): + while time.time() - begin < wait: time.sleep(0.01) try: with socket.create_connection((host, port), socket_timeout): @@ -107,16 +107,15 @@ def wait_socket_is_ready(host, port, wait=2.0, socket_timeout=10): connection_success = True break - return (connection_success, last_exception) + return connection_success, last_exception -def has_privileged_access(executable, device): +def has_privileged_access(executable): """ Check if an executable can access Ethernet and TAP devices in RAW mode. :param executable: executable path - :param device: device name :returns: True or False """ diff --git a/gns3server/modules/base.py b/gns3server/modules/base.py index f9c19ca0..620737c0 100644 --- a/gns3server/modules/base.py +++ b/gns3server/modules/base.py @@ -288,7 +288,7 @@ class IModule(multiprocessing.Process): """ # check if we have a request - if request == None: + if request is None: self.send_param_error() return False log.debug("received request {}".format(request)) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 74192881..3e278c25 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -27,7 +27,6 @@ import shutil import glob import socket from gns3server.modules import IModule -import gns3server.jsonrpc as jsonrpc from .hypervisor import Hypervisor from .hypervisor_manager import HypervisorManager @@ -249,8 +248,8 @@ class Dynamips(IModule): if not os.access(self._dynamips, os.X_OK): raise DynamipsError("Dynamips {} is not executable".format(self._dynamips)) + workdir = os.path.join(self._working_dir, "dynamips") try: - workdir = os.path.join(self._working_dir, "dynamips") os.makedirs(workdir) except FileExistsError: pass @@ -282,7 +281,7 @@ class Dynamips(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() return @@ -342,7 +341,7 @@ class Dynamips(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() else: log.debug("received request {}".format(request)) @@ -415,7 +414,6 @@ class Dynamips(IModule): port, host)) response = {"lport": port} - return response def set_ghost_ios(self, router): @@ -498,7 +496,7 @@ class Dynamips(IModule): """ log.info("creating config file {} from base64".format(destination_config_path)) - config = base64.decodestring(config_base64.encode("utf-8")).decode("utf-8") + config = base64.decodebytes(config_base64.encode("utf-8")).decode("utf-8") config = "!\n" + config.replace("\r", "") config = config.replace('%h', router.name) config_dir = os.path.dirname(destination_config_path) diff --git a/gns3server/modules/dynamips/adapters/adapter.py b/gns3server/modules/dynamips/adapters/adapter.py index b963e334..d963933e 100644 --- a/gns3server/modules/dynamips/adapters/adapter.py +++ b/gns3server/modules/dynamips/adapters/adapter.py @@ -63,7 +63,7 @@ class Adapter(object): False otherwise. """ - if self._wics[wic_slot_id] == None: + if self._wics[wic_slot_id] is None: return True return False diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 0a53b64b..0770ff63 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -61,7 +61,7 @@ class DynamipsHypervisor(object): self._udp_end_port_range = 20000 self._nio_udp_auto_instances = {} self._version = "N/A" - self._timeout = 30 + self._timeout = timeout self._socket = None self._uuid = None @@ -80,9 +80,7 @@ class DynamipsHypervisor(object): host = self._host try: - self._socket = socket.create_connection((host, - self._port), - self._timeout) + self._socket = socket.create_connection((host, self._port), self._timeout) except OSError as e: raise DynamipsError("Could not connect to server: {}".format(e)) @@ -477,7 +475,7 @@ class DynamipsHypervisor(object): self.socket.sendall(command.encode('utf-8')) except OSError as e: raise DynamipsError("Lost communication with {host}:{port} :{error}" - .format(host=self._host, port=self._port, error=e)) + .format(host=self._host, port=self._port, error=e)) # Now retrieve the result data = [] @@ -488,7 +486,7 @@ class DynamipsHypervisor(object): buf += chunk.decode("utf-8") except OSError as e: raise DynamipsError("Communication timed out with {host}:{port} :{error}" - .format(host=self._host, port=self._port, error=e)) + .format(host=self._host, port=self._port, error=e)) # If the buffer doesn't end in '\n' then we can't be done try: diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index 911874e0..e1cc2e29 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -70,7 +70,7 @@ class Hypervisor(DynamipsHypervisor): :returns: id (integer) """ - return(self._id) + return self._id @property def started(self): @@ -90,7 +90,7 @@ class Hypervisor(DynamipsHypervisor): :returns: path to Dynamips """ - return(self._path) + return self._path @path.setter def path(self, path): @@ -110,7 +110,7 @@ class Hypervisor(DynamipsHypervisor): :returns: port number (integer) """ - return(self._port) + return self._port @port.setter def port(self, port): @@ -130,7 +130,7 @@ class Hypervisor(DynamipsHypervisor): :returns: host/address (string) """ - return(self._host) + return self._host @host.setter def host(self, host): @@ -232,7 +232,7 @@ class Hypervisor(DynamipsHypervisor): self._process.wait(1) except subprocess.TimeoutExpired: self._process.kill() - if self._process.poll() == None: + if self._process.poll() is None: log.warn("Dynamips process {} is still running".format(self._process.pid)) if self._stdout_file and os.access(self._stdout_file, os.W_OK): @@ -264,7 +264,7 @@ class Hypervisor(DynamipsHypervisor): :returns: True or False """ - if self._process and self._process.poll() == None: + if self._process and self._process.poll() is None: return True return False diff --git a/gns3server/modules/dynamips/hypervisor_manager.py b/gns3server/modules/dynamips/hypervisor_manager.py index 4a65b2f4..7c8153c4 100644 --- a/gns3server/modules/dynamips/hypervisor_manager.py +++ b/gns3server/modules/dynamips/hypervisor_manager.py @@ -39,10 +39,6 @@ class HypervisorManager(object): :param path: path to the Dynamips executable :param working_dir: path to a working directory :param host: host/address for hypervisors to listen to - :param base_port: base TCP port for hypervisors - :param base_console: base TCP port for consoles - :param base_aux: base TCP port for auxiliary consoles - :param base_udp: base UDP port for UDP tunnels """ def __init__(self, path, working_dir, host='127.0.0.1'): @@ -504,13 +500,12 @@ class HypervisorManager(object): else: log.info("allocating an hypervisor per IOS image disabled") - def wait_for_hypervisor(self, host, port, timeout=10): + def wait_for_hypervisor(self, host, port): """ Waits for an hypervisor to be started (accepting a socket connection) :param host: host/address to connect to the hypervisor :param port: port to connect to the hypervisor - :param timeout: timeout value (default is 10 seconds) """ begin = time.time() diff --git a/gns3server/modules/dynamips/nios/nio.py b/gns3server/modules/dynamips/nios/nio.py index f27b7e73..04af1380 100644 --- a/gns3server/modules/dynamips/nios/nio.py +++ b/gns3server/modules/dynamips/nios/nio.py @@ -174,7 +174,7 @@ class NIO(object): :returns: tuple (filter name, filter options) """ - return (self._input_filter, self._input_filter_options) + return self._input_filter, self._input_filter_options @property def output_filter(self): @@ -184,7 +184,7 @@ class NIO(object): :returns: tuple (filter name, filter options) """ - return (self._output_filter, self._output_filter_options) + return self._output_filter, self._output_filter_options def get_stats(self): """ diff --git a/gns3server/modules/dynamips/nodes/bridge.py b/gns3server/modules/dynamips/nodes/bridge.py index 84e7255a..a87ba029 100644 --- a/gns3server/modules/dynamips/nodes/bridge.py +++ b/gns3server/modules/dynamips/nodes/bridge.py @@ -20,8 +20,6 @@ Interface for Dynamips NIO bridge module ("nio_bridge"). http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L538 """ -from ..dynamips_error import DynamipsError - class Bridge(object): """ diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 34321986..7bfe7e52 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -134,7 +134,7 @@ class Router(object): # get the default base MAC address self._mac_addr = self._hypervisor.send("{platform} get_mac_addr {name}".format(platform=self._platform, - name=self._name))[0] + name=self._name))[0] self._hypervisor.devices.append(self) @@ -250,7 +250,6 @@ class Router(object): raise DynamipsError("Could not amend the configuration {}: {}".format(private_config_path, e)) self.set_config(self.startup_config, new_private_config_path) - new_name_no_quotes = new_name new_name = '"' + new_name + '"' # put the new name into quotes to protect spaces self._hypervisor.send("vm rename {name} {new_name}".format(name=self._name, new_name=new_name)) @@ -978,7 +977,7 @@ class Router(object): translated by the JIT (they contain the native code corresponding to MIPS code pages). - :param excec_area: exec area value (integer) + :param exec_area: exec area value (integer) """ self._hypervisor.send("vm set_exec_area {name} {exec_area}".format(name=self._name, @@ -1259,7 +1258,7 @@ class Router(object): :returns: slot bindings (adapter names) list """ - return (self._hypervisor.send("vm slot_bindings {}".format(self._name))) + return self._hypervisor.send("vm slot_bindings {}".format(self._name)) def slot_add_binding(self, slot_id, adapter): """ @@ -1275,16 +1274,16 @@ class Router(object): raise DynamipsError("Slot {slot_id} doesn't exist on router {name}".format(name=self._name, slot_id=slot_id)) - if slot != None: + if slot is not None: current_adapter = slot raise DynamipsError("Slot {slot_id} is already occupied by adapter {adapter} on router {name}".format(name=self._name, slot_id=slot_id, adapter=current_adapter)) # Only c7200, c3600 and c3745 (NM-4T only) support new adapter while running - if self.is_running() and not (self._platform == 'c7200' \ - and not (self._platform == 'c3600' and self.chassis == '3660') \ - and not (self._platform == 'c3745' and adapter == 'NM-4T')): + if self.is_running() and not (self._platform == 'c7200' + and not (self._platform == 'c3600' and self.chassis == '3660') + and not (self._platform == 'c3745' and adapter == 'NM-4T')): raise DynamipsError("Adapter {adapter} cannot be added while router {name} is running".format(adapter=adapter, name=self._name)) @@ -1322,14 +1321,14 @@ class Router(object): raise DynamipsError("Slot {slot_id} doesn't exist on router {name}".format(name=self._name, slot_id=slot_id)) - if adapter == None: + if adapter is None: raise DynamipsError("No adapter in slot {slot_id} on router {name}".format(name=self._name, slot_id=slot_id)) # Only c7200, c3600 and c3745 (NM-4T only) support to remove adapter while running - if self.is_running() and not (self._platform == 'c7200' \ - and not (self._platform == 'c3600' and self.chassis == '3660') \ - and not (self._platform == 'c3745' and adapter == 'NM-4T')): + if self.is_running() and not (self._platform == 'c7200' + and not (self._platform == 'c3600' and self.chassis == '3660') + and not (self._platform == 'c3745' and adapter == 'NM-4T')): raise DynamipsError("Adapter {adapter} cannot be removed while router {name} is running".format(adapter=adapter, name=self._name)) @@ -1415,8 +1414,8 @@ class Router(object): # WIC1 = 16, WIC2 = 32 and WIC3 = 48 internal_wic_slot_id = 16 * (wic_slot_id + 1) self._hypervisor.send("vm slot_remove_binding {name} {slot_id} {wic_slot_id}".format(name=self._name, - slot_id=slot_id, - wic_slot_id=internal_wic_slot_id)) + slot_id=slot_id, + wic_slot_id=internal_wic_slot_id)) log.info("router {name} [id={id}]: {wic} removed from WIC slot {wic_slot_id}".format(name=self._name, id=self._id, diff --git a/gns3server/modules/dynamips/schemas/atmsw.py b/gns3server/modules/dynamips/schemas/atmsw.py index 2041299b..cddea592 100644 --- a/gns3server/modules/dynamips/schemas/atmsw.py +++ b/gns3server/modules/dynamips/schemas/atmsw.py @@ -87,129 +87,129 @@ ATMSW_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/dynamips/schemas/ethhub.py b/gns3server/modules/dynamips/schemas/ethhub.py index 6db1b796..50470bcc 100644 --- a/gns3server/modules/dynamips/schemas/ethhub.py +++ b/gns3server/modules/dynamips/schemas/ethhub.py @@ -87,129 +87,129 @@ ETHHUB_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/dynamips/schemas/ethsw.py b/gns3server/modules/dynamips/schemas/ethsw.py index a33a98b8..92f47b80 100644 --- a/gns3server/modules/dynamips/schemas/ethsw.py +++ b/gns3server/modules/dynamips/schemas/ethsw.py @@ -102,129 +102,129 @@ ETHSW_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { @@ -269,7 +269,7 @@ ETHSW_ADD_NIO_SCHEMA = { "dependencies": { "port_type": ["vlan"], "vlan": ["port_type"] - } + } } ETHSW_DELETE_NIO_SCHEMA = { diff --git a/gns3server/modules/dynamips/schemas/frsw.py b/gns3server/modules/dynamips/schemas/frsw.py index 5dd5e5bb..b5b6ebdb 100644 --- a/gns3server/modules/dynamips/schemas/frsw.py +++ b/gns3server/modules/dynamips/schemas/frsw.py @@ -87,129 +87,129 @@ FRSW_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/dynamips/schemas/vm.py b/gns3server/modules/dynamips/schemas/vm.py index 47bcb75b..3a7d9af5 100644 --- a/gns3server/modules/dynamips/schemas/vm.py +++ b/gns3server/modules/dynamips/schemas/vm.py @@ -424,129 +424,129 @@ VM_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index aa7a7dbf..86a51d60 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -20,17 +20,13 @@ IOU server module. """ import os -import sys import base64 import tempfile -import fcntl -import struct import socket import shutil from gns3server.modules import IModule from gns3server.config import Config -import gns3server.jsonrpc as jsonrpc from .iou_device import IOUDevice from .iou_error import IOUError from .nios.nio_udp import NIO_UDP @@ -215,12 +211,12 @@ class IOU(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() return if "iourc" in request: - iourc_content = base64.decodestring(request["iourc"].encode("utf-8")).decode("utf-8") + iourc_content = base64.decodebytes(request["iourc"].encode("utf-8")).decode("utf-8") iourc_content = iourc_content.replace("\r\n", "\n") # dos2unix try: with tempfile.NamedTemporaryFile(mode="w", delete=False) as f: @@ -228,7 +224,7 @@ class IOU(IModule): f.write(iourc_content) self._iourc = f.name except OSError as e: - raise IOUError("Could not save iourc file to {}: {}".format(f.name, e)) + raise IOUError("Could not create the iourc file: {}".format(e)) if "iouyap" in request and request["iouyap"]: self._iouyap = request["iouyap"] @@ -410,7 +406,7 @@ class IOU(IModule): try: if "startup_config_base64" in request: # a new startup-config has been pushed - config = base64.decodestring(request["startup_config_base64"].encode("utf-8")).decode("utf-8") + config = base64.decodebytes(request["startup_config_base64"].encode("utf-8")).decode("utf-8") config = "!\n" + config.replace("\r", "") config = config.replace('%h', iou_instance.name) try: @@ -587,8 +583,8 @@ class IOU(IModule): iou_instance.id, port, self._host)) - response = {"lport": port} - response["port_id"] = request["port_id"] + response = {"lport": port, + "port_id": request["port_id"]} self.send_response(response) @IModule.route("iou.add_nio") @@ -643,12 +639,12 @@ class IOU(IModule): nio = NIO_UDP(lport, rhost, rport) elif request["nio"]["type"] == "nio_tap": tap_device = request["nio"]["tap_device"] - if not has_privileged_access(self._iouyap, tap_device): + if not has_privileged_access(self._iouyap): raise IOUError("{} has no privileged access to {}.".format(self._iouyap, tap_device)) nio = NIO_TAP(tap_device) elif request["nio"]["type"] == "nio_generic_ethernet": ethernet_device = request["nio"]["ethernet_device"] - if not has_privileged_access(self._iouyap, ethernet_device): + if not has_privileged_access(self._iouyap): raise IOUError("{} has no privileged access to {}.".format(self._iouyap, ethernet_device)) nio = NIO_GenericEthernet(ethernet_device) if not nio: @@ -710,7 +706,7 @@ class IOU(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() else: log.debug("received request {}".format(request)) diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 4c3aee38..8233240a 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -83,7 +83,7 @@ class IOUDevice(object): self._iourc = "" self._iouyap = "" self._console = console - self._working_dir = None + self._working_dir = working_dir self._command = [] self._process = None self._iouyap_process = None @@ -154,7 +154,7 @@ class IOUDevice(object): :returns: id (integer) """ - return(self._id) + return self._id @classmethod def reset(cls): @@ -185,7 +185,7 @@ class IOUDevice(object): if self._startup_config: # update the startup-config - config_path = os.path.join(self.working_dir, "startup-config") + config_path = os.path.join(self._working_dir, "startup-config") if os.path.isfile(config_path): try: with open(config_path, "r+") as f: @@ -209,7 +209,7 @@ class IOUDevice(object): :returns: path to IOU """ - return(self._path) + return self._path @path.setter def path(self, path): @@ -221,8 +221,8 @@ class IOUDevice(object): self._path = path log.info("IOU {name} [id={id}]: path changed to {path}".format(name=self._name, - id=self._id, - path=path)) + id=self._id, + path=path)) @property def iourc(self): @@ -232,14 +232,14 @@ class IOUDevice(object): :returns: path to the iourc file """ - return(self._iourc) + return self._iourc @iourc.setter def iourc(self, iourc): """ Sets the path to the iourc file. - :param path: path to the iourc file. + :param iourc: path to the iourc file. """ self._iourc = iourc @@ -255,14 +255,14 @@ class IOUDevice(object): :returns: path to iouyap """ - return(self._iouyap) + return self._iouyap @iouyap.setter def iouyap(self, iouyap): """ Sets the path to iouyap. - :param path: path to iouyap + :param iouyap: path to iouyap """ self._iouyap = iouyap @@ -299,8 +299,8 @@ class IOUDevice(object): self._working_dir = working_dir log.info("IOU {name} [id={id}]: working directory changed to {wd}".format(name=self._name, - id=self._id, - wd=self._working_dir)) + id=self._id, + wd=self._working_dir)) @property def console(self): @@ -327,8 +327,8 @@ class IOUDevice(object): self._console = console self._allocated_console_ports.append(self._console) log.info("IOU {name} [id={id}]: console port set to {port}".format(name=self._name, - id=self._id, - port=console)) + id=self._id, + port=console)) def command(self): """ @@ -368,8 +368,8 @@ class IOUDevice(object): shutil.rmtree(self._working_dir) except OSError as e: log.error("could not delete IOU device {name} [id={id}]: {error}".format(name=self._name, - id=self._id, - error=e)) + id=self._id, + error=e)) return log.info("IOU device {name} [id={id}] has been deleted (including associated files)".format(name=self._name, @@ -402,6 +402,7 @@ class IOUDevice(object): for unit in adapter.ports.keys(): nio = adapter.get_nio(unit) if nio: + connection = None if isinstance(nio, NIO_UDP): # UDP tunnel connection = {"tunnel_udp": "{lport}:{rhost}:{rport}".format(lport=nio.lport, @@ -415,7 +416,8 @@ class IOUDevice(object): # Ethernet interface connection = {"eth_dev": "{ethernet_device}".format(ethernet_device=nio.ethernet_device)} - config["{iouyap_id}:{bay}/{unit}".format(iouyap_id=str(self._id + 512), bay=bay_id, unit=unit_id)] = connection + if connection: + config["{iouyap_id}:{bay}/{unit}".format(iouyap_id=str(self._id + 512), bay=bay_id, unit=unit_id)] = connection unit_id += 1 bay_id += 1 @@ -581,7 +583,7 @@ class IOUDevice(object): self._iouyap_process.wait(1) except subprocess.TimeoutExpired: self._iouyap_process.kill() - if self._iouyap_process.poll() == None: + if self._iouyap_process.poll() is None: log.warn("iouyap PID={} for IOU instance {} is still running".format(self._iouyap_process.pid, self._id)) self._iouyap_process = None @@ -594,7 +596,7 @@ class IOUDevice(object): self._process.wait(1) except subprocess.TimeoutExpired: self._process.kill() - if self._process.poll() == None: + if self._process.poll() is None: log.warn("IOU instance {} PID={} is still running".format(self._id, self._process.pid)) self._process = None @@ -637,7 +639,7 @@ class IOUDevice(object): :returns: True or False """ - if self._process and self._process.poll() == None: + if self._process and self._process.poll() is None: return True return False @@ -648,7 +650,7 @@ class IOUDevice(object): :returns: True or False """ - if self._iouyap_process and self._iouyap_process.poll() == None: + if self._iouyap_process and self._iouyap_process.poll() is None: return True return False @@ -723,16 +725,14 @@ class IOUDevice(object): env = os.environ.copy() env["IOURC"] = self._iourc - output = b"" try: output = subprocess.check_output([self._path, "-h"], stderr=subprocess.STDOUT, cwd=self._working_dir, env=env) - except OSError as e: - log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) - else: if re.search("-l\s+Enable Layer 1 keepalive messages", output.decode("utf-8")): command.extend(["-l"]) else: raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path))) + except OSError as e: + log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e)) def _build_command(self): """ @@ -904,8 +904,8 @@ class IOUDevice(object): self._startup_config = startup_config log.info("IOU {name} [id={id}]: startup_config set to {config}".format(name=self._name, - id=self._id, - config=self._startup_config)) + id=self._id, + config=self._startup_config)) @property def ethernet_adapters(self): diff --git a/gns3server/modules/iou/ioucon.py b/gns3server/modules/iou/ioucon.py index 7578c0a3..c3d04636 100644 --- a/gns3server/modules/iou/ioucon.py +++ b/gns3server/modules/iou/ioucon.py @@ -56,32 +56,32 @@ EXIT_ABORT = 2 # Mostly from: # https://code.google.com/p/miniboa/source/browse/trunk/miniboa/telnet.py #--[ Telnet Commands ]--------------------------------------------------------- -SE = 240 # End of subnegotiation parameters -NOP = 241 # No operation -DATMK = 242 # Data stream portion of a sync. -BREAK = 243 # NVT Character BRK -IP = 244 # Interrupt Process -AO = 245 # Abort Output -AYT = 246 # Are you there -EC = 247 # Erase Character -EL = 248 # Erase Line -GA = 249 # The Go Ahead Signal -SB = 250 # Sub-option to follow -WILL = 251 # Will; request or confirm option begin -WONT = 252 # Wont; deny option request -DO = 253 # Do = Request or confirm remote option -DONT = 254 # Don't = Demand or confirm option halt -IAC = 255 # Interpret as Command -SEND = 1 # Sub-process negotiation SEND command -IS = 0 # Sub-process negotiation IS command +SE = 240 # End of sub-negotiation parameters +NOP = 241 # No operation +DATMK = 242 # Data stream portion of a sync. +BREAK = 243 # NVT Character BRK +IP = 244 # Interrupt Process +AO = 245 # Abort Output +AYT = 246 # Are you there +EC = 247 # Erase Character +EL = 248 # Erase Line +GA = 249 # The Go Ahead Signal +SB = 250 # Sub-option to follow +WILL = 251 # Will; request or confirm option begin +WONT = 252 # Wont; deny option request +DO = 253 # Do = Request or confirm remote option +DONT = 254 # Don't = Demand or confirm option halt +IAC = 255 # Interpret as Command +SEND = 1 # Sub-process negotiation SEND command +IS = 0 # Sub-process negotiation IS command #--[ Telnet Options ]---------------------------------------------------------- BINARY = 0 # Transmit Binary -ECHO = 1 # Echo characters back to sender -RECON = 2 # Reconnection -SGA = 3 # Suppress Go-Ahead -TMARK = 6 # Timing Mark -TTYPE = 24 # Terminal Type -NAWS = 31 # Negotiate About Window Size +ECHO = 1 # Echo characters back to sender +RECON = 2 # Reconnection +SGA = 3 # Suppress Go-Ahead +TMARK = 6 # Timing Mark +TTYPE = 24 # Terminal Type +NAWS = 31 # Negotiate About Window Size LINEMO = 34 # Line Mode @@ -299,9 +299,7 @@ class TelnetServer(Console): buf.extend(self._read_block(1)) iac_cmd.append(buf[iac_loc + 2]) # We do ECHO, SGA, and BINARY. Period. - if (iac_cmd[1] == DO - and iac_cmd[2] not in [ECHO, SGA, BINARY]): - + if iac_cmd[1] == DO and iac_cmd[2] not in [ECHO, SGA, BINARY]: self._write_cur(bytes([IAC, WONT, iac_cmd[2]])) log.debug("Telnet WON'T {:#x}".format(iac_cmd[2])) else: @@ -326,7 +324,7 @@ class TelnetServer(Console): fd.send(bytes([IAC, WILL, ECHO, IAC, WILL, SGA, IAC, WILL, BINARY, - IAC, DO, BINARY])) + IAC, DO, BINARY])) if args.telnet_limit and len(self.fd_dict) > args.telnet_limit: fd.send(b'\r\nToo many connections\r\n') @@ -601,7 +599,7 @@ def start_ioucon(cmdline_args, stop_event): nport = int(port) except ValueError: pass - if (addr == '' or nport == 0): + if addr == '' or nport == 0: raise ConfigError('format for --telnet-server must be ' 'ADDR:PORT (like 127.0.0.1:20000)') diff --git a/gns3server/modules/iou/schemas.py b/gns3server/modules/iou/schemas.py index 35520659..1d7ed554 100644 --- a/gns3server/modules/iou/schemas.py +++ b/gns3server/modules/iou/schemas.py @@ -189,129 +189,129 @@ IOU_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 291aadee..9c566ea1 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -20,16 +20,12 @@ VPCS server module. """ import os -import sys import base64 -import tempfile -import struct import socket import shutil from gns3server.modules import IModule from gns3server.config import Config -import gns3server.jsonrpc as jsonrpc from .vpcs_device import VPCSDevice from .vpcs_error import VPCSError from .nios.nio_udp import NIO_UDP @@ -101,7 +97,6 @@ class VPCS(IModule): :param signum: signal number (if called by the signal handler) """ - # self._vpcs_callback.stop() # delete all VPCS instances for vpcs_id in self._vpcs_instances: vpcs_instance = self._vpcs_instances[vpcs_id] @@ -162,7 +157,7 @@ class VPCS(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() return @@ -326,7 +321,7 @@ class VPCS(IModule): try: if "script_file_base64" in request: # a new startup-config has been pushed - config = base64.decodestring(request["script_file_base64"].encode("utf-8")).decode("utf-8") + config = base64.decodebytes(request["script_file_base64"].encode("utf-8")).decode("utf-8") config = config.replace("\r", "") config = config.replace('%h', vpcs_instance.name) try: @@ -502,8 +497,8 @@ class VPCS(IModule): port, self._host)) - response = {"lport": port} - response["port_id"] = request["port_id"] + response = {"lport": port, + "port_id": request["port_id"]} self.send_response(response) @IModule.route("vpcs.add_nio") @@ -554,7 +549,7 @@ class VPCS(IModule): nio = NIO_UDP(lport, rhost, rport) elif request["nio"]["type"] == "nio_tap": tap_device = request["nio"]["tap_device"] - if not self.has_privileged_access(self._vpcs, tap_device): + if not self.has_privileged_access(self._vpcs): raise VPCSError("{} has no privileged access to {}.".format(self._vpcs, tap_device)) nio = NIO_TAP(tap_device) if not nio: @@ -614,7 +609,7 @@ class VPCS(IModule): :param request: JSON request """ - if request == None: + if request is None: self.send_param_error() else: log.debug("received request {}".format(request)) diff --git a/gns3server/modules/vpcs/schemas.py b/gns3server/modules/vpcs/schemas.py index 868f9b31..7258bda2 100644 --- a/gns3server/modules/vpcs/schemas.py +++ b/gns3server/modules/vpcs/schemas.py @@ -151,129 +151,129 @@ VPCS_ADD_NIO_SCHEMA = { "type": "object", "definitions": { - "UDP": { - "description": "UDP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_udp"] - }, - "lport": { - "description": "Local port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - "rhost": { - "description": "Remote host", - "type": "string", - "minLength": 1 - }, - "rport": { - "description": "Remote port", - "type": "integer", - "minimum": 1, - "maximum": 65535 - } - }, - "required": ["type", "lport", "rhost", "rport"], - "additionalProperties": False + "UDP": { + "description": "UDP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_udp"] + }, + "lport": { + "description": "Local port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "rhost": { + "description": "Remote host", + "type": "string", + "minLength": 1 + }, + "rport": { + "description": "Remote port", + "type": "integer", + "minimum": 1, + "maximum": 65535 + } }, - "Ethernet": { - "description": "Generic Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_generic_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "lport", "rhost", "rport"], + "additionalProperties": False + }, + "Ethernet": { + "description": "Generic Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_generic_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "LinuxEthernet": { - "description": "Linux Ethernet Network Input/Output", - "properties": { - "type": { - "enum": ["nio_linux_ethernet"] - }, - "ethernet_device": { - "description": "Ethernet device name e.g. eth0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "ethernet_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "LinuxEthernet": { + "description": "Linux Ethernet Network Input/Output", + "properties": { + "type": { + "enum": ["nio_linux_ethernet"] + }, + "ethernet_device": { + "description": "Ethernet device name e.g. eth0", + "type": "string", + "minLength": 1 + }, }, - "TAP": { - "description": "TAP Network Input/Output", - "properties": { - "type": { - "enum": ["nio_tap"] - }, - "tap_device": { - "description": "TAP device name e.g. tap0", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "tap_device"], - "additionalProperties": False + "required": ["type", "ethernet_device"], + "additionalProperties": False + }, + "TAP": { + "description": "TAP Network Input/Output", + "properties": { + "type": { + "enum": ["nio_tap"] + }, + "tap_device": { + "description": "TAP device name e.g. tap0", + "type": "string", + "minLength": 1 + }, }, - "UNIX": { - "description": "UNIX Network Input/Output", - "properties": { - "type": { - "enum": ["nio_unix"] - }, - "local_file": { - "description": "path to the UNIX socket file (local)", - "type": "string", - "minLength": 1 - }, - "remote_file": { - "description": "path to the UNIX socket file (remote)", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "local_file", "remote_file"], - "additionalProperties": False + "required": ["type", "tap_device"], + "additionalProperties": False + }, + "UNIX": { + "description": "UNIX Network Input/Output", + "properties": { + "type": { + "enum": ["nio_unix"] + }, + "local_file": { + "description": "path to the UNIX socket file (local)", + "type": "string", + "minLength": 1 + }, + "remote_file": { + "description": "path to the UNIX socket file (remote)", + "type": "string", + "minLength": 1 + }, }, - "VDE": { - "description": "VDE Network Input/Output", - "properties": { - "type": { - "enum": ["nio_vde"] - }, - "control_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - "local_file": { - "description": "path to the VDE control file", - "type": "string", - "minLength": 1 - }, - }, - "required": ["type", "control_file", "local_file"], - "additionalProperties": False + "required": ["type", "local_file", "remote_file"], + "additionalProperties": False + }, + "VDE": { + "description": "VDE Network Input/Output", + "properties": { + "type": { + "enum": ["nio_vde"] + }, + "control_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, + "local_file": { + "description": "path to the VDE control file", + "type": "string", + "minLength": 1 + }, }, - "NULL": { - "description": "NULL Network Input/Output", - "properties": { - "type": { - "enum": ["nio_null"] - }, - }, - "required": ["type"], - "additionalProperties": False + "required": ["type", "control_file", "local_file"], + "additionalProperties": False + }, + "NULL": { + "description": "NULL Network Input/Output", + "properties": { + "type": { + "enum": ["nio_null"] + }, }, + "required": ["type"], + "additionalProperties": False }, + }, "properties": { "id": { diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index f3fbf3e3..eb639954 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -81,7 +81,8 @@ class VPCSDevice(object): self._path = path self._console = console - self._working_dir = None + self._working_dir = working_dir + self._host = host self._command = [] self._process = None self._vpcs_stdout_file = "" @@ -135,7 +136,7 @@ class VPCSDevice(object): :returns: id (integer) """ - return(self._id) + return self._id @classmethod def reset(cls): @@ -166,7 +167,7 @@ class VPCSDevice(object): if self._script_file: # update the startup.vpc - config_path = os.path.join(self.working_dir, "startup.vpc") + config_path = os.path.join(self._working_dir, "startup.vpc") if os.path.isfile(config_path): try: with open(config_path, "r+") as f: @@ -178,8 +179,8 @@ class VPCSDevice(object): raise VPCSError("Could not amend the configuration {}: {}".format(config_path, e)) log.info("VPCS {name} [id={id}]: renamed to {new_name}".format(name=self._name, - id=self._id, - new_name=new_name)) + id=self._id, + new_name=new_name)) self._name = new_name @property @@ -190,7 +191,7 @@ class VPCSDevice(object): :returns: path to VPCS """ - return(self._path) + return self._path @path.setter def path(self, path): @@ -202,8 +203,8 @@ class VPCSDevice(object): self._path = path log.info("VPCS {name} [id={id}]: path changed to {path}".format(name=self._name, - id=self._id, - path=path)) + id=self._id, + path=path)) @property def working_dir(self): @@ -234,8 +235,8 @@ class VPCSDevice(object): self._working_dir = working_dir log.info("VPCS {name} [id={id}]: working directory changed to {wd}".format(name=self._name, - id=self._id, - wd=self._working_dir)) + id=self._id, + wd=self._working_dir)) @property def console(self): @@ -262,8 +263,8 @@ class VPCSDevice(object): self._console = console self._allocated_console_ports.append(self._console) log.info("VPCS {name} [id={id}]: console port set to {port}".format(name=self._name, - id=self._id, - port=console)) + id=self._id, + port=console)) def command(self): """ @@ -286,7 +287,7 @@ class VPCSDevice(object): self._allocated_console_ports.remove(self.console) log.info("VPCS device {name} [id={id}] has been deleted".format(name=self._name, - id=self._id)) + id=self._id)) def clean_delete(self): """ @@ -331,10 +332,10 @@ class VPCSDevice(object): raise VPCSError("No path to a VPCS executable has been set") if not os.path.isfile(self._path): - raise VPCSError("VPCS '{}' is not accessible".format(self._path)) + raise VPCSError("VPCS program '{}' is not accessible".format(self._path)) if not os.access(self._path, os.X_OK): - raise VPCSError("VPCS '{}' is not executable".format(self._path)) + raise VPCSError("VPCS program '{}' is not executable".format(self._path)) if not self._ethernet_adapter.get_nio(0): raise VPCSError("This VPCS instance must be connected in order to start") @@ -400,7 +401,7 @@ class VPCSDevice(object): :returns: True or False """ - if self._process and self._process.poll() == None: + if self._process and self._process.poll() is None: return True return False @@ -414,7 +415,7 @@ class VPCSDevice(object): if not self._ethernet_adapter.port_exists(port_id): raise VPCSError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter, - port_id=port_id)) + port_id=port_id)) self._ethernet_adapter.add_nio(port_id, nio) log.info("VPCS {name} [id={id}]: {nio} added to port {port_id}".format(name=self._name, @@ -517,7 +518,7 @@ class VPCSDevice(object): """ Sets the script-file for this VPCS instance. - :param base_script_file: path to base-script-file + :param script_file: path to base-script-file """ self._script_file = script_file diff --git a/requirements.txt b/requirements.txt index 6fb17eea..ae4f8b0a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +netifaces tornado pyzmq netifaces-py3 diff --git a/setup.py b/setup.py index ffba880a..9008d47a 100644 --- a/setup.py +++ b/setup.py @@ -48,12 +48,12 @@ setup( "tornado>=3.1", "pyzmq>=14.0.0", "jsonschema==2.3.0" - ], + ], entry_points={ "console_scripts": [ "gns3server = gns3server.main:main", - ] - }, + ] + }, packages=find_packages(), package_data={"gns3server": ["templates/upload.html"]}, include_package_data=True, @@ -71,5 +71,5 @@ setup( "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", - ], + ], ) diff --git a/tests/test_jsonrpc.py b/tests/test_jsonrpc.py index 67bea4a9..155502c5 100644 --- a/tests/test_jsonrpc.py +++ b/tests/test_jsonrpc.py @@ -40,7 +40,7 @@ class JSONRPC(AsyncTestCase): AsyncWSRequest(self.URL, self.io_loop, self.stop, json_encode(request)) response = self.wait() json_response = json_decode(response) - assert json_response["id"] == None + assert json_response["id"] is None assert json_response["error"].get("code") == -32600 def test_request_with_invalid_json(self): @@ -49,7 +49,7 @@ class JSONRPC(AsyncTestCase): AsyncWSRequest(self.URL, self.io_loop, self.stop, request) response = self.wait() json_response = json_decode(response) - assert json_response["id"] == None + assert json_response["id"] is None assert json_response["error"].get("code") == -32700 def test_request_with_invalid_jsonrpc_field(self): @@ -58,7 +58,7 @@ class JSONRPC(AsyncTestCase): AsyncWSRequest(self.URL, self.io_loop, self.stop, json_encode(request)) response = self.wait() json_response = json_decode(response) - assert json_response["id"] == None + assert json_response["id"] is None assert json_response["error"].get("code") == -32700 def test_request_with_no_params(self): diff --git a/tests/test_version_handler.py b/tests/test_version_handler.py index feeef3d3..0c8c75d9 100644 --- a/tests/test_version_handler.py +++ b/tests/test_version_handler.py @@ -34,7 +34,7 @@ class TestVersionHandler(AsyncHTTPTestCase): self.http_client.fetch(self.get_url(self.URL), self.stop) response = self.wait() - assert(response.headers['Content-Type'].startswith('application/json')) - assert(response.body) + assert response.headers['Content-Type'].startswith('application/json') + assert response.body body = json_decode(response.body) assert body['version'] == __version__