diff options
author | Martin Klozik <martinx.klozik@intel.com> | 2017-11-15 08:24:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-11-15 08:24:29 +0000 |
commit | 66a2773d89c689d1b8740aa2388164582e9ccb6c (patch) | |
tree | 6d427256960f314d8ac7152f7497f3f6ea033811 /tools | |
parent | 31770a64cd8a5c40ee3657ac97e87a900f7aeca5 (diff) | |
parent | b1534957e463b5e34957a8d48ce5c6b0552ffbb4 (diff) |
Merge "teststeps: Improvements and bugfixing of teststeps"
Diffstat (limited to 'tools')
-rw-r--r-- | tools/functions.py | 42 | ||||
-rwxr-xr-x | tools/pkt_gen/ixnet/ixnet.py | 11 | ||||
-rw-r--r-- | tools/teststepstools.py | 8 |
3 files changed, 53 insertions, 8 deletions
diff --git a/tools/functions.py b/tools/functions.py index e8bc31da..9292867d 100644 --- a/tools/functions.py +++ b/tools/functions.py @@ -19,6 +19,7 @@ import os import logging import glob import shutil +import re from conf import settings as S MAX_L4_FLOWS = 65536 @@ -171,3 +172,44 @@ def check_traffic(traffic): traffic['multistream'] = MAX_L4_FLOWS return traffic + +def filter_output(output, regex): + """Filter output by defined regex. Output can be either string, list or tuple. + Every string is split into list line by line. After that regex is applied + to filter only matching lines, which are returned back. + + :returns: list of matching records + """ + result = [] + if isinstance(output, str): + for line in output.split('\n'): + result += re.findall(regex, line) + return result + elif isinstance(output, list) or isinstance(output, tuple): + tmp_res = [] + for item in output: + tmp_res.append(filter_output(item, regex)) + return tmp_res + else: + raise RuntimeError('Only strings and lists are supported by filter_output(), ' + 'but output has type {}'.format(type(output))) + +def format_description(desc, length): + """ Split description into multiple lines based on given line length. + + :param desc: A string with testcase description + :param length: A maximum line length + """ + # split description to multiple lines + words = desc.split() + output = [] + line = '' + for word in words: + if len(line) + len(word) < length: + line += '{} '.format(word) + else: + output.append(line.strip()) + line = '{} '.format(word) + + output.append(line.strip()) + return output diff --git a/tools/pkt_gen/ixnet/ixnet.py b/tools/pkt_gen/ixnet/ixnet.py index 972fa331..b8fb1879 100755 --- a/tools/pkt_gen/ixnet/ixnet.py +++ b/tools/pkt_gen/ixnet/ixnet.py @@ -153,9 +153,8 @@ class IxNet(trafficgen.ITrafficGenerator): """Initialize IXNET members """ super().__init__() - self._script = os.path.join(settings.getValue('TRAFFICGEN_IXIA_3RD_PARTY'), - settings.getValue('TRAFFICGEN_IXNET_TCL_SCRIPT')) self._tclsh = tkinter.Tcl() + self._script = None self._cfg = None self._logger = logging.getLogger(__name__) self._params = None @@ -177,6 +176,8 @@ class IxNet(trafficgen.ITrafficGenerator): def configure(self): """Configure system for IxNetwork. """ + self._script = os.path.join(settings.getValue('TRAFFICGEN_IXIA_3RD_PARTY'), + settings.getValue('TRAFFICGEN_IXNET_TCL_SCRIPT')) self._cfg = { 'lib_path': settings.getValue('TRAFFICGEN_IXNET_LIB_PATH'), # IxNetwork machine configuration @@ -225,6 +226,8 @@ class IxNet(trafficgen.ITrafficGenerator): 'multipleStreams': traffic['multistream'], 'streamType': traffic['stream_type'], 'rfc2544TestType': 'throughput', + 'flowControl': "True" if traffic['flow_control'] else "False", + 'learningFrames': "True" if traffic['learning_frames'] else "False", } self._params['traffic'] = self.traffic_defaults.copy() @@ -280,6 +283,8 @@ class IxNet(trafficgen.ITrafficGenerator): 'multipleStreams': traffic['multistream'], 'streamType': traffic['stream_type'], 'rfc2544TestType': 'throughput', + 'flowControl': "True" if traffic['flow_control'] else "False", + 'learningFrames': "True" if traffic['learning_frames'] else "False", } self._params['traffic'] = self.traffic_defaults.copy() @@ -418,6 +423,8 @@ class IxNet(trafficgen.ITrafficGenerator): 'multipleStreams': traffic['multistream'], 'streamType': traffic['stream_type'], 'rfc2544TestType': 'back2back', + 'flowControl': "True" if traffic['flow_control'] else "False", + 'learningFrames': "True" if traffic['learning_frames'] else "False", } self._params['traffic'] = self.traffic_defaults.copy() diff --git a/tools/teststepstools.py b/tools/teststepstools.py index 5d551c68..639e3437 100644 --- a/tools/teststepstools.py +++ b/tools/teststepstools.py @@ -15,10 +15,10 @@ """Various helper functions for step driven testcases """ -import re import logging import subprocess import locale +from tools.functions import filter_output _LOGGER = logging.getLogger(__name__) @@ -93,11 +93,7 @@ class TestStepsTools(object): output = output.decode(locale.getdefaultlocale()[1]) if regex: - for line in output.split('\n'): - result = re.findall(regex, line) - if result: - return result - return [] + return filter_output(output, regex) return output |