summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py')
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py11
1 files changed, 10 insertions, 1 deletions
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 0a6e64fb..d4ad8bd2 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
@@ -2,6 +2,7 @@
from collections import namedtuple
from utils.text_opts import *
from trex_stl_exceptions import *
+import types
RpcCmdData = namedtuple('RpcCmdData', ['method', 'params'])
TupleRC = namedtuple('RC', ['rc', 'data', 'is_warn'])
@@ -102,9 +103,17 @@ def RC_WARN (warn):
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 (type(valid_types) is type or # single type, not array of types
+ type(valid_types) is tuple or # several valid types as tuple
+ type(valid_types) is types.ClassType): # old style class
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')
+
+# throws STLError if not exactly one argument is present
+def verify_exclusive_arg (args_list):
+ if not (len(filter(lambda x: x is not None, args_list)) == 1):
+ raise STLError('exactly one parameter from {0} should be provided'.format(args_list))
+