summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-09-25 18:45:04 +0300
committerimarom <imarom@cisco.com>2016-09-25 18:45:04 +0300
commitf6d11f9e01e39fe2688558c7598f22ce9feb35da (patch)
tree672f5e4c5010484569edbbe8b29c4c03b2cd7ef4 /scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
parentd94e6a00edc22a1dd4946b3603aebb29319ce5ce (diff)
merge issues with rand limit
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py')
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
index b6fad865..2ca92cb8 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py
@@ -1,6 +1,6 @@
import os
import sys
-import linecache
+import traceback
from .utils.text_opts import *
@@ -13,23 +13,19 @@ except NameError:
class STLError(Exception):
def __init__ (self, msg):
self.msg = str(msg)
+ self.tb = traceback.extract_stack()
def __str__ (self):
- exc_type, exc_obj, exc_tb = sys.exc_info()
- if not exc_tb:
- return self.msg
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
-
-
- src_line = str(linecache.getline(fname, exc_tb.tb_lineno))
+ fname = os.path.split(self.tb[-2][0])[1]
+ lineno = self.tb[-2][1]
+ func = self.tb[-2][2]
+ src = self.tb[-2][3]
s = "\n******\n"
- s += "Error at {0}:{1} - '{2}'\n\n".format(format_text(fname, 'bold'), format_text(exc_tb.tb_lineno, 'bold'), format_text(src_line.strip(), 'bold'))
+ s += "Error at {0}:{1} - '{2}'\n\n".format(format_text(fname, 'bold'), format_text(lineno, 'bold'), format_text(src.strip(), 'bold'))
s += "specific error:\n\n{0}\n".format(format_text(self.msg, 'bold'))
-
-
return s
def brief (self):
@@ -40,17 +36,18 @@ class STLError(Exception):
class STLStateError(STLError):
def __init__ (self, op, state):
self.msg = "Operation '{0}' is not valid while '{1}'".format(op, state)
-
+ self.tb = traceback.extract_stack()
# port state error
class STLPortStateError(STLError):
def __init__ (self, port, op, state):
self.msg = "Operation '{0}' on port(s) '{1}' is not valid while port(s) '{2}'".format(op, port, state)
-
+ self.tb = traceback.extract_stack()
# raised when argument value is not valid for operation
class STLArgumentError(STLError):
def __init__ (self, name, got, valid_values = None, extended = None):
+ self.tb = traceback.extract_stack()
self.msg = "Argument: '{0}' invalid value: '{1}'".format(name, got)
if valid_values:
self.msg += " - valid values are '{0}'".format(valid_values)
@@ -61,12 +58,14 @@ class STLArgumentError(STLError):
# raised when argument type is not valid for operation
class STLTypeError(STLError):
def __init__ (self, arg_name, arg_type, valid_types):
+ self.tb = traceback.extract_stack()
self.msg = "Argument: '%s' invalid type: '%s', expecting type(s): %s." % (arg_name, arg_type.__name__,
[t.__name__ for t in valid_types] if isinstance(valid_types, tuple) else valid_types.__name__)
# raised when timeout occurs
class STLTimeoutError(STLError):
def __init__ (self, timeout):
+ self.tb = traceback.extract_stack()
self.msg = "Timeout: operation took more than '{0}' seconds".format(timeout)