Skip to content

Commit

Permalink
[vstest]: change float division to integer division
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan committed Jul 7, 2020
1 parent 6adaf2e commit 26efbcf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions tests/port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ****"
Expand Down
94 changes: 47 additions & 47 deletions tests/test_warm_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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)
Expand All @@ -765,28 +765,28 @@ 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":
assert v[1] == newmacs[i]
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":
assert v[1] == newmacs[i]
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)
Expand Down Expand Up @@ -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")
Expand All @@ -1972,17 +1972,17 @@ 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
assert ndel == 0

# 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)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 26efbcf

Please sign in to comment.