Skip to content

Commit

Permalink
Fix unicode issue in ipaddress for python2 (#1627)
Browse files Browse the repository at this point in the history
Signed-off-by: bingwang <[email protected]>
  • Loading branch information
bingwang-ms authored May 24, 2021
1 parent cda3441 commit 5f62262
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import traceback
import ipaddress

def to_unicode(x):
if sys.version_info < (3, 0):
return unicode(x)
return str(x)

ARP_CHUNK = binascii.unhexlify('08060001080006040001') # defines a part of the packet for ARP Request
ARP_PAD = binascii.unhexlify('00' * 18)
Expand Down Expand Up @@ -96,7 +100,7 @@ def get_map_host_port_id_2_iface_name(asic_db):
port_id = value['SAI_HOSTIF_ATTR_OBJ_ID']
iface_name = value['SAI_HOSTIF_ATTR_NAME']
host_port_id_2_iface[port_id] = iface_name

return host_port_id_2_iface

def get_map_lag_port_id_2_portchannel_name(asic_db, app_db, host_port_id_2_iface):
Expand Down Expand Up @@ -274,7 +278,7 @@ def send_garp_nd(neighbor_entries, map_mac_ip_per_vlan):
# send arp/ndp packets
for vlan_name, dst_mac, dst_ip in neighbor_entries:
src_if = map_mac_ip_per_vlan[vlan_name][dst_mac]
if ipaddress.ip_interface(dst_ip).ip.version == 4:
if ipaddress.ip_interface(to_unicode(dst_ip)).ip.version == 4:
send_arp(sockets[src_if], src_mac_addrs[src_if], src_ip_addrs[vlan_name], dst_mac, dst_ip)
else:
send_ndp(sockets[src_if], src_mac_addrs[src_if], src_ip_addrs[vlan_name], dst_mac, dst_ip)
Expand Down

0 comments on commit 5f62262

Please sign in to comment.