From 61ef750da38827baee6faef0d6f9c47c1755d4f4 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 29 May 2014 12:59:13 -0600 Subject: [PATCH] Replace decode errors when reading device configs. --- gns3server/modules/dynamips/__init__.py | 2 +- gns3server/modules/dynamips/hypervisor.py | 2 +- gns3server/modules/dynamips/nodes/router.py | 4 ++-- gns3server/modules/iou/__init__.py | 2 +- gns3server/modules/iou/iou_device.py | 6 +++--- gns3server/modules/vpcs/__init__.py | 2 +- gns3server/modules/vpcs/vpcs_device.py | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 3e278c25..b2667f93 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -474,7 +474,7 @@ class Dynamips(IModule): raise DynamipsError("Could not create configs directory: {}".format(e)) try: - with open(local_base_config, "r") as f: + with open(local_base_config, "r", errors="replace") as f: config = f.read() with open(config_path, "w") as f: config = "!\n" + config.replace("\r", "") diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index e1cc2e29..20e49741 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -251,7 +251,7 @@ class Hypervisor(DynamipsHypervisor): output = "" if self._stdout_file and os.access(self._stdout_file, os.R_OK): try: - with open(self._stdout_file) as file: + with open(self._stdout_file, errors="replace") as file: output = file.read() except OSError as e: log.warn("could not read {}: {}".format(self._stdout_file, e)) diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 7bfe7e52..bfdc9c28 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -223,7 +223,7 @@ class Router(object): startup_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}.cfg".format(self.name)) if os.path.isfile(startup_config_path): try: - with open(startup_config_path, "r+") as f: + with open(startup_config_path, "r+", errors="replace") as f: old_config = f.read() new_config = old_config.replace(self.name, new_name) f.seek(0) @@ -239,7 +239,7 @@ class Router(object): private_config_path = os.path.join(self.hypervisor.working_dir, "configs", "{}-private.cfg".format(self.name)) if os.path.isfile(private_config_path): try: - with open(private_config_path, "r+") as f: + with open(private_config_path, "r+", errors="replace") as f: old_config = f.read() new_config = old_config.replace(self.name, new_name) f.seek(0) diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 86a51d60..74a3a444 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -421,7 +421,7 @@ class IOU(IModule): if os.path.isfile(request["startup_config"]) and request["startup_config"] != config_path: # this is a local file set in the GUI try: - with open(request["startup_config"], "r") as f: + with open(request["startup_config"], "r", errors="replace") as f: config = f.read() with open(config_path, "w") as f: config = "!\n" + config.replace("\r", "") diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index 8233240a..42a5cd6c 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -188,7 +188,7 @@ class IOUDevice(object): config_path = os.path.join(self._working_dir, "startup-config") if os.path.isfile(config_path): try: - with open(config_path, "r+") as f: + with open(config_path, "r+", errors="replace") as f: old_config = f.read() new_config = old_config.replace(self._name, new_name) f.seek(0) @@ -611,7 +611,7 @@ class IOUDevice(object): output = "" if self._iou_stdout_file: try: - with open(self._iou_stdout_file) as file: + with open(self._iou_stdout_file, errors="replace") as file: output = file.read() except OSError as e: log.warn("could not read {}: {}".format(self._iou_stdout_file, e)) @@ -626,7 +626,7 @@ class IOUDevice(object): output = "" if self._iouyap_stdout_file: try: - with open(self._iouyap_stdout_file) as file: + with open(self._iouyap_stdout_file, errors="replace") as file: output = file.read() except OSError as e: log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e)) diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 9c566ea1..7140d592 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -336,7 +336,7 @@ class VPCS(IModule): if os.path.isfile(request["script_file"]) and request["script_file"] != config_path: # this is a local file set in the GUI try: - with open(request["script_file"], "r") as f: + with open(request["script_file"], "r", errors="replace") as f: config = f.read() with open(config_path, "w") as f: config = config.replace("\r", "") diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index eb639954..5cd09489 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -170,7 +170,7 @@ class VPCSDevice(object): config_path = os.path.join(self._working_dir, "startup.vpc") if os.path.isfile(config_path): try: - with open(config_path, "r+") as f: + with open(config_path, "r+", errors="replace") as f: old_config = f.read() new_config = old_config.replace(self._name, new_name) f.seek(0) @@ -388,7 +388,7 @@ class VPCSDevice(object): output = "" if self._vpcs_stdout_file: try: - with open(self._vpcs_stdout_file) as file: + with open(self._vpcs_stdout_file, errors="replace") as file: output = file.read() except OSError as e: log.warn("could not read {}: {}".format(self._vpcs_stdout_file, e))