summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client_utils
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-01-19 08:49:31 -0500
committerimarom <imarom@cisco.com>2016-01-21 10:11:55 -0500
commitc93acc26bf2517c872da716198e76bcf566b836a (patch)
treed8edf7b972eae0d821cee644b720312f97fd5891 /scripts/automation/trex_control_plane/client_utils
parent2d9d5e147b8f15a8308dad46711390f3b168ec56 (diff)
draft #2
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils')
-rwxr-xr-xscripts/automation/trex_control_plane/client_utils/parsing_opts.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/parsing_opts.py b/scripts/automation/trex_control_plane/client_utils/parsing_opts.py
index c1afda26..3cc32b1d 100755
--- a/scripts/automation/trex_control_plane/client_utils/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/client_utils/parsing_opts.py
@@ -69,10 +69,19 @@ match_multiplier_help = """Multiplier should be passed in the following format:
will provide a percentage of the line rate. examples
: '-m 10', '-m 10kbps', '-m 10mpps', '-m 23%%' """
-def match_multiplier_common(val, strict_abs = True):
- # on strict absolute we do not allow +/-
- if strict_abs:
+# decodes multiplier
+# if allow_update - no +/- is allowed
+# divide states between how many entities the
+# value should be divided
+def decode_multiplier(val, allow_update = False, divide_count = 1):
+
+ # must be string
+ if not isinstance(val, str):
+ return None
+
+ # do we allow updates ? +/-
+ if not allow_update:
match = re.match("^(\d+(\.\d+)?)(bps|kbps|mbps|gbps|pps|kpps|mpps|%?)$", val)
op = None
else:
@@ -136,19 +145,32 @@ def match_multiplier_common(val, strict_abs = True):
else:
result['op'] = "abs"
+ if result['op'] != 'percentage':
+ result['value'] = result['value'] / divide_count
+
return result
else:
- raise argparse.ArgumentTypeError(match_multiplier_help)
+ return None
def match_multiplier(val):
'''match some val against multiplier shortcut inputs '''
- return match_multiplier_common(val, strict_abs = False)
+ result = decode_multiplier(val, allow_update = False)
+ if not result:
+ raise argparse.ArgumentTypeError(match_multiplier_help)
+
+ return val
+
def match_multiplier_strict(val):
'''match some val against multiplier shortcut inputs '''
- return match_multiplier_common(val, strict_abs = True)
+ result = decode_multiplier(val, allow_update = True)
+ if not result:
+ raise argparse.ArgumentTypeError(match_multiplier_help)
+
+ return val
+
def is_valid_file(filename):
if not os.path.isfile(filename):
@@ -287,7 +309,7 @@ class CCmdArgParser(argparse.ArgumentParser):
opts.ports = self.stateless_client.get_all_ports()
# so maybe we have ports configured
- elif (getattr(opts, "ports", None) == []):
+ elif getattr(opts, "ports", None):
for port in opts.ports:
if not self.stateless_client._validate_port_list([port]):
self.error("port id '{0}' is not a valid port id\n".format(port))