From: Ondrej Lichtner <olichtne(a)redhat.com>
All LNST related Exceptions should inherit from the LnstError base
exception class.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/Config.py | 3 ++-
lnst/Common/ExecCmd.py | 3 ++-
lnst/Common/NetTestCommand.py | 5 +++--
lnst/Common/ResourceCache.py | 3 ++-
lnst/Common/SecureSocket.py | 3 ++-
lnst/Common/ShellProcess.py | 3 ++-
lnst/Common/TestsCommon.py | 3 ++-
lnst/Controller/Machine.py | 5 +++--
lnst/Controller/Task.py | 4 +++-
lnst/Controller/VirtUtils.py | 3 ++-
lnst/RecipeCommon/ModuleWrap.py | 33 +++++++++++++++++----------------
11 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index d47f3e2..04d6f9b 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -18,10 +18,11 @@ from lnst.Common.Utils import bool_it
from lnst.Common.NetUtils import verify_mac_address
from lnst.Common.Colours import get_preset_conf
from lnst.Common.Version import LNSTMajorVersion
+from lnst.Common.LnstError import LnstError
DefaultRPCPort = 9999
-class ConfigError(Exception):
+class ConfigError(LnstError):
pass
class Config():
diff --git a/lnst/Common/ExecCmd.py b/lnst/Common/ExecCmd.py
index 24715ae..6489766 100644
--- a/lnst/Common/ExecCmd.py
+++ b/lnst/Common/ExecCmd.py
@@ -12,8 +12,9 @@ jpirko(a)redhat.com (Jiri Pirko)
import logging
import subprocess
+from lnst.Common.LnstError import LnstError
-class ExecCmdFail(Exception):
+class ExecCmdFail(LnstError):
_cmd = None
_retval = None
_stderr = None
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index f91cc37..ad4fe8f 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -21,6 +21,7 @@ from time import time
from lnst.Common.ExecCmd import exec_cmd, ExecCmdFail
from lnst.Common.ConnectionHandler import send_data
from lnst.Common.Logs import log_exc_traceback
+from lnst.Common.LnstError import LnstError
DEFAULT_TIMEOUT = 60
@@ -64,7 +65,7 @@ def str_command(command):
return ", ".join(attrs)
-class CommandException(Exception):
+class CommandException(LnstError):
"""Base class for client errors."""
def __init__(self, command):
self.command = command
@@ -72,7 +73,7 @@ class CommandException(Exception):
def __str__(self):
return "CommandException: " + str(self.command)
-class BgCommandException(Exception):
+class BgCommandException(CommandException):
"""Base class for background command errors."""
def __init__(self, str):
self._str = str
diff --git a/lnst/Common/ResourceCache.py b/lnst/Common/ResourceCache.py
index 98558a2..2037a0c 100644
--- a/lnst/Common/ResourceCache.py
+++ b/lnst/Common/ResourceCache.py
@@ -15,10 +15,11 @@ import re
import time
import shutil
from lnst.Common.ExecCmd import exec_cmd
+from lnst.Common.LnstError import LnstError
SETUP_SCRIPT_NAME = "lnst-setup.sh"
-class ResourceCacheError(Exception):
+class ResourceCacheError(LnstError):
pass
class ResourceCache(object):
diff --git a/lnst/Common/SecureSocket.py b/lnst/Common/SecureSocket.py
index b856238..84ff04a 100644
--- a/lnst/Common/SecureSocket.py
+++ b/lnst/Common/SecureSocket.py
@@ -20,6 +20,7 @@ import cPickle
import hashlib
import hmac
from lnst.Common.Utils import not_imported
+from lnst.Common.LnstError import LnstError
DH_GROUP = {"p":
int("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"\
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"\
@@ -71,7 +72,7 @@ SRP_GROUP["p_size"] = bit_length(SRP_GROUP["p"])/8
if bit_length(SRP_GROUP["p"])%8:
SRP_GROUP["p_size"] += 1
-class SecSocketException(Exception):
+class SecSocketException(LnstError):
pass
cryptography = not_imported
diff --git a/lnst/Common/ShellProcess.py b/lnst/Common/ShellProcess.py
index a4928ed..58c4bd1 100644
--- a/lnst/Common/ShellProcess.py
+++ b/lnst/Common/ShellProcess.py
@@ -13,9 +13,10 @@ import pty, os, termios, time, signal, re, select
import logging, atexit
from lnst.Common.Utils import wait_for
from lnst.Common.ProcessManager import ProcessManager
+from lnst.Common.LnstError import LnstError
class ShellProcess:
- class ProcessError(Exception):
+ class ProcessError(LnstError):
def __init__(self, patterns, output):
Exception.__init__(self, patterns, output)
self.patterns = patterns
diff --git a/lnst/Common/TestsCommon.py b/lnst/Common/TestsCommon.py
index accb6b8..471d720 100644
--- a/lnst/Common/TestsCommon.py
+++ b/lnst/Common/TestsCommon.py
@@ -16,6 +16,7 @@ import os
import signal
import time
from lnst.Common.NetTestCommand import NetTestCommandGeneric
+from lnst.Common.LnstError import LnstError
class testLogger(logging.Logger):
def __init__(self, name, level=logging.NOTSET):
@@ -50,7 +51,7 @@ try:
finally:
logging._releaseLock()
-class TestOptionMissing(Exception):
+class TestOptionMissing(LnstError):
pass
class TestGeneric(NetTestCommandGeneric):
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 539952e..3bfcf82 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -23,16 +23,17 @@ from lnst.Common.NetUtils import normalize_hwaddr
from lnst.Common.Utils import wait_for, create_tar_archive
from lnst.Common.Utils import check_process_running
from lnst.Common.NetTestCommand import DEFAULT_TIMEOUT
+from lnst.Controller.Common import ControllerError
from lnst.Controller.CtlSecSocket import CtlSecSocket
# conditional support for libvirt
if check_process_running("libvirtd"):
from lnst.Controller.VirtUtils import VirtNetCtl, VirtDomainCtl
-class MachineError(Exception):
+class MachineError(ControllerError):
pass
-class PrefixMissingError(Exception):
+class PrefixMissingError(ControllerError):
pass
class Machine(object):
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index a144d00..5c288cc 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -18,6 +18,7 @@ from lnst.Common.Config import lnst_config
from lnst.Controller.XmlTemplates import XmlTemplateError
from lnst.Common.Path import Path
from lnst.Controller.PerfRepoMapping import PerfRepoMapping
+from lnst.Controller.Common import ControllerError
from lnst.Common.Utils import Noop
try:
@@ -84,7 +85,8 @@ def match():
return False
-class TaskError(Exception): pass
+class TaskError(ControllerError):
+ pass
class ControllerAPI(object):
""" An API class representing the controller. """
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index 750196c..c8da28a 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -16,6 +16,7 @@ import libvirt
from libvirt import libvirtError
from lnst.Common.ExecCmd import exec_cmd, ExecCmdFail
from lnst.Common.NetUtils import scan_netdevs
+from lnst.Controller.Common import ControllerError
#this is a global object because opening the connection to libvirt in every
#object instance that uses it sometimes fails - the libvirt server probably
@@ -27,7 +28,7 @@ def init_libvirt_con():
if _libvirt_conn is None:
_libvirt_conn = libvirt.open(None)
-class VirtUtilsError(Exception):
+class VirtUtilsError(ControllerError):
pass
def _ip(cmd):
diff --git a/lnst/RecipeCommon/ModuleWrap.py b/lnst/RecipeCommon/ModuleWrap.py
index 2df953c..1f7acc6 100644
--- a/lnst/RecipeCommon/ModuleWrap.py
+++ b/lnst/RecipeCommon/ModuleWrap.py
@@ -10,6 +10,7 @@ __author__ = """
olichtne(a)redhat.com (Ondrej Lichtner)
"""
+from lnst.Common.LnstError import LnstError
from lnst.Controller.Task import ctl
def ping(src, dst, options={}, expect="pass", bg=False):
@@ -24,10 +25,10 @@ def ping(src, dst, options={}, expect="pass", bg=False):
options = dict(options)
if 'addr' in options or 'iface' in options:
- raise Exception("options can't contain keys 'addr' and
'iface'")
+ raise LnstError("options can't contain keys 'addr' and
'iface'")
if not isinstance(src, tuple) or len(src) < 2 or len(src) > 4:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
try:
if len(src) == 2:
h1, if1 = src
@@ -39,10 +40,10 @@ def ping(src, dst, options={}, expect="pass", bg=False):
h1, if1, addr_index1, addr_selector1 = src
options["iface"] = if1.get_ip(addr_index1,
selector=addr_selector1)
except:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
if not isinstance(dst, tuple) or len(dst) < 3 or len(dst) > 4:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
try:
if len(dst) == 3:
h2, if2, addr_index2 = dst
@@ -51,7 +52,7 @@ def ping(src, dst, options={}, expect="pass", bg=False):
h2, if2, addr_index2, addr_selector2 = dst
options["addr"] = if2.get_ip(addr_index2, selector=addr_selector2)
except:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
ping_mod = ctl.get_module("IcmpPing",
options = options)
@@ -70,10 +71,10 @@ def ping6(src, dst, options={}, expect="pass", bg=False):
options = dict(options)
if 'addr' in options or 'iface' in options:
- raise Exception("options can't contain keys 'addr' and
'iface'")
+ raise LnstError("options can't contain keys 'addr' and
'iface'")
if not isinstance(src, tuple) or len(src) < 2 or len(src) > 4:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
try:
if len(src) == 2:
h1, if1 = src
@@ -85,10 +86,10 @@ def ping6(src, dst, options={}, expect="pass", bg=False):
h1, if1, addr_index1, addr_selector1 = src
options["iface"] = if1.get_ip(addr_index1,
selector=addr_selector1)
except:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
if not isinstance(dst, tuple) or len(dst) < 3 or len(dst) > 4:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
try:
if len(dst) == 3:
h2, if2, addr_index2 = dst
@@ -97,7 +98,7 @@ def ping6(src, dst, options={}, expect="pass", bg=False):
h2, if2, addr_index2, addr_selector2 = dst
options["addr"] = if2.get_ip(addr_index2, selector=addr_selector2)
except:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
ping_mod = ctl.get_module("Icmp6Ping",
options = options)
@@ -123,17 +124,17 @@ def netperf(src, dst, server_opts={}, client_opts={}, baseline={},
timeout=60):
server_opts = dict(server_opts)
if 'bind' in server_opts or 'role' in server_opts:
- raise Exception("server_opts can't contain keys 'bind' and
'role'")
+ raise LnstError("server_opts can't contain keys 'bind' and
'role'")
client_opts = dict(client_opts)
if 'bind' in client_opts or\
'role' in client_opts or\
'netperf_server' in client_opts:
- raise Exception("client_opts can't contain keys 'bind',
'role' "\
+ raise LnstError("client_opts can't contain keys 'bind',
'role' "\
"and 'netperf_server'")
if not isinstance(src, tuple) or len(src) < 2 or len(src) > 4:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
try:
if len(src) == 3:
h1, if1, addr_index1 = src
@@ -142,10 +143,10 @@ def netperf(src, dst, server_opts={}, client_opts={}, baseline={},
timeout=60):
h1, if1, addr_index1, addr_selector1 = src
client_ip = if1.get_ip(addr_index1, selector=addr_selector1)
except:
- raise Exception('Invalid source specification')
+ raise LnstError('Invalid source specification')
if not isinstance(dst, tuple) or len(dst) < 3 or len(dst) > 4:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
try:
if len(dst) == 3:
h2, if2, addr_index2 = dst
@@ -154,7 +155,7 @@ def netperf(src, dst, server_opts={}, client_opts={}, baseline={},
timeout=60):
h2, if2, addr_index2, addr_selector2 = dst
server_ip = if2.get_ip(addr_index2, addr_selector2)
except:
- raise Exception('Invalid destination specification')
+ raise LnstError('Invalid destination specification')
server_opts["role"] = "server"
server_opts["bind"] = server_ip
--
2.13.0