summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-04-14 17:23:04 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-04-14 17:23:04 +0300
commit501fb3b44f14e9c0d40a63bd8b47200b01e50be9 (patch)
treea45a01a5d0e724282f83df5b419916afd6784ca6
parente0720b15ec9dc695a8c1799e87cbe41a670cb616 (diff)
regression: python3 support
-rwxr-xr-xscripts/automation/regression/CPlatform.py19
-rwxr-xr-xscripts/automation/regression/CShowParser.py2
-rwxr-xr-xscripts/automation/regression/aggregate_results.py65
-rwxr-xr-xscripts/automation/regression/functional_tests/platform_device_cfg_test.py6
-rw-r--r--scripts/automation/regression/functional_tests/stl_basic_tests.py1
-rwxr-xr-xscripts/automation/regression/interactive_platform.py110
-rwxr-xr-xscripts/automation/regression/platform_cmd_link.py40
-rwxr-xr-xscripts/automation/regression/stateful_tests/tests_exceptions.py48
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_client_pkg_test.py2
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_general_test.py42
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_imix_test.py31
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_ipv6_test.py17
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_nat_test.py29
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_nbar_test.py47
-rwxr-xr-xscripts/automation/regression/stateful_tests/trex_rx_test.py48
-rw-r--r--scripts/automation/regression/stateless_tests/stl_client_test.py2
-rwxr-xr-xscripts/automation/regression/stateless_tests/stl_examples_test.py5
-rw-r--r--scripts/automation/regression/stateless_tests/stl_general_test.py10
-rw-r--r--scripts/automation/regression/stateless_tests/stl_rx_test.py6
-rwxr-xr-xscripts/automation/regression/stateless_tests/trex_client_pkg_test.py2
-rwxr-xr-xscripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py15
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py15
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py26
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py11
-rwxr-xr-xscripts/run_functional_tests5
25 files changed, 324 insertions, 280 deletions
diff --git a/scripts/automation/regression/CPlatform.py b/scripts/automation/regression/CPlatform.py
index da056d23..7727b3ce 100755
--- a/scripts/automation/regression/CPlatform.py
+++ b/scripts/automation/regression/CPlatform.py
@@ -67,7 +67,9 @@ class CPlatform(object):
cache = CCommandCache()
cache.add('EXEC', "configure replace {drive}:{file} force".format(drive = cfg_drive, file = config_filename))
- self.cmd_link.run_single_command(cache)
+ res = self.cmd_link.run_single_command(cache)
+ if 'Rollback Done' not in res:
+ raise UserWarning('Could not load clean config, please verify file exists. Response:\n%s' % res)
def config_pbr (self, mode = 'config'):
idx = 1
@@ -566,7 +568,7 @@ class CPlatform(object):
# print response
# response = self.cmd_link.run_single_command('show platform hardware qfp active interface all statistics')
# print response
- if_list_by_name = map( lambda x: x.get_name(), self.if_mngr.get_if_list() )
+ if_list_by_name = [x.get_name() for x in self.if_mngr.get_if_list()]
return CShowParser.parse_drop_stats(response, if_list_by_name )
def get_nat_stats (self):
@@ -820,7 +822,7 @@ class CPlatform(object):
self.reload_connection(device_cfg_obj)
progress_thread.join()
except Exception as e:
- print e
+ print(e)
def get_if_manager(self):
return self.if_mngr
@@ -864,9 +866,8 @@ class CStaticRouteConfig(object):
def extract_net_addr (self, ip_addr, ip_mask):
addr_lst = ip_addr.split('.')
mask_lst = ip_mask.split('.')
- mask_lst = map(lambda x,y: int(x) & int(y), addr_lst, mask_lst )
- masked_str = map(lambda x: str(x), mask_lst )
- return '.'.join(masked_str)
+ mask_lst = [str(int(x) & int(y)) for x, y in zip(addr_lst, mask_lst)]
+ return '.'.join(mask_lst)
def dump_config (self):
import yaml
@@ -884,9 +885,9 @@ class CNatConfig(object):
@staticmethod
def calc_pool_end (nat_pool_start, netmask):
- pool_start_lst = map(lambda x: int(x), nat_pool_start.split('.') )
+ pool_start_lst = [int(x) for x in nat_pool_start.split('.')]
pool_end_lst = list( pool_start_lst ) # create new list object, don't point to the original one
- mask_lst = map(lambda x: int(x), netmask.split('.'))
+ mask_lst = [int(x) for x in netmask.split('.')]
curr_octet = 3 # start with the LSB octet
inc_val = 1
@@ -902,7 +903,7 @@ class CNatConfig(object):
else:
pool_end_lst[curr_octet] += (inc_val - 1)
break
- return '.'.join(map(lambda x: str(x), pool_end_lst))
+ return '.'.join([str(x) for x in pool_end_lst])
def dump_config (self):
import yaml
diff --git a/scripts/automation/regression/CShowParser.py b/scripts/automation/regression/CShowParser.py
index b3120eb1..3445c70e 100755
--- a/scripts/automation/regression/CShowParser.py
+++ b/scripts/automation/regression/CShowParser.py
@@ -54,7 +54,7 @@ class CShowParser(object):
if avg_pkt_cnt == 0.0:
# escaping zero division case
continue
- if stats.has_key(key) :
+ if key in stats:
stats[key] += avg_pkt_cnt
else:
stats[key] = avg_pkt_cnt
diff --git a/scripts/automation/regression/aggregate_results.py b/scripts/automation/regression/aggregate_results.py
index 31929d50..35ec80d0 100755
--- a/scripts/automation/regression/aggregate_results.py
+++ b/scripts/automation/regression/aggregate_results.py
@@ -8,7 +8,10 @@ import sys, os
from collections import OrderedDict
import copy
import datetime, time
-import cPickle as pickle
+try:
+ import cPickle as pickle
+except:
+ import pickle
import subprocess, shlex
from ansi2html import Ansi2HTMLConverter
@@ -83,12 +86,12 @@ def add_category_of_tests(category, tests, tests_type = None, category_info_dir
with open(category_info_file) as f:
for info_line in f.readlines():
key_value = info_line.split(':', 1)
- if key_value[0].strip() in trex_info_dict.keys() + ['User']: # always 'hhaim', no need to show
+ if key_value[0].strip() in list(trex_info_dict.keys()) + ['User']: # always 'hhaim', no need to show
continue
html_output += add_th_td('%s:' % key_value[0], key_value[1])
else:
html_output += add_th_td('Info:', 'No info')
- print 'add_category_of_tests: no category info %s' % category_info_file
+ print('add_category_of_tests: no category info %s' % category_info_file)
if tests_type:
html_output += add_th_td('Tests type:', tests_type.capitalize())
if len(tests):
@@ -253,13 +256,16 @@ if __name__ == '__main__':
build_url = os.environ.get('BUILD_URL')
build_id = os.environ.get('BUILD_ID')
trex_repo = os.environ.get('TREX_CORE_REPO')
+ python_ver = os.environ.get('PYTHON_VER')
if not scenario:
- print 'Warning: no environment variable SCENARIO, using default'
+ print('Warning: no environment variable SCENARIO, using default')
scenario = 'TRex regression'
if not build_url:
- print 'Warning: no environment variable BUILD_URL'
+ print('Warning: no environment variable BUILD_URL')
if not build_id:
- print 'Warning: no environment variable BUILD_ID'
+ print('Warning: no environment variable BUILD_ID')
+ if not python_ver:
+ print('Warning: no environment variable PYTHON_VER')
trex_info_dict = OrderedDict()
for file in glob.glob('%s/report_*.info' % args.input_dir):
@@ -279,17 +285,17 @@ if __name__ == '__main__':
trex_last_commit_hash = trex_info_dict.get('Git SHA')
if trex_last_commit_hash and trex_repo:
try:
- print 'Getting TRex commit with hash %s' % trex_last_commit_hash
+ print('Getting TRex commit with hash %s' % trex_last_commit_hash)
command = 'git --git-dir %s show %s --quiet' % (trex_repo, trex_last_commit_hash)
- print 'Executing: %s' % command
+ print('Executing: %s' % command)
proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(trex_last_commit_info, stderr) = proc.communicate()
- print 'Stdout:\n\t' + trex_last_commit_info.replace('\n', '\n\t')
- print 'Stderr:', stderr
- print 'Return code:', proc.returncode
+ print('Stdout:\n\t' + trex_last_commit_info.replace('\n', '\n\t'))
+ print('Stderr:', stderr)
+ print('Return code:', proc.returncode)
trex_last_commit_info = trex_last_commit_info.replace('\n', '<br>')
except Exception as e:
- print 'Error getting last commit: %s' % e
+ print('Error getting last commit: %s' % e)
##### get xmls: report_<setup name>.xml
@@ -304,7 +310,7 @@ if __name__ == '__main__':
jobs_list.append(line)
else:
message = '%s does not exist!' % jobs_file
- print message
+ print(message)
err.append(message)
##### aggregate results to 1 single tree
@@ -331,7 +337,7 @@ if __name__ == '__main__':
tests = root.getchildren()
if not len(tests): # there should be tests:
message = 'No tests in xml %s' % xml_file
- print message
+ print(message)
#err.append(message)
for test in tests:
setups[job][test_type].append(test)
@@ -340,7 +346,7 @@ if __name__ == '__main__':
aggregated_root.append(test)
if not sum([len(x) for x in setups[job].values()]):
message = 'No reports from setup %s!' % job
- print message
+ print(message)
err.append(message)
continue
@@ -405,7 +411,10 @@ if __name__ == '__main__':
<body>
<table class="reference">
'''
- html_output += add_th_td('Scenario:', scenario.capitalize())
+ if scenario:
+ html_output += add_th_td('Scenario:', scenario.capitalize())
+ if python_ver:
+ html_output += add_th_td('Python:', python_ver)
start_time_file = '%s/start_time.info' % args.input_dir
if os.path.exists(start_time_file):
with open(start_time_file) as f:
@@ -530,7 +539,10 @@ if __name__ == '__main__':
<body>
<table class="reference">
'''
- mail_output += add_th_td('Scenario:', scenario.capitalize())
+ if scenario:
+ mail_output += add_th_td('Scenario:', scenario.capitalize())
+ if python_ver:
+ mail_output += add_th_td('Python:', python_ver)
if build_url:
mail_output += add_th_td('Full HTML report:', '<a class="example" href="%s/HTML_Report">link</a>' % build_url)
start_time_file = '%s/start_time.info' % args.input_dir
@@ -565,7 +577,7 @@ if __name__ == '__main__':
with open(category_info_file) as f:
for info_line in f.readlines():
key_value = info_line.split(':', 1)
- if key_value[0].strip() in trex_info_dict.keys() + ['User']: # always 'hhaim', no need to show
+ if key_value[0].strip() in list(trex_info_dict.keys()) + ['User']: # always 'hhaim', no need to show
continue
mail_output += add_th_td('%s:' % key_value[0].strip(), key_value[1].strip())
else:
@@ -598,12 +610,15 @@ if __name__ == '__main__':
# build status
category_dict_status = {}
if os.path.exists(args.build_status_file):
- with open(args.build_status_file) as f:
- print('Reading: %s' % args.build_status_file)
- category_dict_status = pickle.load(f)
- if type(category_dict_status) is not dict:
- print '%s is corrupt, truncating' % args.build_status_file
- category_dict_status = {}
+ print('Reading: %s' % args.build_status_file)
+ with open(args.build_status_file, 'rb') as f:
+ try:
+ category_dict_status = pickle.load(f)
+ except Exception as e:
+ print('Error during pickle load: %s' % e)
+ if type(category_dict_status) is not dict:
+ print('%s is corrupt, truncating' % args.build_status_file)
+ category_dict_status = {}
last_status = category_dict_status.get(scenario, 'Successful') # assume last is passed if no history
if err or len(error_tests): # has fails
@@ -618,7 +633,7 @@ if __name__ == '__main__':
current_status = 'Fixed'
category_dict_status[scenario] = current_status
- with open(args.build_status_file, 'w') as f:
+ with open(args.build_status_file, 'wb') as f:
print('Writing output file: %s' % args.build_status_file)
pickle.dump(category_dict_status, f)
diff --git a/scripts/automation/regression/functional_tests/platform_device_cfg_test.py b/scripts/automation/regression/functional_tests/platform_device_cfg_test.py
index 3935a4c5..c60635fe 100755
--- a/scripts/automation/regression/functional_tests/platform_device_cfg_test.py
+++ b/scripts/automation/regression/functional_tests/platform_device_cfg_test.py
@@ -9,12 +9,12 @@ from nose.tools import assert_not_equal
class CDeviceCfg_Test(functional_general_test.CGeneralFunctional_Test):
def setUp(self):
- self.dev_cfg = CDeviceCfg('./functional_tests/config.yaml')
+ self.dev_cfg = CDeviceCfg('./functional_tests/config.yaml')
def test_get_interfaces_cfg(self):
assert_equal (self.dev_cfg.get_interfaces_cfg(),
- [{'client': {'src_mac_addr': '0000.0001.0000', 'name': 'GigabitEthernet0/0/1', 'dest_mac_addr': '0000.1000.0000'}, 'vrf_name': None, 'server': {'src_mac_addr': '0000.0002.0000', 'name': 'GigabitEthernet0/0/2', 'dest_mac_addr': '0000.2000.0000'}}, {'client': {'src_mac_addr': '0000.0003.0000', 'name': 'GigabitEthernet0/0/3', 'dest_mac_addr': '0000.3000.0000'}, 'vrf_name': 'dup', 'server': {'src_mac_addr': '0000.0004.0000', 'name': 'GigabitEthernet0/0/4', 'dest_mac_addr': '0000.4000.0000'}}]
- )
+ [{'client': {'src_mac_addr': '0000.0001.0000', 'name': 'GigabitEthernet0/0/1', 'dest_mac_addr': '0000.1000.0000'}, 'vrf_name': None, 'server': {'src_mac_addr': '0000.0002.0000', 'name': 'GigabitEthernet0/0/2', 'dest_mac_addr': '0000.2000.0000'}}, {'client': {'src_mac_addr': '0000.0003.0000', 'name': 'GigabitEthernet0/0/3', 'dest_mac_addr': '0000.3000.0000'}, 'vrf_name': 'dup', 'server': {'src_mac_addr': '0000.0004.0000', 'name': 'GigabitEthernet0/0/4', 'dest_mac_addr': '0000.4000.0000'}}]
+ )
def tearDown(self):
pass
diff --git a/scripts/automation/regression/functional_tests/stl_basic_tests.py b/scripts/automation/regression/functional_tests/stl_basic_tests.py
index ecb7b465..71228d9a 100644
--- a/scripts/automation/regression/functional_tests/stl_basic_tests.py
+++ b/scripts/automation/regression/functional_tests/stl_basic_tests.py
@@ -135,6 +135,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
def run_py_profile_path (self, profile, options,silent = False, do_no_remove=False,compare =True, test_generated=True, do_no_remove_generated = False):
+ print('Testing profile: %s' % profile)
output_cap = "a.pcap"
input_file = os.path.join('stl/', profile)
golden_file = os.path.join('exp',os.path.basename(profile).split('.')[0]+'.pcap');
diff --git a/scripts/automation/regression/interactive_platform.py b/scripts/automation/regression/interactive_platform.py
index bfedd37d..10e89910 100755
--- a/scripts/automation/regression/interactive_platform.py
+++ b/scripts/automation/regression/interactive_platform.py
@@ -33,30 +33,30 @@ class InteractivePlatform(cmd.Cmd):
self.platform.launch_connection(self.device_cfg)
except Exception as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
exit(-1)
def do_show_cfg (self, line):
"""Outputs the loaded interface configuration"""
self.platform.get_if_manager().dump_if_config()
- print termstyle.green("*** End of interface configuration ***")
+ print(termstyle.green("*** End of interface configuration ***"))
def do_show_nat_cfg (self, line):
"""Outputs the loaded nat provided configuration"""
try:
self.platform.dump_obj_config('nat')
- print termstyle.green("*** End of nat configuration ***")
+ print(termstyle.green("*** End of nat configuration ***"))
except UserWarning as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_show_static_route_cfg (self, line):
"""Outputs the loaded static route configuration"""
try:
self.platform.dump_obj_config('static_route')
- print termstyle.green("*** End of static route configuration ***")
+ print(termstyle.green("*** End of static route configuration ***"))
except UserWarning as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_switch_cfg (self, cfg_file_path):
"""Switch the current platform interface configuration with another one"""
@@ -66,9 +66,9 @@ class InteractivePlatform(cmd.Cmd):
self.platform.load_platform_data_from_file(self.device_cfg)
if not self.virtual_mode:
self.platform.reload_connection(self.device_cfg)
- print termstyle.green("Configuration switching completed successfully.")
+ print(termstyle.green("Configuration switching completed successfully."))
else:
- print termstyle.magenta("Configuration file is missing. Please try again.")
+ print(termstyle.magenta("Configuration file is missing. Please try again."))
def do_load_clean (self, arg):
"""Loads a clean configuration file onto the platform
@@ -80,7 +80,7 @@ class InteractivePlatform(cmd.Cmd):
if len(in_val)==2:
self.platform.load_clean_config(in_val[0], in_val[1])
else:
- print termstyle.magenta("One of the config inputs is missing.")
+ print(termstyle.magenta("One of the config inputs is missing."))
else:
self.platform.load_clean_config()
# print termstyle.magenta("Configuration file definition is missing. use 'help load_clean' for further info.")
@@ -88,27 +88,27 @@ class InteractivePlatform(cmd.Cmd):
def do_basic_if_config(self, line):
"""Apply basic interfaces configuartion to all platform interfaces"""
self.platform.configure_basic_interfaces()
- print termstyle.green("Basic interfaces configuration applied successfully.")
+ print(termstyle.green("Basic interfaces configuration applied successfully."))
def do_pbr(self, line):
"""Apply IPv4 PBR configuration on all interfaces"""
self.platform.config_pbr()
- print termstyle.green("IPv4 PBR configuration applied successfully.")
+ print(termstyle.green("IPv4 PBR configuration applied successfully."))
def do_no_pbr(self, line):
"""Removes IPv4 PBR configuration from all interfaces"""
self.platform.config_no_pbr()
- print termstyle.green("IPv4 PBR configuration removed successfully.")
+ print(termstyle.green("IPv4 PBR configuration removed successfully."))
def do_nbar(self, line):
"""Apply NBAR PD configuration on all interfaces"""
self.platform.config_nbar_pd()
- print termstyle.green("NBAR configuration applied successfully.")
+ print(termstyle.green("NBAR configuration applied successfully."))
def do_no_nbar(self, line):
"""Removes NBAR PD configuration from all interfaces"""
self.platform.config_no_nbar_pd()
- print termstyle.green("NBAR configuration removed successfully.")
+ print(termstyle.green("NBAR configuration removed successfully."))
def do_static_route(self, arg):
"""Apply IPv4 static routing configuration on all interfaces
@@ -131,16 +131,16 @@ class InteractivePlatform(cmd.Cmd):
'server_destination_mask' : '255.0.0.0' }
stat_route_obj = CStaticRouteConfig(stat_route_dict)
self.platform.config_static_routing(stat_route_obj)
- print termstyle.green("IPv4 static routing configuration applied successfully.")
+ print(termstyle.green("IPv4 static routing configuration applied successfully."))
# print termstyle.magenta("Specific configutaion is missing. use 'help static_route' for further info.")
def do_no_static_route(self, line):
"""Removes IPv4 static route configuration from all non-duplicated interfaces"""
try:
self.platform.config_no_static_routing()
- print termstyle.green("IPv4 static routing configuration removed successfully.")
+ print(termstyle.green("IPv4 static routing configuration removed successfully."))
except UserWarning as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_nat(self, arg):
"""Apply NAT configuration on all non-duplicated interfaces
@@ -164,122 +164,122 @@ class InteractivePlatform(cmd.Cmd):
'pool_netmask' : '255.255.255.0' }
nat_obj = CNatConfig(nat_dict)
self.platform.config_nat(nat_obj)
- print termstyle.green("NAT configuration applied successfully.")
+ print(termstyle.green("NAT configuration applied successfully."))
def do_no_nat(self, arg):
"""Removes NAT configuration from all non-duplicated interfaces"""
try:
self.platform.config_no_nat()
- print termstyle.green("NAT configuration removed successfully.")
+ print(termstyle.green("NAT configuration removed successfully."))
except UserWarning as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_ipv6_pbr(self, line):
"""Apply IPv6 PBR configuration on all interfaces"""
self.platform.config_ipv6_pbr()
- print termstyle.green("IPv6 PBR configuration applied successfully.")
+ print(termstyle.green("IPv6 PBR configuration applied successfully."))
def do_no_ipv6_pbr(self, line):
"""Removes IPv6 PBR configuration from all interfaces"""
self.platform.config_no_ipv6_pbr()
- print termstyle.green("IPv6 PBR configuration removed successfully.")
+ print(termstyle.green("IPv6 PBR configuration removed successfully."))
def do_zbf(self, line):
"""Apply Zone-Based policy Firewall configuration on all interfaces"""
self.platform.config_zbf()
- print termstyle.green("Zone-Based policy Firewall configuration applied successfully.")
+ print(termstyle.green("Zone-Based policy Firewall configuration applied successfully."))
def do_no_zbf(self, line):
"""Removes Zone-Based policy Firewall configuration from all interfaces"""
self.platform.config_no_zbf()
- print termstyle.green("Zone-Based policy Firewall configuration removed successfully.")
+ print(termstyle.green("Zone-Based policy Firewall configuration removed successfully."))
def do_show_cpu_util(self, line):
"""Fetches CPU utilization stats from the platform"""
try:
- print self.platform.get_cpu_util()
- print termstyle.green("*** End of show_cpu_util output ***")
+ print(self.platform.get_cpu_util())
+ print(termstyle.green("*** End of show_cpu_util output ***"))
except PlatformResponseMissmatch as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_show_drop_stats(self, line):
"""Fetches packet drop stats from the platform.\nDrop are summed and presented for both input and output traffic of each interface"""
- print self.platform.get_drop_stats()
- print termstyle.green("*** End of show_drop_stats output ***")
+ print(self.platform.get_drop_stats())
+ print(termstyle.green("*** End of show_drop_stats output ***"))
def do_show_nbar_stats(self, line):
"""Fetches NBAR classification stats from the platform.\nStats are available both as raw data and as percentage data."""
try:
- print self.platform.get_nbar_stats()
- print termstyle.green("*** End of show_nbar_stats output ***")
+ print(self.platform.get_nbar_stats())
+ print(termstyle.green("*** End of show_nbar_stats output ***"))
except PlatformResponseMissmatch as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
def do_show_nat_stats(self, line):
"""Fetches NAT translations stats from the platform"""
- print self.platform.get_nat_stats()
- print termstyle.green("*** End of show_nat_stats output ***")
+ print(self.platform.get_nat_stats())
+ print(termstyle.green("*** End of show_nat_stats output ***"))
def do_show_cft_stats(self, line):
"""Fetches CFT stats from the platform"""
- print self.platform.get_cft_stats()
- print termstyle.green("*** End of show_sft_stats output ***")
+ print(self.platform.get_cft_stats())
+ print(termstyle.green("*** End of show_sft_stats output ***"))
def do_show_cvla_memory_usage(self, line):
"""Fetches CVLA memory usage stats from the platform"""
(res, res2) = self.platform.get_cvla_memory_usage()
- print res
- print res2
- print termstyle.green("*** End of show_cvla_memory_usage output ***")
+ print(res)
+ print(res2)
+ print(termstyle.green("*** End of show_cvla_memory_usage output ***"))
def do_clear_counters(self, line):
"""Clears interfaces counters"""
self.platform.clear_counters()
- print termstyle.green("*** clear counters completed ***")
+ print(termstyle.green("*** clear counters completed ***"))
def do_clear_nbar_stats(self, line):
"""Clears interfaces counters"""
self.platform.clear_nbar_stats()
- print termstyle.green("*** clear nbar stats completed ***")
+ print(termstyle.green("*** clear nbar stats completed ***"))
def do_clear_cft_counters(self, line):
"""Clears interfaces counters"""
self.platform.clear_cft_counters()
- print termstyle.green("*** clear cft counters completed ***")
+ print(termstyle.green("*** clear cft counters completed ***"))
def do_clear_drop_stats(self, line):
"""Clears interfaces counters"""
self.platform.clear_packet_drop_stats()
- print termstyle.green("*** clear packet drop stats completed ***")
+ print(termstyle.green("*** clear packet drop stats completed ***"))
def do_clear_nat_translations(self, line):
"""Clears nat translations"""
self.platform.clear_nat_translations()
- print termstyle.green("*** clear nat translations completed ***")
+ print(termstyle.green("*** clear nat translations completed ***"))
def do_set_tftp_server (self, line):
"""Configures TFTP access on platform"""
self.platform.config_tftp_server(self.device_cfg)
- print termstyle.green("*** TFTP config deployment completed ***")
+ print(termstyle.green("*** TFTP config deployment completed ***"))
def do_show_running_image (self, line):
"""Fetches currently loaded image of the platform"""
res = self.platform.get_running_image_details()
- print res
- print termstyle.green("*** Show running image completed ***")
+ print(res)
+ print(termstyle.green("*** Show running image completed ***"))
def do_check_image_existence(self, arg):
"""Check if specific image file (usually *.bin) is already stored in platform drive"""
if arg:
try:
res = self.platform.check_image_existence(arg.split(' ')[0])
- print res
- print termstyle.green("*** Check image existence completed ***")
+ print(res)
+ print(termstyle.green("*** Check image existence completed ***"))
except PlatformResponseAmbiguity as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
else:
- print termstyle.magenta("Please provide an image name in order to check for existance.")
+ print(termstyle.magenta("Please provide an image name in order to check for existance."))
def do_load_image (self, arg):
"""Loads a given image filename from tftp server (if not available on disk) and sets it as the boot image on the platform"""
@@ -287,9 +287,9 @@ class InteractivePlatform(cmd.Cmd):
try:
self.platform.load_platform_image('asr1001-universalk9.BLD_V155_2_S_XE315_THROTTLE_LATEST_20150324_100047-std.bin')#arg.split(' ')[0])
except UserWarning as inst:
- print termstyle.magenta(inst)
+ print(termstyle.magenta(inst))
else:
- print termstyle.magenta("Image filename is missing.")
+ print(termstyle.magenta("Image filename is missing."))
def do_reload (self, line):
"""Reloads the platform"""
@@ -298,9 +298,9 @@ class InteractivePlatform(cmd.Cmd):
if ans:
# user confirmed he wishes to reload the platform
self.platform.reload_platform(self.device_cfg)
- print termstyle.green("*** Platform reload completed ***")
+ print(termstyle.green("*** Platform reload completed ***"))
else:
- print termstyle.green("*** Platform reload aborted ***")
+ print(termstyle.green("*** Platform reload aborted ***"))
def do_quit(self, arg):
"""Quits the application"""
diff --git a/scripts/automation/regression/platform_cmd_link.py b/scripts/automation/regression/platform_cmd_link.py
index 247127ca..ceb0b1de 100755
--- a/scripts/automation/regression/platform_cmd_link.py
+++ b/scripts/automation/regression/platform_cmd_link.py
@@ -5,6 +5,7 @@ import CustomLogger
import misc_methods
import telnetlib
import socket
+import time
from collections import OrderedDict
class CCommandCache(object):
@@ -193,8 +194,8 @@ class CIfObj(object):
self.if_type = if_type
self.src_mac_addr = src_mac_addr
self.dest_mac_addr = dest_mac_addr
- self.ipv4_addr = ipv4_addr
- self.ipv6_addr = ipv6_addr
+ self.ipv4_addr = ipv4_addr
+ self.ipv6_addr = ipv6_addr
self.pair_parent = None # a pointer to CDualIfObj which holds this interface and its pair-complement
def __get_and_increment_id (self):
@@ -373,6 +374,23 @@ class AuthError(Exception):
class CIosTelnet(telnetlib.Telnet):
AuthError = AuthError
+
+ # wrapper for compatibility with Python2/3, convert input to bytes
+ def str_to_bytes_wrapper(self, func, text, *args, **kwargs):
+ if type(text) in (list, tuple):
+ text = [elem.encode('ascii') if type(elem) is str else elem for elem in text]
+ res = func(self, text.encode('ascii') if type(text) is str else text, *args, **kwargs)
+ return res.decode() if type(res) is bytes else res
+
+ def read_until(self, text, *args, **kwargs):
+ return self.str_to_bytes_wrapper(telnetlib.Telnet.read_until, text, *args, **kwargs)
+
+ def write(self, text, *args, **kwargs):
+ return self.str_to_bytes_wrapper(telnetlib.Telnet.write, text, *args, **kwargs)
+
+ def expect(self, text, *args, **kwargs):
+ return self.str_to_bytes_wrapper(telnetlib.Telnet.expect, text, *args, **kwargs)
+
def __init__ (self, host, line_pass, en_pass, port = 23, str_wait = "#"):
telnetlib.Telnet.__init__(self)
self.host = host
@@ -401,33 +419,33 @@ class CIosTelnet(telnetlib.Telnet):
except Exception as inst:
raise
- def write_ios_cmd (self, cmd_list, result_from = 0, timeout = 1, **kwargs):
+ def write_ios_cmd (self, cmd_list, result_from = 0, timeout = 10, **kwargs):
assert (isinstance (cmd_list, list) == True)
-
- if 'flush_first' in kwargs:
- self.read_until(self.pr, timeout) # clear any accumulated data in telnet session
+ self.read_until(self.pr, timeout = 1)
res = ''
- wf = ''
if 'read_until' in kwargs:
wf = kwargs['read_until']
else:
wf = self.pr
+ start_time = time.time()
for idx, cmd in enumerate(cmd_list):
self.write(cmd+'\r\n')
if idx < result_from:
# don't care for return string
if type(wf) is list:
- self.expect(wf, timeout)[2]
+ self.expect(wf, timeout = 3)[2]
else:
- self.read_until(wf, timeout)
+ self.read_until(wf, timeout = 3)
else:
# care for return string
if type(wf) is list:
- res += self.expect(wf, timeout)[2]
+ res += self.expect(wf, timeout = 3)[2]
else:
- res += self.read_until(wf, timeout)
+ res += self.read_until(wf, timeout = 3)
+ if time.time() - start_time >= timeout:
+ raise Exception('A timeout error has occured at command %s' % cmd_list)
# return res.split('\r\n')
return res # return the received response as a string, each line is seperated by '\r\n'.
diff --git a/scripts/automation/regression/stateful_tests/tests_exceptions.py b/scripts/automation/regression/stateful_tests/tests_exceptions.py
index 604efcc8..360f44a5 100755
--- a/scripts/automation/regression/stateful_tests/tests_exceptions.py
+++ b/scripts/automation/regression/stateful_tests/tests_exceptions.py
@@ -1,37 +1,37 @@
#!/router/bin/python
class TRexInUseError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
class TRexRunFailedError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
class TRexIncompleteRunError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
class TRexLowCpuUtilError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
class AbnormalResultError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
class ClassificationMissmatchError(Exception):
- def __init__(self, value):
- self.value = value
- def __str__(self):
- return repr(self.value)
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
diff --git a/scripts/automation/regression/stateful_tests/trex_client_pkg_test.py b/scripts/automation/regression/stateful_tests/trex_client_pkg_test.py
index e2040e73..4ad7fba3 100755
--- a/scripts/automation/regression/stateful_tests/trex_client_pkg_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_client_pkg_test.py
@@ -1,5 +1,5 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test, CTRexScenario
+from .trex_general_test import CTRexGeneral_Test, CTRexScenario
from misc_methods import run_command
from nose.plugins.attrib import attr
diff --git a/scripts/automation/regression/stateful_tests/trex_general_test.py b/scripts/automation/regression/stateful_tests/trex_general_test.py
index 7eae3224..1a44970a 100755
--- a/scripts/automation/regression/stateful_tests/trex_general_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_general_test.py
@@ -34,7 +34,7 @@ import os
from CPlatform import *
import termstyle
import threading
-from tests_exceptions import *
+from .tests_exceptions import *
from platform_cmd_link import *
import unittest
from glob import glob
@@ -77,11 +77,11 @@ class CTRexGeneral_Test(unittest.TestCase):
CTRexScenario.router.load_platform_data_from_file(device_cfg)
CTRexScenario.router.launch_connection(device_cfg)
running_image = CTRexScenario.router.get_running_image_details()['image']
- print 'Current router image: %s' % running_image
+ print('Current router image: %s' % running_image)
if CTRexScenario.router_cfg['forceImageReload']:
needed_image = device_cfg.get_image_name()
if not CTRexScenario.router.is_image_matches(needed_image):
- print 'Setting router image: %s' % needed_image
+ print('Setting router image: %s' % needed_image)
CTRexScenario.router.config_tftp_server(device_cfg)
CTRexScenario.router.load_platform_image(needed_image)
CTRexScenario.router.set_boot_image(needed_image)
@@ -91,14 +91,14 @@ class CTRexGeneral_Test(unittest.TestCase):
if not CTRexScenario.router.is_image_matches(needed_image):
self.fail('Unable to set router image: %s, current image is: %s' % (needed_image, running_image))
else:
- print 'Matches needed image: %s' % needed_image
+ print('Matches needed image: %s' % needed_image)
CTRexScenario.router_image = running_image
if self.modes:
- print termstyle.green('\t!!!\tRunning with modes: %s, not suitable tests will be skipped.\t!!!' % list(self.modes))
+ print(termstyle.green('\t!!!\tRunning with modes: %s, not suitable tests will be skipped.\t!!!' % list(self.modes)))
CTRexScenario.is_init = True
- print termstyle.green("Done instantiating T-Rex scenario!\n")
+ print(termstyle.green("Done instantiating T-Rex scenario!\n"))
# raise RuntimeError('CTRexScenario class is not initialized!')
self.router = CTRexScenario.router
@@ -155,11 +155,11 @@ class CTRexGeneral_Test(unittest.TestCase):
trex_tx_bps = trex_res.get_last_value("trex-global.data.m_total_tx_bytes")
test_norm_cpu = 100.0*(trex_tx_bps/(cores*cpu_util))/1e6
- print "TRex CPU utilization: %g%%, norm_cpu is : %d Mb/core" % (round(cpu_util), int(test_norm_cpu))
+ print("TRex CPU utilization: %g%%, norm_cpu is : %d Mb/core" % (round(cpu_util), int(test_norm_cpu)))
#expected_norm_cpu = self.get_benchmark_param('cpu_to_core_ratio')
- #calc_error_precent = abs(100.0*(test_norm_cpu/expected_norm_cpu)-100.0)
+ #calc_error_precent = abs(100.0*(test_norm_cpu/expected_norm_cpu)-100.0)
# if calc_error_precent > err:
# msg ='Normalized bandwidth to CPU utilization ratio is %2.0f Mb/core expected %2.0f Mb/core more than %2.0f %% - ERROR' % (test_norm_cpu, expected_norm_cpu, err)
@@ -256,8 +256,8 @@ class CTRexGeneral_Test(unittest.TestCase):
# check for trex-router packet consistency
# TODO: check if it's ok
- print 'router drop stats: %s' % pkt_drop_stats
- print 'TRex drop stats: %s' % trex_drops
+ print('router drop stats: %s' % pkt_drop_stats)
+ print('TRex drop stats: %s' % trex_drops)
#self.assertEqual(pkt_drop_stats, trex_drops, "TRex's and router's drop stats don't match.")
except KeyError as e:
@@ -285,12 +285,12 @@ class CTRexGeneral_Test(unittest.TestCase):
# We encountered error, don't fail the test immediately
def fail(self, reason = 'Unknown error'):
- print 'Error: %s' % reason
+ print('Error: %s' % reason)
self.fail_reasons.append(reason)
# skip running of the test, counts as 'passed' but prints 'skipped'
def skip(self, message = 'Unknown reason'):
- print 'Skip: %s' % message
+ print('Skip: %s' % message)
self.skipping = True
raise SkipTest(message)
@@ -303,10 +303,10 @@ class CTRexGeneral_Test(unittest.TestCase):
if test_setup_modes_conflict:
self.skip("The test can't run with following modes of given setup: %s " % test_setup_modes_conflict)
if self.trex and not self.trex.is_idle():
- print 'Warning: TRex is not idle at setUp, trying to stop it.'
+ print('Warning: TRex is not idle at setUp, trying to stop it.')
self.trex.force_kill(confirm = False)
if not self.is_loopback:
- print ''
+ print('')
if self.trex: # stateful
self.router.load_clean_config()
self.router.clear_counters()
@@ -322,24 +322,24 @@ class CTRexGeneral_Test(unittest.TestCase):
# assert CTRexScenario.is_init == True
def tearDown(self):
if self.trex and not self.trex.is_idle():
- print 'Warning: TRex is not idle at tearDown, trying to stop it.'
+ print('Warning: TRex is not idle at tearDown, trying to stop it.')
self.trex.force_kill(confirm = False)
if not self.skipping:
# print server logs of test run
if self.trex and CTRexScenario.server_logs:
try:
- print termstyle.green('\n>>>>>>>>>>>>>>> Daemon log <<<<<<<<<<<<<<<')
+ print(termstyle.green('\n>>>>>>>>>>>>>>> Daemon log <<<<<<<<<<<<<<<'))
daemon_log = self.trex.get_trex_daemon_log()
log_size = len(daemon_log)
- print ''.join(daemon_log[CTRexScenario.daemon_log_lines:])
+ print(''.join(daemon_log[CTRexScenario.daemon_log_lines:]))
CTRexScenario.daemon_log_lines = log_size
except Exception as e:
- print "Can't get TRex daemon log:", e
+ print("Can't get TRex daemon log:", e)
try:
- print termstyle.green('>>>>>>>>>>>>>>>> Trex log <<<<<<<<<<<<<<<<')
- print ''.join(self.trex.get_trex_log())
+ print(termstyle.green('>>>>>>>>>>>>>>>> Trex log <<<<<<<<<<<<<<<<'))
+ print(''.join(self.trex.get_trex_log()))
except Exception as e:
- print "Can't get TRex log:", e
+ print("Can't get TRex log:", e)
if len(self.fail_reasons):
raise Exception('The test is failed, reasons:\n%s' % '\n'.join(self.fail_reasons))
diff --git a/scripts/automation/regression/stateful_tests/trex_imix_test.py b/scripts/automation/regression/stateful_tests/trex_imix_test.py
index c93480c3..e7c27cc7 100755
--- a/scripts/automation/regression/stateful_tests/trex_imix_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_imix_test.py
@@ -1,7 +1,7 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test
+from .trex_general_test import CTRexGeneral_Test
from CPlatform import CStaticRouteConfig
-from tests_exceptions import *
+from .tests_exceptions import *
#import sys
import time
from nose.tools import nottest
@@ -11,7 +11,6 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
def __init__(self, *args, **kwargs):
# super(CTRexIMIX_Test, self).__init__()
CTRexGeneral_Test.__init__(self, *args, **kwargs)
- pass
def setUp(self):
super(CTRexIMIX_Test, self).setUp() # launch super test class setUp process
@@ -43,8 +42,8 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res)
@@ -62,7 +61,7 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
trex_development = True)
trex_res = self.trex.sample_to_run_finish()
- print trex_res
+ print(trex_res)
def test_routing_imix (self):
# test initializtion
@@ -87,8 +86,8 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
@@ -123,10 +122,10 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
- print ("\nLATEST DUMP:")
- print trex_res.get_latest_dump()
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
+ print("\nLATEST DUMP:")
+ print(trex_res.get_latest_dump())
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res)
@@ -157,8 +156,8 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
# trex_res is a CTRexResults instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
@@ -186,8 +185,8 @@ class CTRexIMIX_Test(CTRexGeneral_Test):
# trex_res is a CTRexResults instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res, minimal_cpu = 0, maximal_cpu = 10)
diff --git a/scripts/automation/regression/stateful_tests/trex_ipv6_test.py b/scripts/automation/regression/stateful_tests/trex_ipv6_test.py
index bffb4754..6aba9ae0 100755
--- a/scripts/automation/regression/stateful_tests/trex_ipv6_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_ipv6_test.py
@@ -1,14 +1,13 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test
-from tests_exceptions import *
+from .trex_general_test import CTRexGeneral_Test
+from .tests_exceptions import *
import time
from nose.tools import assert_equal
class CTRexIPv6_Test(CTRexGeneral_Test):
"""This class defines the IPv6 testcase of the T-Rex traffic generator"""
def __init__(self, *args, **kwargs):
- super(CTRexIPv6_Test, self).__init__(*args, **kwargs)
- pass
+ super(CTRexIPv6_Test, self).__init__(*args, **kwargs)
def setUp(self):
super(CTRexIPv6_Test, self).setUp() # launch super test class setUp process
@@ -43,8 +42,8 @@ class CTRexIPv6_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
@@ -80,8 +79,8 @@ class CTRexIPv6_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
trex_tx_pckt = float(trex_res.get_last_value("trex-global.data.m_total_tx_pkts"))
trex_drops = int(trex_res.get_total_drops())
@@ -95,7 +94,7 @@ class CTRexIPv6_Test(CTRexGeneral_Test):
def tearDown(self):
CTRexGeneral_Test.tearDown(self)
- # remove config here
+ # remove config here
pass
if __name__ == "__main__":
diff --git a/scripts/automation/regression/stateful_tests/trex_nat_test.py b/scripts/automation/regression/stateful_tests/trex_nat_test.py
index e429bc17..512ad4e4 100755
--- a/scripts/automation/regression/stateful_tests/trex_nat_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_nat_test.py
@@ -1,6 +1,6 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test
-from tests_exceptions import *
+from .trex_general_test import CTRexGeneral_Test
+from .tests_exceptions import *
import time
from CPlatform import CStaticRouteConfig, CNatConfig
from nose.tools import assert_equal
@@ -9,13 +9,11 @@ from nose.tools import assert_equal
class CTRexNoNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
"""This class defines the NAT testcase of the T-Rex traffic generator"""
def __init__(self, *args, **kwargs):
- super(CTRexNoNat_Test, self).__init__(*args, **kwargs)
+ super(CTRexNoNat_Test, self).__init__(*args, **kwargs)
self.unsupported_modes = ['loopback'] # NAT requires device
- pass
def setUp(self):
super(CTRexNoNat_Test, self).setUp() # launch super test class setUp process
- pass
def check_nat_stats (self, nat_stats):
pass
@@ -46,10 +44,10 @@ class CTRexNoNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
- print ("\nLATEST DUMP:")
- print trex_res.get_latest_dump()
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
+ print("\nLATEST DUMP:")
+ print(trex_res.get_latest_dump())
expected_nat_opened = self.get_benchmark_param('nat_opened')
@@ -77,9 +75,8 @@ class CTRexNoNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
class CTRexNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
"""This class defines the NAT testcase of the T-Rex traffic generator"""
def __init__(self, *args, **kwargs):
- super(CTRexNat_Test, self).__init__(*args, **kwargs)
+ super(CTRexNat_Test, self).__init__(*args, **kwargs)
self.unsupported_modes = ['loopback'] # NAT requires device
- pass
def setUp(self):
super(CTRexNat_Test, self).setUp() # launch super test class setUp process
@@ -124,10 +121,10 @@ class CTRexNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
- print ("\nLATEST DUMP:")
- print trex_res.get_latest_dump()
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
+ print("\nLATEST DUMP:")
+ print(trex_res.get_latest_dump())
trex_nat_stats = trex_res.get_last_value("trex-global.data", ".*nat.*") # extract all nat data
if self.get_benchmark_param('allow_timeout_dev'):
@@ -153,7 +150,7 @@ class CTRexNat_Test(CTRexGeneral_Test):#(unittest.TestCase):
# raiseraise AbnormalResultError('Normalized bandwidth to CPU utilization ratio exceeds 3%')
nat_stats = self.router.get_nat_stats()
- print nat_stats
+ print(nat_stats)
self.assert_gt(nat_stats['total_active_trans'], 5000, 'total active translations is not high enough')
self.assert_gt(nat_stats['dynamic_active_trans'], 5000, 'total dynamic active translations is not high enough')
diff --git a/scripts/automation/regression/stateful_tests/trex_nbar_test.py b/scripts/automation/regression/stateful_tests/trex_nbar_test.py
index 1453c02b..69c3f605 100755
--- a/scripts/automation/regression/stateful_tests/trex_nbar_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_nbar_test.py
@@ -1,6 +1,6 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test
-from tests_exceptions import *
+from .trex_general_test import CTRexGeneral_Test
+from .tests_exceptions import *
from interfaces_e import IFType
from nose.tools import nottest
from misc_methods import print_r
@@ -8,9 +8,8 @@ from misc_methods import print_r
class CTRexNbar_Test(CTRexGeneral_Test):
"""This class defines the NBAR testcase of the T-Rex traffic generator"""
def __init__(self, *args, **kwargs):
- super(CTRexNbar_Test, self).__init__(*args, **kwargs)
+ super(CTRexNbar_Test, self).__init__(*args, **kwargs)
self.unsupported_modes = ['loopback'] # obviously no NBar in loopback
- pass
def setUp(self):
super(CTRexNbar_Test, self).setUp() # launch super test class setUp process
@@ -21,8 +20,8 @@ class CTRexNbar_Test(CTRexGeneral_Test):
def match_classification (self):
nbar_benchmark = self.get_benchmark_param("nbar_classification")
test_classification = self.router.get_nbar_stats()
- print "TEST CLASSIFICATION:"
- print test_classification
+ print("TEST CLASSIFICATION:")
+ print(test_classification)
missmatchFlag = False
missmatchMsg = "NBAR classification contians a missmatch on the following protocols:"
fmt = '\n\t{0:15} | Expected: {1:>3.2f}%, Got: {2:>3.2f}%'
@@ -31,7 +30,7 @@ class CTRexNbar_Test(CTRexGeneral_Test):
for cl_intf in self.router.get_if_manager().get_if_list(if_type = IFType.Client):
client_intf = cl_intf.get_name()
- for protocol, bench in nbar_benchmark.iteritems():
+ for protocol, bench in nbar_benchmark.items():
if protocol != 'total':
try:
bench = float(bench)
@@ -44,11 +43,11 @@ class CTRexNbar_Test(CTRexGeneral_Test):
missmatchMsg += fmt.format(protocol, bench, protocol_test_res)
except KeyError as e:
missmatchFlag = True
- print e
- print "Changes missmatchFlag to True. ", "\n\tProtocol {0} isn't part of classification results on interface {intf}".format( protocol, intf = client_intf )
+ print(e)
+ print("Changes missmatchFlag to True. ", "\n\tProtocol {0} isn't part of classification results on interface {intf}".format( protocol, intf = client_intf ))
missmatchMsg += "\n\tProtocol {0} isn't part of classification results on interface {intf}".format( protocol, intf = client_intf )
except ZeroDivisionError as e:
- print "ZeroDivisionError: %s" % protocol
+ print("ZeroDivisionError: %s" % protocol)
pass
if missmatchFlag:
self.fail(missmatchMsg)
@@ -78,10 +77,10 @@ class CTRexNbar_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
- print ("\nLATEST DUMP:")
- print trex_res.get_latest_dump()
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
+ print("\nLATEST DUMP:")
+ print(trex_res.get_latest_dump())
self.check_general_scenario_results(trex_res, check_latency = False) # NBAR can cause latency
@@ -89,16 +88,16 @@ class CTRexNbar_Test(CTRexGeneral_Test):
trex_tx_pckt = trex_res.get_last_value("trex-global.data.m_total_tx_pkts")
cpu_util = trex_res.get_last_value("trex-global.data.m_cpu_util")
cpu_util_hist = trex_res.get_value_list("trex-global.data.m_cpu_util")
- print "cpu util is:", cpu_util
- print cpu_util_hist
+ print("cpu util is:", cpu_util)
+ print(cpu_util_hist)
test_norm_cpu = 2 * trex_tx_pckt / (core * cpu_util)
- print "test_norm_cpu is:", test_norm_cpu
+ print("test_norm_cpu is:", test_norm_cpu)
if self.get_benchmark_param('cpu2core_custom_dev'):
# check this test by custom deviation
deviation_compare_value = self.get_benchmark_param('cpu2core_dev')
- print "Comparing test with custom deviation value- {dev_val}%".format( dev_val = int(deviation_compare_value*100) )
+ print("Comparing test with custom deviation value- {dev_val}%".format( dev_val = int(deviation_compare_value*100) ))
# need to be fixed !
#if ( abs((test_norm_cpu/self.get_benchmark_param('cpu_to_core_ratio')) - 1) > deviation_compare_value):
@@ -134,10 +133,10 @@ class CTRexNbar_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
- print ("\nLATEST DUMP:")
- print trex_res.get_latest_dump()
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
+ print("\nLATEST DUMP:")
+ print(trex_res.get_latest_dump())
self.check_general_scenario_results(trex_res)
@@ -170,8 +169,8 @@ class CTRexNbar_Test(CTRexGeneral_Test):
# trex_res is a CTRexResult instance- and contains the summary of the test results
# you may see all the results keys by simply calling here for 'print trex_res.result'
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res, check_latency = False)
diff --git a/scripts/automation/regression/stateful_tests/trex_rx_test.py b/scripts/automation/regression/stateful_tests/trex_rx_test.py
index 37b1c722..2f0a24f4 100755
--- a/scripts/automation/regression/stateful_tests/trex_rx_test.py
+++ b/scripts/automation/regression/stateful_tests/trex_rx_test.py
@@ -1,7 +1,7 @@
#!/router/bin/python
-from trex_general_test import CTRexGeneral_Test
+from .trex_general_test import CTRexGeneral_Test
from CPlatform import CStaticRouteConfig, CNatConfig
-from tests_exceptions import *
+from .tests_exceptions import *
#import sys
import time
import copy
@@ -13,11 +13,9 @@ class CTRexRx_Test(CTRexGeneral_Test):
def __init__(self, *args, **kwargs):
CTRexGeneral_Test.__init__(self, *args, **kwargs)
self.unsupported_modes = ['virt_nics'] # TODO: fix
- pass
def setUp(self):
CTRexGeneral_Test.setUp(self)
- pass
def check_rx_errors(self, trex_res, allow_error_tolerance = True):
@@ -58,9 +56,9 @@ class CTRexRx_Test(CTRexGeneral_Test):
raise AbnormalResultError('No TRex results by path: %s' % path)
- print 'Total packets checked: %s' % total_rx
- print 'Latency counters: %s' % latency_counters_display
- print 'rx_check counters: %s' % rx_counters
+ print('Total packets checked: %s' % total_rx)
+ print('Latency counters: %s' % latency_counters_display)
+ print('rx_check counters: %s' % rx_counters)
except KeyError as e:
self.fail('Expected key in TRex result was not found.\n%s' % traceback.print_exc())
@@ -77,11 +75,11 @@ class CTRexRx_Test(CTRexGeneral_Test):
if self.is_loopback or error_percentage > error_tolerance:
self.fail('Too much errors in rx_check. (~%s%% of traffic)' % error_percentage)
else:
- print 'There are errors in rx_check (%f%%), not exceeding allowed limit (%s%%)' % (error_percentage, error_tolerance)
+ print('There are errors in rx_check (%f%%), not exceeding allowed limit (%s%%)' % (error_percentage, error_tolerance))
else:
- print 'No errors in rx_check.'
+ print('No errors in rx_check.')
except Exception as e:
- print traceback.print_exc()
+ print(traceback.print_exc())
self.fail('Errors in rx_check: %s' % e)
def test_rx_check_sfr(self):
@@ -108,8 +106,8 @@ class CTRexRx_Test(CTRexGeneral_Test):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
#print ("\nLATEST DUMP:")
#print trex_res.get_latest_dump()
@@ -144,8 +142,8 @@ class CTRexRx_Test(CTRexGeneral_Test):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res)
@@ -176,8 +174,8 @@ class CTRexRx_Test(CTRexGeneral_Test):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
#print ("\nLATEST DUMP:")
#print trex_res.get_latest_dump()
@@ -210,8 +208,8 @@ class CTRexRx_Test(CTRexGeneral_Test):
trex_res = self.trex.sample_to_run_finish()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res)
@@ -241,15 +239,15 @@ class CTRexRx_Test(CTRexGeneral_Test):
learn_verify = True,
l_pkt_mode = 2)
- print 'Run for 40 seconds, expect no errors'
+ print('Run for 40 seconds, expect no errors')
trex_res = self.trex.sample_x_seconds(40)
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_general_scenario_results(trex_res)
self.check_CPU_benchmark(trex_res)
self.check_rx_errors(trex_res)
- print 'Run until finish, expect errors'
+ print('Run until finish, expect errors')
old_errors = copy.deepcopy(self.fail_reasons)
nat_dict = self.get_benchmark_param('nat_dict', test_name = 'test_nat_simple')
nat_obj = CNatConfig(nat_dict)
@@ -258,13 +256,13 @@ class CTRexRx_Test(CTRexGeneral_Test):
trex_res = self.trex.sample_to_run_finish()
self.router.config_no_zbf()
self.router.clear_nat_translations()
- print ("\nLATEST RESULT OBJECT:")
- print trex_res
+ print("\nLATEST RESULT OBJECT:")
+ print(trex_res)
self.check_rx_errors(trex_res, allow_error_tolerance = False)
if self.fail_reasons == old_errors:
self.fail('Expected errors here, got none.')
else:
- print 'Got errors as expected.'
+ print('Got errors as expected.')
self.fail_reasons = old_errors
def tearDown(self):
diff --git a/scripts/automation/regression/stateless_tests/stl_client_test.py b/scripts/automation/regression/stateless_tests/stl_client_test.py
index 2611fb66..6308e203 100644
--- a/scripts/automation/regression/stateless_tests/stl_client_test.py
+++ b/scripts/automation/regression/stateless_tests/stl_client_test.py
@@ -1,5 +1,5 @@
#!/router/bin/python
-from stl_general_test import CStlGeneral_Test, CTRexScenario
+from .stl_general_test import CStlGeneral_Test, CTRexScenario
from trex_stl_lib.api import *
import os, sys
import glob
diff --git a/scripts/automation/regression/stateless_tests/stl_examples_test.py b/scripts/automation/regression/stateless_tests/stl_examples_test.py
index 9e4fffc9..3f7d7b87 100755
--- a/scripts/automation/regression/stateless_tests/stl_examples_test.py
+++ b/scripts/automation/regression/stateless_tests/stl_examples_test.py
@@ -1,5 +1,5 @@
#!/router/bin/python
-from stl_general_test import CStlGeneral_Test, CTRexScenario
+from .stl_general_test import CStlGeneral_Test, CTRexScenario
import os, sys
from misc_methods import run_command
@@ -28,6 +28,3 @@ class STLExamples_Test(CStlGeneral_Test):
return_code, stdout, stderr = run_command("sh -c 'cd %s; %s %s -s %s'" % (examples_dir, sys.executable, example, CTRexScenario.configuration.trex['trex_name']))
assert return_code == 0, 'example %s failed.\nstdout: %s\nstderr: %s' % (return_code, stdout, stderr)
- def test_stl_examples1(self):
- print 'in test_stl_examples1'
-
diff --git a/scripts/automation/regression/stateless_tests/stl_general_test.py b/scripts/automation/regression/stateless_tests/stl_general_test.py
index 64e93510..54388121 100644
--- a/scripts/automation/regression/stateless_tests/stl_general_test.py
+++ b/scripts/automation/regression/stateless_tests/stl_general_test.py
@@ -28,11 +28,11 @@ class CStlGeneral_Test(CTRexGeneral_Test):
sys.stdout.write('.')
sys.stdout.flush()
self.stl_trex.connect()
- print ''
+ print('')
return True
except:
time.sleep(1)
- print ''
+ print('')
return False
def map_ports(self, timeout = 5):
@@ -42,10 +42,10 @@ class CStlGeneral_Test(CTRexGeneral_Test):
sys.stdout.flush()
CTRexScenario.stl_ports_map = stl_map_ports(self.stl_trex)
if self.verify_bidirectional(CTRexScenario.stl_ports_map):
- print ''
+ print('')
return True
time.sleep(1)
- print ''
+ print('')
return False
# verify all the ports are bidirectional
@@ -82,5 +82,5 @@ class STLBasic_Test(CStlGeneral_Test):
CTRexScenario.stl_init_error = err
if not self.map_ports():
self.fail(err)
- print 'Got ports mapping: %s' % CTRexScenario.stl_ports_map
+ print('Got ports mapping: %s' % CTRexScenario.stl_ports_map)
CTRexScenario.stl_init_error = None
diff --git a/scripts/automation/regression/stateless_tests/stl_rx_test.py b/scripts/automation/regression/stateless_tests/stl_rx_test.py
index bb682b6c..c55ee13e 100644
--- a/scripts/automation/regression/stateless_tests/stl_rx_test.py
+++ b/scripts/automation/regression/stateless_tests/stl_rx_test.py
@@ -1,5 +1,5 @@
#!/router/bin/python
-from stl_general_test import CStlGeneral_Test, CTRexScenario
+from .stl_general_test import CStlGeneral_Test, CTRexScenario
from trex_stl_lib.api import *
import os, sys
@@ -86,7 +86,7 @@ class STLRX_Test(CStlGeneral_Test):
# add both streams to ports
self.c.add_streams([s1], ports = [self.tx_port])
- print "\ninjecting {0} packets on port {1}\n".format(total_pkts, self.tx_port)
+ print("\ninjecting {0} packets on port {1}\n".format(total_pkts, self.tx_port))
exp = {'pg_id': 5, 'total_pkts': total_pkts, 'pkt_len': self.pkt.get_pkt_len()}
@@ -148,7 +148,7 @@ class STLRX_Test(CStlGeneral_Test):
exp = {'pg_id': 5, 'total_pkts': total_pkts, 'pkt_len': self.pkt.get_pkt_len()}
for i in range(0, 10):
- print "starting iteration {0}".format(i)
+ print("starting iteration {0}".format(i))
self.__rx_iteration( [exp] )
diff --git a/scripts/automation/regression/stateless_tests/trex_client_pkg_test.py b/scripts/automation/regression/stateless_tests/trex_client_pkg_test.py
index 6e2de230..64d5000e 100755
--- a/scripts/automation/regression/stateless_tests/trex_client_pkg_test.py
+++ b/scripts/automation/regression/stateless_tests/trex_client_pkg_test.py
@@ -1,5 +1,5 @@
#!/router/bin/python
-from stl_general_test import CStlGeneral_Test, CTRexScenario
+from .stl_general_test import CStlGeneral_Test, CTRexScenario
from misc_methods import run_command
from nose.plugins.attrib import attr
diff --git a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
index 9ca13e17..4fd1e4c7 100755
--- a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
+++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py
@@ -592,7 +592,10 @@ class CTRexClient(object):
"""
try:
- return binascii.a2b_base64(self.server.get_trex_daemon_log())
+ res = binascii.a2b_base64(self.server.get_trex_daemon_log())
+ if type(res) is bytes:
+ return res.decode()
+ return res
except AppError as err:
self._handle_AppError_exception(err.args[0])
except ProtocolError:
@@ -613,7 +616,10 @@ class CTRexClient(object):
"""
try:
- return binascii.a2b_base64(self.server.get_trex_log())
+ res = binascii.a2b_base64(self.server.get_trex_log())
+ if type(res) is bytes:
+ return res.decode()
+ return res
except AppError as err:
self._handle_AppError_exception(err.args[0])
except ProtocolError:
@@ -636,7 +642,10 @@ class CTRexClient(object):
try:
version_dict = OrderedDict()
- result_lines = binascii.a2b_base64(self.server.get_trex_version()).split('\n')
+ res = binascii.a2b_base64(self.server.get_trex_version())
+ if type(res) is bytes:
+ res = res.decode()
+ result_lines = res.split('\n')
for line in result_lines:
if not line:
continue
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
index 9518852f..45f3dd45 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
@@ -172,23 +172,12 @@ import sys
import os
import socket
import copy
-from collections import defaultdict, OrderedDict
+from collections import defaultdict
from .api import *
from .trex_stl_types import *
from .utils.common import get_number
-class LRU_cache(OrderedDict):
- def __init__(self, maxlen = 20, *args, **kwargs):
- OrderedDict.__init__(self, *args, **kwargs)
- self.maxlen = maxlen
-
- def __setitem__(self, *args, **kwargs):
- OrderedDict.__setitem__(self, *args, **kwargs)
- if len(self) > self.maxlen:
- self.popitem(last = False)
-
-
class HLT_ERR(dict):
def __init__(self, log = 'Unknown error', **kwargs):
dict.__init__(self, {'status': 0})
@@ -1078,7 +1067,7 @@ def generate_packet(**user_kwargs):
if ip_tos < 0 or ip_tos > 255:
raise STLError('TOS %s is not in range 0-255' % ip_tos)
l3_layer = IP(tos = ip_tos,
- len = kwargs['l3_length'],
+ #len = kwargs['l3_length'], don't let user create corrupt packets
id = kwargs['ip_id'],
frag = kwargs['ip_fragment_offset'],
ttl = kwargs['ip_ttl'],
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
index f0ac5c33..e182f5ea 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
@@ -200,7 +200,7 @@ class CTRexInfoGenerator(object):
@staticmethod
def _get_rational_block_char(value, range_start, interval):
# in Konsole, utf-8 is sometimes printed with artifacts, return ascii for now
- return 'X' if value >= range_start + float(interval) / 2 else ' '
+ #return 'X' if value >= range_start + float(interval) / 2 else ' '
value -= range_start
ratio = float(value) / interval
if ratio <= 0.0625:
@@ -225,8 +225,8 @@ class CTRexInfoGenerator(object):
relevant_port = self.__get_relevant_ports(port_id_list)[0]
hist_len = len(relevant_port.port_stats.history)
hist_maxlen = relevant_port.port_stats.history.maxlen
- util_tx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['m_percentage']) for i in range(hist_len)]
- util_rx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['m_rx_percentage']) for i in range(hist_len)]
+ util_tx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['tx_percentage']) for i in range(hist_len)]
+ util_rx_hist = [0] * (hist_maxlen - hist_len) + [round(relevant_port.port_stats.history[i]['rx_percentage']) for i in range(hist_len)]
stats_table = text_tables.TRexTextTable()
@@ -239,7 +239,7 @@ class CTRexInfoGenerator(object):
stats_table.add_row([y, ''.join([self._get_rational_block_char(util_tx, y, 5) for util_tx in util_tx_hist]),
''.join([self._get_rational_block_char(util_rx, y, 5) for util_rx in util_rx_hist])])
- return {"port_statistics": ExportableStats({}, stats_table)}
+ return {"port_graph": ExportableStats({}, stats_table)}
def _generate_port_stats(self, port_id_list):
relevant_ports = self.__get_relevant_ports(port_id_list)
@@ -414,7 +414,7 @@ class CTRexStats(object):
self.reference_stats = {}
self.latest_stats = {}
self.last_update_ts = time.time()
- self.history = deque(maxlen = 30)
+ self.history = deque(maxlen = 47)
self.lock = threading.Lock()
self.has_baseline = False
@@ -723,12 +723,24 @@ class CPortStats(CTRexStats):
pps = snapshot.get("m_total_tx_pps")
rx_bps = snapshot.get("m_total_rx_bps")
rx_pps = snapshot.get("m_total_rx_pps")
+ ts_diff = 0.5 # TODO: change this to real ts diff from server
bps_L1 = calc_bps_L1(bps, pps)
- rx_bps_L1 = calc_bps_L1(rx_bps, rx_pps)
+ bps_rx_L1 = calc_bps_L1(rx_bps, rx_pps)
snapshot['m_total_tx_bps_L1'] = bps_L1
snapshot['m_percentage'] = (bps_L1 / self._port_obj.get_speed_bps()) * 100
- snapshot['m_rx_percentage'] = (rx_bps_L1 / self._port_obj.get_speed_bps()) * 100
+
+ # TX line util not smoothed
+ diff_tx_pkts = snapshot.get('opackets', 0) - self.latest_stats.get('opackets', 0)
+ diff_tx_bytes = snapshot.get('obytes', 0) - self.latest_stats.get('obytes', 0)
+ tx_bps_L1 = calc_bps_L1(8.0 * diff_tx_bytes / ts_diff, float(diff_tx_pkts) / ts_diff)
+ snapshot['tx_percentage'] = 100.0 * tx_bps_L1 / self._port_obj.get_speed_bps()
+
+ # RX line util not smoothed
+ diff_rx_pkts = snapshot.get('ipackets', 0) - self.latest_stats.get('ipackets', 0)
+ diff_rx_bytes = snapshot.get('ibytes', 0) - self.latest_stats.get('ibytes', 0)
+ rx_bps_L1 = calc_bps_L1(8.0 * diff_rx_bytes / ts_diff, float(diff_rx_pkts) / ts_diff)
+ snapshot['rx_percentage'] = 100.0 * rx_bps_L1 / self._port_obj.get_speed_bps()
# simple...
self.latest_stats = snapshot
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 f6718fda..d84af22f 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,5 +1,5 @@
-from collections import namedtuple
+from collections import namedtuple, OrderedDict
from .utils.text_opts import *
from .trex_stl_exceptions import *
import types
@@ -157,3 +157,12 @@ class StatNotAvailable(object):
def __cmp__(self, *args, **kwargs):
raise Exception("Stat '%s' not available at this setup" % self.stat_name)
+class LRU_cache(OrderedDict):
+ def __init__(self, maxlen = 20, *args, **kwargs):
+ OrderedDict.__init__(self, *args, **kwargs)
+ self.maxlen = maxlen
+
+ def __setitem__(self, *args, **kwargs):
+ OrderedDict.__setitem__(self, *args, **kwargs)
+ if len(self) > self.maxlen:
+ self.popitem(last = False)
diff --git a/scripts/run_functional_tests b/scripts/run_functional_tests
index 9ec1bd39..c43224af 100755
--- a/scripts/run_functional_tests
+++ b/scripts/run_functional_tests
@@ -1,5 +1,6 @@
#!/bin/bash
+INPUT_ARGS=${@//--python[23]/}
if [[ $@ =~ '--python2' || ! $@ =~ '--python3' ]]; then
source find_python.sh --python2
@@ -7,7 +8,7 @@ if [[ $@ =~ '--python2' || ! $@ =~ '--python3' ]]; then
# Python 2
echo Python2 test
- $PYTHON trex_unit_test.py --functional $@
+ $PYTHON trex_unit_test.py --functional $INPUT_ARGS
if [ $? -eq 0 ]; then
printf "\n$PYTHON test succeeded\n\n"
else
@@ -23,7 +24,7 @@ if [[ $@ =~ '--python3' || ! $@ =~ '--python2' ]]; then
# Python 3
echo Python3 test
- $PYTHON trex_unit_test.py --functional $@
+ $PYTHON trex_unit_test.py --functional $INPUT_ARGS
if [ $? -eq 0 ]; then
printf "\n$PYTHON test succeeded\n\n"
else