From 2d83657bd9d064aa1438427edbad1e70ba326f08 Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Thu, 28 Sep 2017 17:56:34 +0300 Subject: [PATCH] Fix missing WindowsError on linux --- chaos_monkey/dropper.py | 12 +++++++++--- chaos_monkey/system_info/__init__.py | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/chaos_monkey/dropper.py b/chaos_monkey/dropper.py index adbca1821..c0b995ae8 100644 --- a/chaos_monkey/dropper.py +++ b/chaos_monkey/dropper.py @@ -19,6 +19,12 @@ if "win32" == sys.platform: else: DETACHED_PROCESS = 0 +# Linux doesn't have WindowsError +try: + WindowsError +except NameError: + WindowsError = None + __author__ = 'itamar' LOG = logging.getLogger(__name__) @@ -62,7 +68,7 @@ class MonkeyDrops(object): self._config['source_path'], self._config['destination_path']) file_moved = True - except (WindowsError, IOError, OSError), exc: + except (WindowsError, IOError, OSError) as exc: LOG.debug("Error moving source file '%s' into '%s': %s", self._config['source_path'], self._config['destination_path'], exc) @@ -75,7 +81,7 @@ class MonkeyDrops(object): LOG.info("Copied source file '%s' into '%s'", self._config['source_path'], self._config['destination_path']) - except (WindowsError, IOError, OSError), exc: + except (WindowsError, IOError, OSError) as exc: LOG.error("Error copying source file '%s' into '%s': %s", self._config['source_path'], self._config['destination_path'], exc) @@ -131,7 +137,7 @@ class MonkeyDrops(object): # try removing the file first try: os.remove(self._config['source_path']) - except Exception, exc: + except Exception as exc: LOG.debug("Error removing source file '%s': %s", self._config['source_path'], exc) # mark the file for removal on next boot diff --git a/chaos_monkey/system_info/__init__.py b/chaos_monkey/system_info/__init__.py index ddf13d885..0a5bf8e31 100644 --- a/chaos_monkey/system_info/__init__.py +++ b/chaos_monkey/system_info/__init__.py @@ -6,6 +6,12 @@ from enum import IntEnum from network.info import get_host_subnets +# Linux doesn't have WindowsError +try: + WindowsError +except NameError: + WindowsError = None + __author__ = 'uri'