From 26efbcf533081d61fc72d964ecb52f7ebb624fd8 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 4 Jul 2020 12:25:05 +0000 Subject: [PATCH] [vstest]: change float division to integer division Signed-off-by: Guohan Lu --- tests/port_dpb.py | 6 +-- tests/test_port_dpb.py | 2 +- tests/test_warm_reboot.py | 94 +++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 6d0b07427ade..7688c3f67d67 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -112,7 +112,7 @@ def port_split(self, child_ports): child_port_list = [] port_num = self.get_port_num() num_lanes = len(self._lanes) - offset = num_lanes/child_ports; + offset = num_lanes//child_ports lanes_per_child = offset for i in range(child_ports): child_port_num = port_num + (i * offset) @@ -121,7 +121,7 @@ def port_split(self, child_ports): child_port_lanes = [] for j in range(lanes_per_child): child_port_lanes.append(self._lanes[(i*offset)+j]) - child_port_speed = self._speed/child_ports + child_port_speed = self._speed//child_ports child_port_index = self._index child_port = Port(self._dvs, child_port_name) @@ -219,7 +219,7 @@ def verify_asic_db(self): (status, fvs) = self._asic_db_ptbl.get(self.get_oid()) assert(status == True) fvs_dict = self.get_fvs_dict(fvs) - if ("SAI_PORT_ATTR_HW_LANE_LIST" in fvs_dict): + if "SAI_PORT_ATTR_HW_LANE_LIST" in fvs_dict: assert(fvs_dict['SAI_PORT_ATTR_HW_LANE_LIST'] == self.get_lanes_asic_db_str()) assert(fvs_dict['SAI_PORT_ATTR_SPEED'] == str(self.get_speed())) diff --git a/tests/test_port_dpb.py b/tests/test_port_dpb.py index 6c72dfda8e69..66ed2bf62730 100644 --- a/tests/test_port_dpb.py +++ b/tests/test_port_dpb.py @@ -63,7 +63,7 @@ def test_port_breakout_one(self, dvs): #print "**** 4X10G --> 4X25G passed ****" dpb.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"]) #print "**** 4X25G --> 1X100G passed ****" - dpb.breakout(dvs, "Ethernet0", maxBreakOut/2) + dpb.breakout(dvs, "Ethernet0", maxBreakOut//2) #print "**** 1X100G --> 2X50G passed ****" dpb.breakin(dvs, ["Ethernet0", "Ethernet2"]) #print "**** 2X50G --> 1X100G passed ****" diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index 87f02272e0ea..5ad0bc7b9b14 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -209,31 +209,31 @@ def setup_initial_neighbors(dvs): for i in range(8, 8+NUM_INTF): for j in range(NUM_NEIGH_PER_INTF): dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4, j+2)) time.sleep(1) for i in range(8, 8+NUM_INTF): for j in range(NUM_NEIGH_PER_INTF): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4, j+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4, j+2)]) # Del half of the ips and a new half of the ips # note: the first ipv4 can not be deleted only def del_and_add_neighbors(dvs): for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF//2+2)) + dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF//2+2)) dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) #ping new IPs def ping_new_ips(dvs): for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) class TestWarmReboot(object): @@ -488,10 +488,10 @@ def test_swss_neighbor_syncup(self, dvs, testlog): macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) time.sleep(1) @@ -500,7 +500,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): tbl = swsscommon.Table(db, "NEIGH_TABLE") for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: @@ -510,7 +510,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: @@ -539,7 +539,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # Check the neighbor entries are still in appDB correctly for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: @@ -549,7 +549,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: @@ -586,10 +586,10 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # delete even nummber of ipv4/ipv6 neighbor entries from each interface for i in range(0, len(ips), 2): - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i//2])) for i in range(0, len(v6ips), 2): - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i//2])) # start neighsyncd again start_neighsyncd(dvs) @@ -598,7 +598,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) #should not see deleted neighbor entries if i % 2 == 0: assert status == False @@ -614,7 +614,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) #should not see deleted neighbor entries if i % 2 == 0: assert status == False @@ -663,17 +663,17 @@ def test_swss_neighbor_syncup(self, dvs, testlog): (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) print(output) if output: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) else: - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) for i in range(0, len(v6ips), 2): (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) print(output) if output: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) else: - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) # start neighsyncd again start_neighsyncd(dvs) @@ -685,7 +685,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors, should see all neighbors for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -694,7 +694,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -740,15 +740,15 @@ def test_swss_neighbor_syncup(self, dvs, testlog): for i in range(len(ips)): if i % 2 == 0: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], newmacs[i])) else: - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i//2])) for i in range(len(v6ips)): if i % 2 == 0: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], newmacs[i])) else: - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i//2])) # start neighsyncd again start_neighsyncd(dvs) @@ -765,7 +765,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors, should see all neighbors with updated info for i in range(len(ips)): if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -773,12 +773,12 @@ def test_swss_neighbor_syncup(self, dvs, testlog): if v[0] == "family": assert v[1] == "IPv4" else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == False for i in range(len(v6ips)): if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -786,7 +786,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): if v[0] == "family": assert v[1] == "IPv6" else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == False time.sleep(2) @@ -1947,11 +1947,11 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # should finish the store within 10 seconds time.sleep(10) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) # check syslog and sairedis.rec file for activities check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") @@ -1972,7 +1972,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) + check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS//2)) (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 @@ -1980,9 +1980,9 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # Remove stale entries manually for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4, j+NUM_NEIGH_PER_INTF//2+2, i*4)]) + dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4, j+NUM_NEIGH_PER_INTF//2+2, i*4)]) time.sleep(5) @@ -2022,7 +2022,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): check_kernel_reachable_neigh_num(dvs, 0) # bring down half of the links - for i in range(8, 8+NUM_INTF/2): + for i in range(8, 8+NUM_INTF//2): dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) # start neighsyncd and restore_neighbors @@ -2032,8 +2032,8 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # restore for up interfaces should be done within 10 seconds time.sleep(10) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) @@ -2048,8 +2048,8 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # check syslog and sairedis.rec file for activities - #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") - #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") + #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS//2, "ipv4") + #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS//2, "ipv6") (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) assert nadd == 0 assert ndel == NUM_OF_NEIGHS