diff options
author | imarom <imarom@cisco.com> | 2016-03-23 10:43:40 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-03-23 13:01:10 +0200 |
commit | 89a2be8247936e2d3d8323c0e51a86c198a879a2 (patch) | |
tree | 3433141e9eb84d35816c938308347686608ae6a3 /scripts/automation | |
parent | a380bf1055c6cb4432b1c928f73a3ca3ada52d9d (diff) |
yes...again Python3....
Diffstat (limited to 'scripts/automation')
14 files changed, 187 insertions, 164 deletions
diff --git a/scripts/automation/regression/CProgressDisp.py b/scripts/automation/regression/CProgressDisp.py index ec7920c3..b911c527 100755 --- a/scripts/automation/regression/CProgressDisp.py +++ b/scripts/automation/regression/CProgressDisp.py @@ -1,5 +1,5 @@ #!/router/bin/python - +from __future__ import print_function import threading import sys import time @@ -16,16 +16,16 @@ class ProgressThread(threading.Thread): def run(self): if self.notifyMessage is not None: - print(self.notifyMessage), + print(self.notifyMessage, end=' ') while not self.stoprequest.is_set(): - print "\b.", + print("\b.", end=' ') sys.stdout.flush() time.sleep(5) def join(self, timeout=None): if self.notifyMessage is not None: - print termstyle.green("Done!\n"), + print(termstyle.green("Done!\n"), end=' ') self.stoprequest.set() super(ProgressThread, self).join(timeout) @@ -44,7 +44,7 @@ class TimedProgressBar(threading.Thread): def run (self): # global g_stop - print + print() self.pbar.start() try: @@ -57,10 +57,10 @@ class TimedProgressBar(threading.Thread): except KeyboardInterrupt: # self.pbar.finish() - print "\nInterrupted by user!!" + print("\nInterrupted by user!!") self.join() finally: - print + print() def join(self, isPlannedStop = True, timeout=None): if isPlannedStop: @@ -82,6 +82,6 @@ def timedProgressBar(time_in_secs): time.sleep(0.5) pbar.update(i) pbar.finish() - print + print() diff --git a/scripts/automation/regression/functional_tests/pkt_bld_general_test.py b/scripts/automation/regression/functional_tests/pkt_bld_general_test.py index 5f89eaff..9a1b708a 100755 --- a/scripts/automation/regression/functional_tests/pkt_bld_general_test.py +++ b/scripts/automation/regression/functional_tests/pkt_bld_general_test.py @@ -14,7 +14,7 @@ class CGeneralPktBld_Test(object): @staticmethod def print_packet(pkt_obj): - print "\nGenerated packet:\n{}".format(repr(pkt_obj)) + print("\nGenerated packet:\n{}".format(repr(pkt_obj))) def setUp(self): diff --git a/scripts/automation/regression/functional_tests/platform_cmd_cache_test.py b/scripts/automation/regression/functional_tests/platform_cmd_cache_test.py index 24ccf7a5..077d81ce 100755 --- a/scripts/automation/regression/functional_tests/platform_cmd_cache_test.py +++ b/scripts/automation/regression/functional_tests/platform_cmd_cache_test.py @@ -9,7 +9,7 @@ from nose.tools import assert_not_equal class CCommandCache_Test(functional_general_test.CGeneralFunctional_Test): def setUp(self): - self.cache = CCommandCache() + self.cache = CCommandCache() self.cache.add('IF', "ip nbar protocol-discovery", 'GigabitEthernet0/0/1') self.cache.add('IF', "ip nbar protocol-discovery", 'GigabitEthernet0/0/2') self.cache.add('conf', "arp 1.1.1.1 0000.0001.0000 arpa") @@ -30,10 +30,10 @@ class CCommandCache_Test(functional_general_test.CGeneralFunctional_Test): def test_dump_config (self): import sys - from StringIO import StringIO + from io import BytesIO saved_stdout = sys.stdout try: - out = StringIO() + out = BytesIO() sys.stdout = out self.cache.dump_config() output = out.getvalue().strip() diff --git a/scripts/automation/regression/functional_tests/platform_dual_if_obj_test.py b/scripts/automation/regression/functional_tests/platform_dual_if_obj_test.py index ff54b9ee..d848b466 100755 --- a/scripts/automation/regression/functional_tests/platform_dual_if_obj_test.py +++ b/scripts/automation/regression/functional_tests/platform_dual_if_obj_test.py @@ -9,7 +9,7 @@ from nose.tools import assert_not_equal class CDualIfObj_Test(functional_general_test.CGeneralFunctional_Test): def setUp(self): - self.if_1 = CIfObj('gig0/0/1', '1.1.1.1', '2001:DB8:0:2222:0:0:0:1', '0000.0001.0000', '0000.0001.0000', IFType.Client) + self.if_1 = CIfObj('gig0/0/1', '1.1.1.1', '2001:DB8:0:2222:0:0:0:1', '0000.0001.0000', '0000.0001.0000', IFType.Client) self.if_2 = CIfObj('gig0/0/2', '1.1.2.1', '2001:DB8:1:2222:0:0:0:1', '0000.0002.0000', '0000.0002.0000', IFType.Server) self.if_3 = CIfObj('gig0/0/3', '1.1.3.1', '2001:DB8:2:2222:0:0:0:1', '0000.0003.0000', '0000.0003.0000', IFType.Client) self.if_4 = CIfObj('gig0/0/4', '1.1.4.1', '2001:DB8:3:2222:0:0:0:1', '0000.0004.0000', '0000.0004.0000', IFType.Server) diff --git a/scripts/automation/regression/functional_tests/scapy_pkt_builder_test.py b/scripts/automation/regression/functional_tests/scapy_pkt_builder_test.py index 14f0014c..a3fcd091 100644 --- a/scripts/automation/regression/functional_tests/scapy_pkt_builder_test.py +++ b/scripts/automation/regression/functional_tests/scapy_pkt_builder_test.py @@ -45,7 +45,7 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): pkt_builder.dump_scripts () - print pkt_builder.get_vm_data() + print(pkt_builder.get_vm_data()) assert_equal( pkt_builder.get_vm_data(), {'split_by_var': '', 'instructions': [{'name': 'a', 'max_value': 268435466, 'min_value': 268435457, 'init_value': 268435457, 'size': 4, 'type': 'flow_var', 'step':1,'op': 'inc'}, {'is_big_endian': True, 'pkt_offset': 26, 'type': 'write_flow_var', 'name': 'a', 'add_value': 0}, {'pkt_offset': 14, 'type': 'fix_checksum_ipv4'}]} ) @@ -178,7 +178,7 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): build ipv6 packet """ - print "start " + print("start ") py='\x55'*(64) p=Ether()/IPv6()/UDP(dport=12,sport=1025)/py @@ -300,25 +300,25 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): def test_simple_pkt_loader(self): p=RawPcapReader("functional_tests/golden/basic_imix_golden.cap") - print "" + print("") for pkt in p: - print pkt[1] - print hexdump(str(pkt[0])) + print(pkt[1]) + print(hexdump(str(pkt[0]))) break; def test_simple_pkt_loader1(self): pkt_builder = STLPktBuilder(pkt = "functional_tests/golden/udp_590.cap", build_raw = False); - print "" + print("") pkt_builder.dump_as_hex() r = pkt_builder.pkt_raw - assert_equal(ord(r[1]),0x50) - assert_equal(ord(r[0]),0x00) - assert_equal(ord(r[0x240]),0x16) - assert_equal(ord(r[0x24d]),0x79) + assert_equal(safe_ord(r[1]),0x50) + assert_equal(safe_ord(r[0]),0x00) + assert_equal(safe_ord(r[0x240]),0x16) + assert_equal(safe_ord(r[0x24d]),0x79) assert_equal(len(r),590) - print len(r) + print(len(r)) def test_simple_pkt_loader2(self): @@ -341,8 +341,8 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): py='\x55'*(64) p=Ether()/IP()/UDP(dport=12,sport=1025)/py - pkt_str = str(p); - print "" + pkt_str = bytes(p); + print("") hexdump(pkt_str); scapy_pkt = Ether(pkt_str); scapy_pkt.show2(); diff --git a/scripts/automation/regression/functional_tests/stl_basic_tests.py b/scripts/automation/regression/functional_tests/stl_basic_tests.py index ea515401..6467c128 100644 --- a/scripts/automation/regression/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/functional_tests/stl_basic_tests.py @@ -7,9 +7,9 @@ from nose.tools import assert_not_equal from nose.tools import nottest from nose.plugins.attrib import attr from trex import CTRexScenario -from dpkt import pcap from trex_stl_lib import trex_stl_sim from trex_stl_lib.trex_stl_streams import STLProfile +from trex_stl_lib.trex_stl_packet_builder_scapy import RawPcapReader, RawPcapWriter import sys import os import subprocess @@ -36,7 +36,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): self.profiles['random_size_9k'] = os.path.join(self.profiles_path, "../udp_rand_len_9k.py") self.profiles['imix_tuple_gen'] = os.path.join(self.profiles_path, "imix_1pkt_tuple_gen.yaml") - for k, v in self.profiles.iteritems(): + for k, v in self.profiles.items(): self.verify_exists(v) self.valgrind_profiles = [ self.profiles['imix_3pkt_vm'], @@ -65,23 +65,19 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): def compare_caps (self, cap1, cap2, max_diff_sec = 0.01): - with open(cap1, 'r') as f1: - reader1 = pcap.Reader(f1) - pkts1 = reader1.readpkts() - - with open(cap2, 'r') as f2: - reader2 = pcap.Reader(f2) - pkts2 = reader2.readpkts() + pkts1 = list(RawPcapReader(cap1)) + pkts2 = list(RawPcapReader(cap2)) assert_equal(len(pkts1), len(pkts2)) - for pkt1, pkt2, i in zip(pkts1, pkts2, xrange(1, len(pkts1))): - ts1 = pkt1[0] - ts2 = pkt2[0] + for pkt1, pkt2, i in zip(pkts1, pkts2, range(1, len(pkts1))): + ts1 = float(pkt1[1][0]) + (float(pkt1[1][1]) / 1e6) + ts2 = float(pkt2[1][0]) + (float(pkt2[1][1]) / 1e6) + if abs(ts1-ts2) > 0.000005: # 5 nsec raise AssertionError("TS error: cap files '{0}', '{1}' differ in cap #{2} - '{3}' vs. '{4}'".format(cap1, cap2, i, ts1, ts2)) - if pkt1[1] != pkt2[1]: + if pkt1[0] != pkt2[0]: raise AssertionError("RAW error: cap files '{0}', '{1}' differ in cap #{2}".format(cap1, cap2, i)) @@ -121,6 +117,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): finally: if not do_no_remove: os.unlink(output_cap) + if test_generated: try: generated_filename = input_file.replace('.py', '_GENERATED.py').replace('.yaml', '_GENERATED.py') @@ -128,15 +125,18 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): profile = STLProfile.load_py(input_file) elif input_file.endswith('.yaml'): profile = STLProfile.load_yaml(input_file) - profile.dump_to_code(generated_filename) + profile.dump_to_code(generated_filename) + rc = self.run_sim(generated_filename, output_cap, options, silent) assert_equal(rc, True) if compare: self.compare_caps(output_cap, golden_file) + except Exception as e: - print e + print(e) + finally: if not do_no_remove_generated: os.unlink(generated_filename) @@ -148,52 +148,52 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): def test_stl_profiles (self): p = [ - ["udp_1pkt_1mac_override.py","-m 1 -l 50",True], - ["syn_attack.py","-m 1 -l 50",True], # can't compare random now - ["udp_1pkt_1mac.py","-m 1 -l 50",True], - ["udp_1pkt_mac.py","-m 1 -l 50",True], - ["udp_1pkt.py","-m 1 -l 50",True], - ["udp_1pkt_tuple_gen.py","-m 1 -l 50",True], - ["udp_rand_len_9k.py","-m 1 -l 50",True], # can't do the compare - ["udp_1pkt_mpls.py","-m 1 -l 50",True], - ["udp_1pkt_mpls_vm.py","-m 1 ",True], - ["imix.py","-m 1 -l 100",True], - ["udp_inc_len_9k.py","-m 1 -l 100",True], - ["udp_1pkt_range_clients.py","-m 1 -l 100",True], - ["multi_burst_2st_1000pkt.py","-m 1 -l 100",True], - ["pcap.py", "-m 1", True], - ["pcap_with_vm.py", "-m 1", True], + ["udp_1pkt_1mac_override.py","-m 1 -l 50",True], + ["syn_attack.py","-m 1 -l 50",True], # can't compare random now + ["udp_1pkt_1mac.py","-m 1 -l 50",True], + ["udp_1pkt_mac.py","-m 1 -l 50",True], + ["udp_1pkt.py","-m 1 -l 50",True], + ["udp_1pkt_tuple_gen.py","-m 1 -l 50",True], + ["udp_rand_len_9k.py","-m 1 -l 50",True], # can't do the compare + ["udp_1pkt_mpls.py","-m 1 -l 50",True], + ["udp_1pkt_mpls_vm.py","-m 1 ",True], + ["imix.py","-m 1 -l 100",True], + ["udp_inc_len_9k.py","-m 1 -l 100",True], + ["udp_1pkt_range_clients.py","-m 1 -l 100",True], + ["multi_burst_2st_1000pkt.py","-m 1 -l 100",True], + ["pcap.py", "-m 1", True], + ["pcap_with_vm.py", "-m 1", True], # YAML test - ["yaml/burst_1000_pkt.yaml","-m 1 -l 100",True], - ["yaml/burst_1pkt_1burst.yaml","-m 1 -l 100",True], - ["yaml/burst_1pkt_vm.yaml","-m 1 -l 100",True], - ["yaml/imix_1pkt.yaml","-m 1 -l 100",True], - ["yaml/imix_1pkt_2.yaml","-m 1 -l 100",True], - ["yaml/imix_1pkt_tuple_gen.yaml","-m 1 -l 100",True], - ["yaml/imix_1pkt_vm.yaml","-m 1 -l 100",True], - ["udp_1pkt_pcap.py","-m 1 -l 10",True], - ["udp_3pkt_pcap.py","-m 1 -l 10",True], - #["udp_1pkt_simple.py","-m 1 -l 3",True], - ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True], - ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True], - ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True], - ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile - ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -c 1 -l 17",True], - ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20 --cores 2",True], - ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20 --cores 2",True], - ["udp_1pkt_simple_mac_dst.py","-m 1 -l 1 ",True], - ["udp_1pkt_simple_mac_src.py","-m 1 -l 1 ",True], - ["udp_1pkt_simple_mac_dst_src.py","-m 1 -l 1 ",True], - ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True], - ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True], - ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] , - ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True], - ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True], - ["udp_1pkt_simple_test2.py","-m 1 -l 10 ",True], # test split of packet with ip option - ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True], - ["udp_1pkt_mac_mask5.py","-m 1 -l 30 ",True], - ["udp_1pkt_range_clients_split_garp.py","-m 1 -l 50",True] + ["yaml/burst_1000_pkt.yaml","-m 1 -l 100",True], + ["yaml/burst_1pkt_1burst.yaml","-m 1 -l 100",True], + ["yaml/burst_1pkt_vm.yaml","-m 1 -l 100",True], + ["yaml/imix_1pkt.yaml","-m 1 -l 100",True], + ["yaml/imix_1pkt_2.yaml","-m 1 -l 100",True], + ["yaml/imix_1pkt_tuple_gen.yaml","-m 1 -l 100",True], + ["yaml/imix_1pkt_vm.yaml","-m 1 -l 100",True], + ["udp_1pkt_pcap.py","-m 1 -l 10",True], + ["udp_3pkt_pcap.py","-m 1 -l 10",True], + #["udp_1pkt_simple.py","-m 1 -l 3",True], + ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True], + ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True], + ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True], + ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile + ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -c 1 -l 17",True], + ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20 --cores 2",True], + ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20 --cores 2",True], + ["udp_1pkt_simple_mac_dst.py","-m 1 -l 1 ",True], + ["udp_1pkt_simple_mac_src.py","-m 1 -l 1 ",True], + ["udp_1pkt_simple_mac_dst_src.py","-m 1 -l 1 ",True], + ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True], + ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True], + ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] , + ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True], + ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True], + ["udp_1pkt_simple_test2.py","-m 1 -l 10 ",True], # test split of packet with ip option + ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True], + ["udp_1pkt_mac_mask5.py","-m 1 -l 30 ",True], + ["udp_1pkt_range_clients_split_garp.py","-m 1 -l 50",True] ]; @@ -240,11 +240,10 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): # valgrind tests - this runs in multi thread as it safe (no output) def test_valgrind_various_profiles (self): - - print "\n" + print("\n") threads = [] for profile in self.valgrind_profiles: - print "\n*** VALGRIND: testing profile '{0}' ***\n".format(profile) + print("\n*** VALGRIND: testing profile '{0}' ***\n".format(profile)) obj = {'t': None, 'rc': None} t = Thread(target = self.run_sim, kwargs = {'obj': obj, 'yaml': profile, 'output':None, 'options': "--cores 8 --limit 20 --valgrind", 'silent': True}) diff --git a/scripts/automation/regression/misc_methods.py b/scripts/automation/regression/misc_methods.py index 783858e8..54e3ba5d 100755 --- a/scripts/automation/regression/misc_methods.py +++ b/scripts/automation/regression/misc_methods.py @@ -1,9 +1,12 @@ #!/router/bin/python +import sys +if sys.version_info >= (3, 0): + import configparser +else: + import ConfigParser -import ConfigParser import outer_packages import yaml -import sys from collections import namedtuple import subprocess, shlex import os @@ -13,7 +16,7 @@ TRexConfig = namedtuple('TRexConfig', 'trex, router, tftp') # debug/development purpose, lists object's attributes and their values def print_r(obj): for attr in dir(obj): - print 'obj.%s %s' % (attr, getattr(obj, attr)) + print('obj.%s %s' % (attr, getattr(obj, attr))) def mix_string (str): """Convert all string to lowercase letters, and replaces spaces with '_' char""" @@ -22,20 +25,20 @@ def mix_string (str): # executes given command, returns tuple (return_code, stdout, stderr) def run_command(cmd, background = False): if background: - print 'Running command in background:', cmd + print('Running command in background:', cmd) with open(os.devnull, 'w') as tempf: subprocess.Popen(shlex.split(cmd), stdin=tempf, stdout=tempf, stderr=tempf) return (None,)*3 else: - print 'Running command:', cmd + print('Running command:', cmd) proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() if stdout: - print 'Stdout:\n%s' % stdout + print('Stdout:\n%s' % stdout) if proc.returncode: if stderr: - print 'Stderr:\n%s' % stderr - print 'Return code: %s' % proc.returncode + print('Stderr:\n%s' % stderr) + print('Return code: %s' % proc.returncode) return (proc.returncode, stdout, stderr) @@ -81,7 +84,7 @@ def get_single_net_client_addr (ip_addr, octetListDict = {'3' : 1}, ip_type = 'i if ip_type == 'ipv4': ip_lst = ip_addr.split('.') - for octet,increment in octetListDict.iteritems(): + for octet,increment in octetListDict.items(): int_octet = int(octet) if ((int_octet < 0) or (int_octet > 3)): raise ValueError('the provided octet is not legal in {0} format'.format(ip_type) ) @@ -96,7 +99,7 @@ def get_single_net_client_addr (ip_addr, octetListDict = {'3' : 1}, ip_type = 'i else: # this is a ipv6 address, handle accordingly ip_lst = ip_addr.split(':') - for octet,increment in octetListDict.iteritems(): + for octet,increment in octetListDict.items(): int_octet = int(octet) if ((int_octet < 0) or (int_octet > 7)): raise ValueError('the provided octet is not legal in {0} format'.format(ip_type) ) @@ -159,11 +162,11 @@ def load_complete_config_file (filepath): raise ValueError('A clean router configuration wasn`t provided.') except ValueError: - print '!!!!!' + print("") raise except Exception as inst: - print "\nBad configuration file provided: '{0}'\n".format(filepath) + print("\nBad configuration file provided: '{0}'\n".format(filepath)) raise inst return TRexConfig(trex_config, rtr_config, tftp_config) @@ -174,8 +177,8 @@ def load_object_config_file (filepath): config = yaml.load(f) return config except Exception as inst: - print "\nBad configuration file provided: '{0}'\n".format(filepath) - print inst + print("\nBad configuration file provided: '{0}'\n".format(filepath)) + print(inst) exit(-1) @@ -202,7 +205,7 @@ def query_yes_no(question, default="yes"): while True: sys.stdout.write(question + prompt) - choice = raw_input().lower() + choice = input().lower() if default is not None and choice == '': return valid[default] elif choice in valid: @@ -227,8 +230,8 @@ def load_benchmark_config_file (filepath): benchmark_config = yaml.load(f) except Exception as inst: - print "\nBad configuration file provided: '{0}'\n".format(filepath) - print inst + print("\nBad configuration file provided: '{0}'\n".format(filepath)) + print(inst) exit(-1) return benchmark_config diff --git a/scripts/automation/regression/outer_packages.py b/scripts/automation/regression/outer_packages.py index f55c247d..bec9fe21 100755 --- a/scripts/automation/regression/outer_packages.py +++ b/scripts/automation/regression/outer_packages.py @@ -11,28 +11,56 @@ PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(TREX_PATH, 'external_libs')) PATH_TO_CTRL_PLANE = os.path.abspath(os.path.join(TREX_PATH, 'automation', 'trex_control_plane')) PATH_STL_API = os.path.abspath(os.path.join(PATH_TO_CTRL_PLANE, 'stl')) -NIGHTLY_MODULES = ['ansi2html', - 'enum34-1.0.4', - 'nose-1.3.4', - 'rednose-0.4.1', - 'progressbar-2.2', - 'termstyle', - 'dpkt-1.8.6', - 'yaml-3.11', + +NIGHTLY_MODULES = [ {'name': 'ansi2html'}, + {'name': 'enum34-1.0.4'}, + {'name': 'rednose-0.4.1'}, + {'name': 'progressbar-2.2'}, + {'name': 'termstyle'}, + {'name': 'pyyaml-3.11', 'py-dep': True}, + {'name': 'nose-1.3.4', 'py-dep': True} ] + +def generate_module_path (module, is_python3, is_64bit, is_cel): + platform_path = [module['name']] + + if module.get('py-dep'): + platform_path.append('python3' if is_python3 else 'python2') + + if module.get('arch-dep'): + platform_path.append('cel59' if is_cel else 'fedora18') + platform_path.append('64bit' if is_64bit else '32bit') + + return os.path.normcase(os.path.join(PATH_TO_PYTHON_LIB, *platform_path)) + + +def import_module_list(modules_list): + + # platform data + is_64bit = platform.architecture()[0] == '64bit' + is_python3 = (sys.version_info >= (3, 0)) + is_cel = os.path.exists('/etc/system-profile') + + # regular modules + for p in modules_list: + full_path = generate_module_path(p, is_python3, is_64bit, is_cel) + + if not os.path.exists(full_path): + print("Unable to find required module library: '{0}'".format(p['name'])) + print("Please provide the correct path using PATH_TO_PYTHON_LIB variable") + print("current path used: '{0}'".format(full_path)) + exit(0) + + sys.path.insert(1, full_path) + + def import_nightly_modules (): sys.path.append(TREX_PATH) sys.path.append(PATH_TO_CTRL_PLANE) sys.path.append(PATH_STL_API) import_module_list(NIGHTLY_MODULES) -def import_module_list (modules_list): - assert(isinstance(modules_list, list)) - for p in modules_list: - full_path = os.path.join(PATH_TO_PYTHON_LIB, p) - fix_path = os.path.normcase(full_path) #CURRENT_PATH+p) - sys.path.insert(1, full_path) import_nightly_modules() diff --git a/scripts/automation/regression/platform_cmd_link.py b/scripts/automation/regression/platform_cmd_link.py index 3d577baf..eba20bfd 100755 --- a/scripts/automation/regression/platform_cmd_link.py +++ b/scripts/automation/regression/platform_cmd_link.py @@ -36,31 +36,31 @@ class CCommandCache(object): def dump_config (self): # dump IF config: - print "configure terminal" - for intf, intf_cmd_list in self.cache['IF'].iteritems(): - print "interface {if_name}".format( if_name = intf ) - print '\n'.join(intf_cmd_list) + print("configure terminal") + for intf, intf_cmd_list in self.cache['IF'].items(): + print("interface {if_name}".format( if_name = intf )) + print('\n'.join(intf_cmd_list)) if self.cache['IF']: # add 'exit' note only if if config actually took place - print 'exit' # exit to global config mode + print('exit') # exit to global config mode # dump global config if self.cache['CONF']: - print '\n'.join(self.cache['CONF']) + print('\n'.join(self.cache['CONF'])) # exit back to en mode - print "exit" + print("exit") # dump exec config if self.cache['EXEC']: - print '\n'.join(self.cache['EXEC']) + print('\n'.join(self.cache['EXEC'])) def get_config_list (self): conf_list = [] conf_list.append("configure terminal") - for intf, intf_cmd_list in self.cache['IF'].iteritems(): + for intf, intf_cmd_list in self.cache['IF'].items(): conf_list.append( "interface {if_name}".format( if_name = intf ) ) conf_list.extend( intf_cmd_list ) if len(conf_list)>1: @@ -94,7 +94,7 @@ class CCommandLink(object): def __transmit (self, cmd_list, **kwargs): self.history.extend(cmd_list) if not self.silent_mode: - print '\n'.join(cmd_list) # prompting the pushed platform commands + print('\n'.join(cmd_list)) # prompting the pushed platform commands if not self.virtual_mode: # transmit the command to platform. return self.telnet_con.write_ios_cmd(cmd_list, **kwargs) @@ -181,7 +181,7 @@ class CDeviceCfg(object): def dump_config (self): import yaml - print yaml.dump(self.interfaces_cfg, default_flow_style=False) + print(yaml.dump(self.interfaces_cfg, default_flow_style=False)) class CIfObj(object): _obj_id = 0 @@ -339,7 +339,7 @@ class CIfManager(object): def get_if_list (self, if_type = IFType.All, is_duplicated = None): result = [] - for if_name,if_obj in self.interfarces.iteritems(): + for if_name,if_obj in self.interfarces.items(): if (if_type == IFType.All) or ( if_obj.get_if_type() == if_type) : if (is_duplicated is None) or (if_obj.get_pair_parent().is_duplicated() == is_duplicated): # append this if_obj only if matches both IFType and is_duplicated conditions @@ -362,7 +362,7 @@ class CIfManager(object): def dump_if_config (self): if self.full_device_cfg is None: - print "Device configuration isn't loaded.\nPlease load config and try again." + print("Device configuration isn't loaded.\nPlease load config and try again.") else: self.full_device_cfg.dump_config() diff --git a/scripts/automation/regression/trex.py b/scripts/automation/regression/trex.py index 8efa41f6..9459e7c6 100644 --- a/scripts/automation/regression/trex.py +++ b/scripts/automation/regression/trex.py @@ -96,7 +96,7 @@ class CTRexRunner: self.yaml) # self.trex_config['trex_latency']) - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): tmp_key = key.replace('_','-') dash = ' -' if (len(key)==1) else ' --' if value == True: @@ -104,7 +104,7 @@ class CTRexRunner: else: trex_cmd += (dash + '{k} {val}'.format( k = tmp_key, val = value )) - print "\nT-REX COMMAND: ", trex_cmd + print("\nT-REX COMMAND: ", trex_cmd) cmd = 'sshpass.exp %s %s root "cd %s; %s > %s"' % (self.trex_config['trex_password'], self.trex_config['trex_name'], @@ -172,7 +172,7 @@ class CTRexRunner: fin = datetime.datetime.now() # print "Time difference : ", fin-start runtime_deviation = abs(( (end_time - start_time)/ (duration+15) ) - 1) - print "runtime_deviation: %2.0f %%" % ( runtime_deviation*100.0) + print("runtime_deviation: %2.0f %%" % ( runtime_deviation*100.0)) if ( runtime_deviation > 0.6 ) : # If the run stopped immediately - classify as Trex in use or reachability issue interrupted = True @@ -183,7 +183,7 @@ class CTRexRunner: # results = subprocess.Popen(cmd, stdout = open(os.devnull, 'wb'), # shell=True, preexec_fn=os.setsid) except KeyboardInterrupt: - print "\nT-Rex test interrupted by user during traffic generation!!" + print("\nT-Rex test interrupted by user during traffic generation!!") results.killpg(results.pid, signal.SIGTERM) # Send the kill signal to all the process groups interrupted = True raise RuntimeError @@ -245,7 +245,7 @@ class CTRexResult(): Prints nicely the content of self.result dictionary into the screen """ for key, value in self.result.items(): - print "{0:20} : \t{1}".format(key, float(value)) + print("{0:20} : \t{1}".format(key, float(value))) def update (self, key, val, _str): """ update (self, key, val, _str) -> None @@ -273,7 +273,7 @@ class CTRexResult(): elif s[0]=="K": val = val*1E3 - if self.result.has_key(key): + if key in self.result: if self.result[key] > 0: if (val/self.result[key] > 0.97 ): self.result[key]= val @@ -331,7 +331,7 @@ class CTRexResult(): if match: key = misc_methods.mix_string(match.group(1)) val = float(match.group(4)) - if d.has_key(key): + if key in d: if stop_read == False: self.update (key, val, match.group(5)) else: @@ -345,7 +345,7 @@ class CTRexResult(): if match: key = misc_methods.mix_string(match.group(1)) val = float(match.group(4)) - if d.has_key(key): + if key in d: if stop_read == False: self.update (key, val, match.group(5)) else: @@ -370,7 +370,7 @@ class CTRexResult(): if match: key = misc_methods.mix_string(match.group(1)) val = float(match.group(3)) - if self.result.has_key(key): + if key in self.result: if (self.result[key] < val): # update only if larger than previous value self.result[key] = val else: @@ -391,7 +391,7 @@ class CTRexResult(): def get_status (self, drop_expected = False): if (self.error != ""): - print self.error + print(self.error) return (self.STATUS_ERR_FATAL) d = self.result @@ -417,9 +417,9 @@ class CTRexResult(): # expected measurement expect_vs_measued=d['total-tx']/d['expected-bps'] if ( (expect_vs_measued >1.1) or (expect_vs_measued < 0.9) ) : - print expect_vs_measued - print d['total-tx'] - print d['expected-bps'] + print(expect_vs_measued) + print(d['total-tx']) + print(d['expected-bps']) self.reason="measure is not as expected" return self.STATUS_ERR_BAD_EXPECTED_MEASUREMENT @@ -442,7 +442,7 @@ def test_TRex_result_parser(): t=CTRexResult('trex.txt'); t.load_file_lines() t.parse() - print t.result + print(t.result) diff --git a/scripts/automation/regression/trex_unit_test.py b/scripts/automation/regression/trex_unit_test.py index c8565c19..4348d004 100755 --- a/scripts/automation/regression/trex_unit_test.py +++ b/scripts/automation/regression/trex_unit_test.py @@ -27,6 +27,7 @@ Description: import os import sys import outer_packages + import nose from nose.plugins import Plugin import logging @@ -87,7 +88,7 @@ def kill_trex_process(trex_data): try: proc_name, pid, full_cmd = re.split('\s+', process, maxsplit=2) if proc_name.find('t-rex-64') >= 0: - print 'Killing remote process: %s' % full_cmd + print('Killing remote process: %s' % full_cmd) trex_remote_command(trex_data, 'kill %s' % pid, from_scripts = False) except: continue @@ -184,7 +185,7 @@ class CTRexTestConfiguringPlugin(Plugin): rsync_command = rsync_template % (new_path, self.pkg, os.path.basename(self.pkg), new_path, new_path, new_path) return_code, stdout, stderr = trex_remote_command(self.configuration.trex, rsync_command, from_scripts = False) if return_code: - print 'Failed copying' + print('Failed copying') sys.exit(-1) CTRexScenario.scripts_path = new_path CTRexScenario.is_copied = True @@ -198,7 +199,7 @@ class CTRexTestConfiguringPlugin(Plugin): kill_trex_process(self.configuration.trex) time.sleep(1) elif check_trex_running(self.configuration.trex): - print 'TRex is already running' + print('TRex is already running') sys.exit(-1) @@ -250,7 +251,7 @@ def save_setup_info(): with open('%s/report_%s.info' % (CTRexScenario.report_dir, CTRexScenario.setup_name), 'w') as f: f.write(setup_info) except Exception as err: - print 'Error saving setup info: %s ' % err + print('Error saving setup info: %s ' % err) def set_report_dir (report_dir): @@ -334,12 +335,12 @@ if __name__ == "__main__": result = nose.run(argv = nose_argv + additional_args, addplugins = [red_nose, config_plugin]) and result except Exception as e: result = False - print e + print(e) finally: save_setup_info() if (result == True and not CTRexScenario.is_test_list): - print termstyle.green(""" + print(termstyle.green(""" ..::''''::.. .;'' ``;. :: :: :: :: @@ -356,7 +357,7 @@ if __name__ == "__main__": / ___/ __ |_\ \_\ \/_/ /_/ /_/ |_/___/___(_) - """) + """)) sys.exit(0) sys.exit(-1) diff --git a/scripts/automation/trex_control_plane/client/trex_client.py b/scripts/automation/trex_control_plane/client/trex_client.py index 9e3944d4..68c70119 100755 --- a/scripts/automation/trex_control_plane/client/trex_client.py +++ b/scripts/automation/trex_control_plane/client/trex_client.py @@ -3,12 +3,7 @@ import sys import os -try: - # support import for Python 2 - import outer_packages -except ImportError: - # support import for Python 3 - import client.outer_packages +import client.outer_packages import jsonrpclib from jsonrpclib import ProtocolError, AppError from common.trex_status_e import TRexStatus diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py index fe4bad62..c614c4bd 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py @@ -42,10 +42,7 @@ def import_module_list(modules_list): is_64bit = platform.architecture()[0] == '64bit' is_python3 = (sys.version_info >= (3, 0)) is_cel = os.path.exists('/etc/system-profile') - - - # regular modules for p in modules_list: full_path = generate_module_path(p, is_python3, is_64bit, is_cel) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py index 16ffad43..eed20485 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py @@ -530,9 +530,9 @@ class STLStream(object): good_printable.remove("'") if type(data) is str: - new_data = ''.join([c if c in good_printable else r'\x{0:02x}'.format(ord(c)) for c in x]) + new_data = ''.join([c if c in good_printable else r'\x{0:02x}'.format(ord(c)) for c in data]) else: - new_data = ''.join([chr(c) if chr(c) in good_printable else r'\x{0:02x}'.format(c) for c in x]) + new_data = ''.join([chr(c) if chr(c) in good_printable else r'\x{0:02x}'.format(c) for c in data]) payload_start = packet_command.find("Raw(load='") if payload_start != -1: |