python 3 - regression
authorimarom <[email protected]>
Wed, 23 Mar 2016 09:55:07 +0000 (11:55 +0200)
committerimarom <[email protected]>
Wed, 23 Mar 2016 11:01:11 +0000 (13:01 +0200)
scripts/automation/regression/functional_tests/platform_cmd_cache_test.py
scripts/automation/regression/functional_tests/platform_if_manager_test.py
scripts/automation/regression/functional_tests/stl_basic_tests.py
scripts/automation/regression/platform_cmd_link.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
scripts/find_python.sh
scripts/run_functional_tests

index 077d81c..0be2128 100755 (executable)
@@ -30,10 +30,10 @@ class CCommandCache_Test(functional_general_test.CGeneralFunctional_Test):
 
     def test_dump_config (self):
         import sys
-        from io import BytesIO
+        from io import StringIO, BytesIO
         saved_stdout = sys.stdout
         try:
-            out = BytesIO()
+            out = BytesIO() if sys.version_info < (3,0) else StringIO()
             sys.stdout = out
             self.cache.dump_config()
             output = out.getvalue().strip()
index b09e8d7..72015f5 100755 (executable)
@@ -28,13 +28,13 @@ class CIfManager_Test(functional_general_test.CGeneralFunctional_Test):
         assert_equal( len(self.if_mng.get_dual_if_list()), 2 )
 
         # check the classification with intf name
-        assert_equal( map(CIfObj.get_name, self.if_mng.get_if_list() ), ['GigabitEthernet0/0/1','GigabitEthernet0/0/2','GigabitEthernet0/0/3','GigabitEthernet0/0/4'] )
-        assert_equal( map(CIfObj.get_name, self.if_mng.get_if_list(is_duplicated = True) ), ['GigabitEthernet0/0/3','GigabitEthernet0/0/4'] )
-        assert_equal( map(CIfObj.get_name, self.if_mng.get_if_list(is_duplicated = False) ), ['GigabitEthernet0/0/1','GigabitEthernet0/0/2'] )
-        assert_equal( map(CIfObj.get_name, self.if_mng.get_duplicated_if() ), ['GigabitEthernet0/0/3', 'GigabitEthernet0/0/4'] )
+        assert_equal( list(map(CIfObj.get_name, self.if_mng.get_if_list()) ), ['GigabitEthernet0/0/1','GigabitEthernet0/0/2','GigabitEthernet0/0/3','GigabitEthernet0/0/4'] )
+        assert_equal( list(map(CIfObj.get_name, self.if_mng.get_if_list(is_duplicated = True)) ), ['GigabitEthernet0/0/3','GigabitEthernet0/0/4'] )
+        assert_equal( list(map(CIfObj.get_name, self.if_mng.get_if_list(is_duplicated = False)) ), ['GigabitEthernet0/0/1','GigabitEthernet0/0/2'] )
+        assert_equal( list(map(CIfObj.get_name, self.if_mng.get_duplicated_if()) ), ['GigabitEthernet0/0/3', 'GigabitEthernet0/0/4'] )
 
         # check the classification with vrf name
-        assert_equal( map(CDualIfObj.get_vrf_name, self.if_mng.get_dual_if_list() ), [None, 'dup'] )
+        assert_equal( list(map(CDualIfObj.get_vrf_name, self.if_mng.get_dual_if_list()) ), [None, 'dup'] )
 
     def tearDown(self):
         pass
index 6467c12..2bf9730 100644 (file)
@@ -133,14 +133,16 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
 
                 if compare:
                     self.compare_caps(output_cap, golden_file)
-            
+
             except Exception as e:
                 print(e)
 
             finally:
                 if not do_no_remove_generated:
                     os.unlink(generated_filename)
-                    os.unlink(generated_filename + 'c')
+                    # python 3 does not generate PYC under the same dir
+                    if os.path.exists(generated_filename + 'c'):
+                        os.unlink(generated_filename + 'c')
                 if not do_no_remove:
                     os.unlink(output_cap)
 
index eba20bf..247127c 100755 (executable)
@@ -5,13 +5,14 @@ import CustomLogger
 import misc_methods
 import telnetlib
 import socket
+from collections import OrderedDict
 
 class CCommandCache(object):
     def __init__(self):
         self.__gen_clean_data_structure()
 
     def __gen_clean_data_structure (self):
-        self.cache =  {"IF"   : {},
+        self.cache =  {"IF"   : OrderedDict(),
                        "CONF" : [],
                        "EXEC" : []}
 
@@ -274,7 +275,7 @@ class CIfManager(object):
     _ipv6_gen = misc_methods.get_network_addr(ip_type = 'ipv6')
 
     def __init__(self):
-        self.interfarces     = {}
+        self.interfarces     = OrderedDict()
         self.dual_intf       = []
         self.full_device_cfg = None
 
index eed2048..4f8ce3e 100644 (file)
@@ -534,15 +534,17 @@ class STLStream(object):
             else:
                 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='")
+            payload_start = packet_command.find("Raw(load=")
             if payload_start != -1:
                 packet_command = packet_command[:payload_start-1]
         layers = packet_command.split('/')
+
         if payload:
             if len(new_data) and new_data == new_data[0] * len(new_data):
                 layers.append("Raw(load='%s' * %s)" % (new_data[0], len(new_data)))
             else:
                 layers.append("Raw(load='%s')" % new_data)
+
         packet_code = 'packet = (' + (' / \n          ').join(layers) + ')'
         vm_list = []
         for inst in self.fields['vm']['instructions']:
index 9552260..aba2d93 100755 (executable)
@@ -24,7 +24,21 @@ function find_python {
     exit -1
 }
 
+function find_python3 {
+    MACHINE_PYTHON=python3
+    PYTHON3=$MACHINE_PYTHON
+    PCHECK=`$PYTHON3 -c "import sys; ver = sys.version_info[0] * 10 + sys.version_info[1];sys.exit(ver != 34)"`
+    if [ $? -eq 0 ]; then
+        return
+    fi
+    PYTHON3=
+
+}
+
 if [ -z "$PYTHON" ]; then
     find_python
 fi
 
+if [ -z "$PYTHON3" ]; then
+    find_python3
+fi
index e3a5fa6..783d634 100755 (executable)
@@ -2,5 +2,29 @@
 
 source find_python.sh
 cd automation/regression
-$PYTHON trex_unit_test.py --functional $@
+
+if [ -z "$PYTHON" ]; then
+    echo "*** $PYTHON - python version is too old, 2.7 at least is required"
+else 
+    $PYTHON trex_unit_test.py --functional $@
+    if [ $? -eq 0 ]; then
+        printf "\n$PYTHON test succeeded\n\n"
+    else
+        printf "\n*** $PYTHON test failed\n\n"
+        exit -1
+    fi
+fi
+
+if [ -z "$PYTHON3" ]; then
+    echo "*** $PYTHON3 - python3 version required is 3.4 - skipping python3 test"
+else
+    $PYTHON3 trex_unit_test.py --functional $@
+    if [ $? -eq 0 ]; then
+        printf "\n$PYTHON3 test succeeded\n\n"
+    else
+        printf "\n*** $PYTHON3 test failed\n\n"
+        exit -1
+    fi
+
+fi