From 011117bebcf05f6ef17a3d63155dec630ae88cc3 Mon Sep 17 00:00:00 2001 From: bingwang Date: Sun, 11 Oct 2020 20:23:05 -0700 Subject: [PATCH] Fix exception for ipaddress in python2 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 --- scripts/fast-reboot-dump.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/fast-reboot-dump.py b/scripts/fast-reboot-dump.py index eebb2a8a5e..3881e9f5f4 100644 --- a/scripts/fast-reboot-dump.py +++ b/scripts/fast-reboot-dump.py @@ -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 @@ -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)) @@ -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)