Unified place for exceptions + started to getting rid of exception masking

This commit is contained in:
Martin Magr
2013-01-06 17:40:06 +01:00
parent 481758e448
commit 3cdf3065ec
5 changed files with 36 additions and 21 deletions

View File

@@ -18,15 +18,10 @@ import tempfile
import basedefs
import output_messages
from .exceptions import NetworkError, ScriptRuntimeError
class UtilsError(Exception):
pass
class UtilsNetworkError(UtilsError):
pass
def getColoredText (text, color):
''' gets text string and color
and returns a colored text.
@@ -352,12 +347,12 @@ def host2ip(hostname, allow_localhost=False):
# given hostname is localhost, return appropriate IP address
ip = getLocalhostIP()
if not ip:
raise UtilsNetworkError('Failed to get local IP address.')
raise NetworkError('Failed to get local IP address.')
return ip
except socket.error:
raise UtilsNetworkError('Unknown hostname %s.' % hostname)
raise NetworkError('Unknown hostname %s.' % hostname)
except Exception, ex:
raise UtilsNetworkError('Unknown error appeared: %s' % repr(ex))
raise NetworkError('Unknown error appeared: %s' % repr(ex))
def forceIP(host, allow_localhost=False):
host = host.strip()
@@ -400,7 +395,7 @@ class ScriptRunner(object):
else:
logging.debug("============= STDERR ==========")
logging.debug(stderrdata)
raise Exception("Error running remote script")
raise ScriptRuntimeError("Error running remote script")
else:
logging.debug(script)

View File

@@ -1,15 +1,12 @@
# -*- coding: utf-8 -*-
from .common_utils import UtilsNetworkError, forceIP
from .exceptions import ParamProcessingError
__all__ = ('ParamProcessingError', 'processHost')
class ParamProcessingError(Exception):
pass
def processHost(param, process_args=None):
"""

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
__all__ = ()
class PackStackError(Exception):
"""Default Exception class for packstack installer."""
pass
class InstallError(PackStackError):
pass
class FlagValidationError(InstallError):
pass
class PluginError(PackStackError):
pass
class ParamProcessingError(PluginError):
pass
class NetworkError(PackStackError):
"""Should be used for packstack's network failures."""
pass
class ScriptRuntimeError(PackStackError):
"""Raised when ScriptRunner.execute does not end successfully."""
pass

View File

@@ -18,6 +18,7 @@ import common_utils as utils
import engine_validators as validate
import engine_processors as process
import output_messages
from .exceptions import FlagValidationError
from setup_controller import Controller
@@ -30,11 +31,6 @@ commandLineValues = {}
masked_value_set = set()
class InstallError(Exception):
pass
class FlagValidationError(InstallError):
pass
def initLogging (debug):
global logFile

View File

@@ -6,8 +6,9 @@ import os
import platform
import time
from packstack.installer import basedefs
import packstack.installer.common_utils as utils
from packstack.installer import basedefs
from packstack.installer.exceptions import ScriptRuntimeError
from packstack.modules.ospluginutils import gethostlist,\
manifestfiles,\
@@ -98,7 +99,7 @@ def waitforpuppet(currently_running):
# If we got to this point the puppet apply has finished
currently_running.remove((hostname, log))
except Exception, e:
except ScriptRuntimeError, e:
# the test raises an exception if the file doesn't exist yet
time.sleep(3)
print