Skip to content

Commit

Permalink
Fix exception for ipaddress in python2 (#1164)
Browse files Browse the repository at this point in the history
The 'ipaddress.ip_interface' accepts only unicode str as input, which is
default in python3. However, an exception will raise when running in
python2. This commit fix the issue.

Signed-off-by: bingwang <bingwang@microsoft.com>
  • Loading branch information
bingwang-ms authored Oct 14, 2020
1 parent 3a7457c commit 059cdca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import syslog
import traceback
import ipaddress
from builtins import str #for unicode conversion in python2


ARP_CHUNK = binascii.unhexlify('08060001080006040001') # defines a part of the packet for ARP Request
Expand Down Expand Up @@ -39,7 +40,7 @@ def generate_neighbor_entries(filename, all_available_macs):
arp_output.append(obj)

ip_addr = key.split(':')[2]
if ipaddress.ip_interface(ip_addr).ip.version != 4:
if ipaddress.ip_interface(str(ip_addr)).ip.version != 4:
#This is ipv6 address
ip_addr = key.replace(key.split(':')[0] + ':' + key.split(':')[1] + ':', '')
neighbor_entries.append((vlan_name, mac, ip_addr))
Expand Down Expand Up @@ -232,7 +233,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(str(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 059cdca

Please sign in to comment.