From f4dd096a8ba7d326acd823157cff292314096a94 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 2 Apr 2014 16:10:59 -0600 Subject: [PATCH] Rename all EnvironmentError to OSError. Change version number to 1.0a2-dev1. Check only on Python >= 3.3. --- gns3server/handlers/file_upload_handler.py | 2 +- gns3server/main.py | 12 ++++++++---- gns3server/modules/base.py | 8 +++++++- gns3server/modules/dynamips/__init__.py | 6 +++--- gns3server/modules/dynamips/backends/vm.py | 4 ++-- gns3server/modules/dynamips/hypervisor.py | 4 ++-- gns3server/modules/dynamips/hypervisor_manager.py | 2 +- gns3server/modules/iou/__init__.py | 14 +++++++------- gns3server/modules/iou/iou_device.py | 14 +++++++------- gns3server/server.py | 2 +- gns3server/version.py | 2 +- 11 files changed, 40 insertions(+), 30 deletions(-) diff --git a/gns3server/handlers/file_upload_handler.py b/gns3server/handlers/file_upload_handler.py index eb0ceeeb..ab9100e2 100644 --- a/gns3server/handlers/file_upload_handler.py +++ b/gns3server/handlers/file_upload_handler.py @@ -49,7 +49,7 @@ class FileUploadHandler(tornado.web.RequestHandler): try: os.makedirs(self._upload_dir) log.info("upload directory '{}' created".format(self._upload_dir)) - except EnvironmentError as e: + except OSError as e: log.error("could not create the upload directory {}: {}".format(self._upload_dir, e)) tornado.websocket.WebSocketHandler.__init__(self, application, request) diff --git a/gns3server/main.py b/gns3server/main.py index 501c2cd4..55dca9c3 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os import datetime import sys import multiprocessing @@ -44,12 +45,15 @@ def main(): print("GNS3 server version {}".format(__version__)) print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) - # we only support Python 2 version >= 2.7 and Python 3 version >= 3.3 - if sys.version_info < (2, 7): - raise RuntimeError("Python 2.7 or higher is required") - elif sys.version_info[0] == 3 and sys.version_info < (3, 3): + # we only support Python 3 version >= 3.3 + if sys.version_info < (3, 3): raise RuntimeError("Python 3.3 or higher is required") + print("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(major=sys.version_info[0], + minor=sys.version_info[1], + micro=sys.version_info[2], + pid=os.getpid())) + try: tornado.options.parse_command_line() except (tornado.options.Error, ValueError): diff --git a/gns3server/modules/base.py b/gns3server/modules/base.py index 70c45cd9..515e7e9a 100644 --- a/gns3server/modules/base.py +++ b/gns3server/modules/base.py @@ -20,6 +20,7 @@ Base class (interface) for modules """ import sys +import traceback import gns3server.jsonrpc as jsonrpc import multiprocessing import zmq @@ -230,7 +231,12 @@ class IModule(multiprocessing.Process): self.modules[self.name][destination](self, params) except Exception as e: log.error("uncaught exception {type}".format(type=type(e)), exc_info=1) - self.send_custom_error("uncaught exception {type}: {string}".format(type=type(e), string=str(e))) + exc_type, exc_value, exc_tb = sys.exc_info() + lines = traceback.format_exception(exc_type, exc_value, exc_tb) + tb = "\n" . join(lines) + self.send_custom_error("uncaught exception {type}: {string}\n{tb}".format(type=type(e), + string=str(e), + tb=tb)) def destinations(self): """ diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index dc8bdc6c..054a4ac9 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -208,7 +208,7 @@ class Dynamips(IModule): if not os.path.exists(self._working_dir): try: os.makedirs(self._working_dir) - except EnvironmentError as e: + except OSError as e: raise DynamipsError("Could not create working directory {}".format(e)) # check if the working directory is writable @@ -410,14 +410,14 @@ class Dynamips(IModule): if not os.path.exists(config_dir): try: os.makedirs(config_dir) - except EnvironmentError as e: + except OSError as e: raise DynamipsError("Could not create configs directory: {}".format(e)) config_path = os.path.join(config_dir, config_filename) try: with open(config_path, "w") as f: log.info("saving startup-config to {}".format(config_path)) f.write(config) - except EnvironmentError as e: + except OSError as e: raise DynamipsError("Could not save the configuration {}: {}".format(config_path, e)) return "configs" + os.sep + os.path.basename(config_path) diff --git a/gns3server/modules/dynamips/backends/vm.py b/gns3server/modules/dynamips/backends/vm.py index 85c47f9e..84e581d2 100644 --- a/gns3server/modules/dynamips/backends/vm.py +++ b/gns3server/modules/dynamips/backends/vm.py @@ -467,7 +467,7 @@ class VM(object): with open(config_path, "w") as f: log.info("saving startup-config to {}".format(router.startup_config)) f.write(config) - except EnvironmentError as e: + except OSError as e: raise DynamipsError("Could not save the startup configuration {}: {}".format(config_path, e)) if private_config_base64: @@ -478,7 +478,7 @@ class VM(object): with open(config_path, "w") as f: log.info("saving private-config to {}".format(router.private_config)) f.write(config) - except EnvironmentError as e: + except OSError as e: raise DynamipsError("Could not save the private configuration {}: {}".format(config_path, e)) except DynamipsError as e: diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index eaa9acff..19cfe155 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -211,7 +211,7 @@ class Hypervisor(DynamipsHypervisor): cwd=self._working_dir) log.info("Dynamips started PID={}".format(self._process.pid)) self._started = True - except EnvironmentError as e: + except OSError as e: log.error("could not start Dynamips: {}".format(e)) raise DynamipsError("could not start Dynamips: {}".format(e)) @@ -247,7 +247,7 @@ class Hypervisor(DynamipsHypervisor): try: with open(self._stdout_file) as file: output = file.read() - except EnvironmentError as e: + except OSError as e: log.warn("could not read {}: {}".format(self._stdout_file, e)) return output diff --git a/gns3server/modules/dynamips/hypervisor_manager.py b/gns3server/modules/dynamips/hypervisor_manager.py index cc6c4533..d1d3d190 100644 --- a/gns3server/modules/dynamips/hypervisor_manager.py +++ b/gns3server/modules/dynamips/hypervisor_manager.py @@ -456,7 +456,7 @@ class HypervisorManager(object): # if not os.path.exists(working_dir): # try: # os.makedirs(working_dir) -# except EnvironmentError as e: +# except OSError as e: # raise DynamipsError("{}".format(e)) hypervisor = Hypervisor(self._path, diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 49f62864..b5a59fde 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -87,8 +87,8 @@ class IOU(IModule): self._iourc = "" # check every 5 seconds - self._iou_callback = self.add_periodic_callback(self._check_iou_is_alive, 5000) - self._iou_callback.start() + #self._iou_callback = self.add_periodic_callback(self._check_iou_is_alive, 5000) + #self._iou_callback.start() def stop(self): """ @@ -154,7 +154,7 @@ class IOU(IModule): try: log.info("deleting iourc file {}".format(self._iourc)) os.remove(self._iourc) - except EnvironmentError as e: + except OSError as e: log.warn("could not delete iourc file {}: {}".format(self._iourc, e)) log.info("IOU module has been reset") @@ -189,7 +189,7 @@ class IOU(IModule): log.info("saving iourc file content to {}".format(f.name)) f.write(base64iourc) self._iourc = f.name - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not save iourc file to {}: {}".format(f.name, e)) if "iouyap" in request and request["iouyap"]: @@ -244,7 +244,7 @@ class IOU(IModule): if not os.path.exists(self._working_dir): try: os.makedirs(self._working_dir) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not create working directory {}".format(e)) iou_instance = IOUDevice(iou_path, self._working_dir, host=self._default_host, name=name) @@ -333,7 +333,7 @@ class IOU(IModule): with open(config_path, "w") as f: log.info("saving startup-config to {}".format(config_path)) f.write(config) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not save the configuration {}: {}".format(config_path, e)) request["startup_config"] = os.path.basename(config_path) if "startup_config" in request: @@ -544,7 +544,7 @@ class IOU(IModule): IFF_NO_PI = 0x1000 try: tun = os.open("/dev/net/tun", os.O_RDWR) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not open /dev/net/tun: {}".format(e)) ifr = struct.pack("16sH", tap_device.encode("utf-8"), IFF_TAP | IFF_NO_PI) try: diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index f35ea97a..41058901 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -249,7 +249,7 @@ class IOUDevice(object): if not os.path.exists(working_dir): try: os.makedirs(working_dir) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not create working directory {}: {}".format(working_dir, e)) self._working_dir = working_dir @@ -348,7 +348,7 @@ class IOUDevice(object): config.write(config_file) log.info("IOU {name} [id={id}]: iouyap.ini updated".format(name=self._name, id=self._id)) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not create {}: {}".format(iouyap_ini, e)) def _create_netmap_config(self): @@ -367,7 +367,7 @@ class IOUDevice(object): iou_id=self._id)) log.info("IOU {name} [id={id}]: NETMAP file created".format(name=self._name, id=self._id)) - except EnvironmentError as e: + except OSError as e: raise IOUError("Could not create {}: {}".format(netmap_path, e)) def _start_ioucon(self): @@ -401,7 +401,7 @@ class IOUDevice(object): cwd=self._working_dir) log.info("iouyap started PID={}".format(self._iouyap_process.pid)) - except EnvironmentError as e: + except OSError as e: log.error("could not start iouyap: {}".format(e)) raise IOUError("Could not start iouyap: {}".format(e)) @@ -434,7 +434,7 @@ class IOUDevice(object): env=env) log.info("IOU instance {} started PID={}".format(self._id, self._process.pid)) self._started = True - except EnvironmentError as e: + except OSError as e: log.error("could not start IOU: {}".format(e)) raise IOUError("could not start IOU: {}".format(e)) @@ -493,7 +493,7 @@ class IOUDevice(object): try: with open(self._iou_stdout_file) as file: output = file.read() - except EnvironmentError as e: + except OSError as e: log.warn("could not read {}: {}".format(self._iou_stdout_file, e)) return output @@ -508,7 +508,7 @@ class IOUDevice(object): try: with open(self._iouyap_stdout_file) as file: output = file.read() - except EnvironmentError as e: + except OSError as e: log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e)) return output diff --git a/gns3server/server.py b/gns3server/server.py index 10cc28ad..1770267b 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -78,7 +78,7 @@ class Server(object): try: os.makedirs(self._projects_dir) log.info("projects directory '{}' created".format(self._projects_dir)) - except EnvironmentError as e: + except OSError as e: log.error("could not create the projects directory {}: {}".format(self._projects_dir, e)) def load_modules(self): diff --git a/gns3server/version.py b/gns3server/version.py index 63996c1d..aea583b5 100644 --- a/gns3server/version.py +++ b/gns3server/version.py @@ -23,5 +23,5 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -__version__ = "1.0-alpha1" +__version__ = "1.0a2.dev1" __version_info__ = (1, 0, 0, -99)