diff options
author | 2016-02-11 13:04:59 +0200 | |
---|---|---|
committer | 2016-02-11 13:04:59 +0200 | |
commit | 1a780eaa3669a296b683201ef6431a7490fdc7d6 (patch) | |
tree | e62c1476468e5d184c87a4e369e532036f582d8f /scripts/automation/trex_control_plane | |
parent | 1aec60fb7a6bb5dc4143e91e28844dd4fef6ece6 (diff) | |
parent | a66529ec065cf0745618c0f065d491b9fcca4e53 (diff) |
Fix tests
Diffstat (limited to 'scripts/automation/trex_control_plane')
-rwxr-xr-x | scripts/automation/trex_control_plane/client_utils/general_utils.py | 8 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_exceptions.py | 10 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py (renamed from scripts/automation/trex_control_plane/client/trex_hltapi.py) | 10 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py | 15 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py | 9 |
5 files changed, 34 insertions, 18 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/general_utils.py b/scripts/automation/trex_control_plane/client_utils/general_utils.py index 9a510ec5..d2521f02 100755 --- a/scripts/automation/trex_control_plane/client_utils/general_utils.py +++ b/scripts/automation/trex_control_plane/client_utils/general_utils.py @@ -90,14 +90,6 @@ def id_count_gen(): yield return_id return_id += 1 -# try to get number from input, return None in case of fail -def get_number(input): - try: - if type(input) in (int, long): - return input - return int(input) - except: - return None if __name__ == "__main__": pass 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 45acc72e..e84b032b 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 @@ -10,6 +10,8 @@ class STLError(Exception): 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] @@ -35,7 +37,7 @@ class STLPortStateError(STLError): self.msg = "Operation '{0}' on port(s) '{1}' is not valid while port(s) '{2}'".format(op, port, state) -# raised when argument is not valid for operation +# raised when argument value is not valid for operation class STLArgumentError(STLError): def __init__ (self, name, got, valid_values = None, extended = None): self.msg = "Argument: '{0}' invalid value: '{1}'".format(name, got) @@ -45,10 +47,14 @@ class STLArgumentError(STLError): if extended: self.msg += "\n{0}".format(extended) +# raised when argument type is not valid for operation +class STLTypeError(STLError): + def __init__ (self, arg_name, arg_type, valid_types): + self.msg = "Argument: '%s' invalid type: %s, expecting type(s): %s." % (arg_name, arg_type, valid_types) + # raised when timeout occurs class STLTimeoutError(STLError): def __init__ (self, timeout): self.msg = "Timeout: operation took more than '{0}' seconds".format(timeout) - diff --git a/scripts/automation/trex_control_plane/client/trex_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py index fc507497..65aaa1c5 100755 --- a/scripts/automation/trex_control_plane/client/trex_hltapi.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py @@ -126,16 +126,10 @@ traffic_stats_kwargs = { import sys import os - -CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CURRENT_PATH, '../stl/')) - -from trex_stl_lib.api import * - -from client_utils.general_utils import get_number import socket import copy -from misc_methods import print_r +from trex_stl_lib.api import * +from utils.common import get_number class HLT_ERR(dict): diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py index 1164076b..d387ac9c 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py @@ -1,6 +1,7 @@ from collections import namedtuple from utils.text_opts import * +from trex_stl_exceptions import * RpcCmdData = namedtuple('RpcCmdData', ['method', 'params']) @@ -93,3 +94,17 @@ def RC_ERR (err): def RC_WARN (warn): return RC(True, warn, is_warn = True) + + +# validate type of arg +# example1: validate_type('somearg', somearg, [int, long]) +# example2: validate_type('another_arg', another_arg, str) +def validate_type(arg_name, arg, valid_types): + if type(valid_types) is list: + valid_types = tuple(valid_types) + if type(valid_types) is type or type(valid_types) is tuple: + if isinstance(arg, valid_types): + return + raise STLTypeError(arg_name, type(arg), valid_types) + else: + raise STLError('validate_type: valid_types should be type or list or tuple of types') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py index 117017c3..9490c1b0 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py @@ -45,3 +45,12 @@ def random_id_gen(length=8): for i in range(length): return_id += random.choice(id_chars) yield return_id + +# try to get number from input, return None in case of fail +def get_number(input): + try: + if type(input) in (int, long): + return input + return int(input) + except: + return None |