Skip to content

Commit

Permalink
[fast-reboot-dump] Fix exception in struct.pack (sonic-net#1309)
Browse files Browse the repository at this point in the history
This commit fix the exception thrown by struct.pack when attempting to pack a unicode string.
The script ```fast-reboot-dump.py``` will throw an exception in python3 because ```struct.pack``` requires ```bytes``` for ```s```.
```
Traceback: Traceback (most recent call last):
#12  File "/usr/local/bin/fast-reboot-dump.py", line 299, in <module>
#12    res = main()
#12  File "/usr/local/bin/fast-reboot-dump.py", line 292, in main
#12    send_garp_nd(neighbor_entries, map_mac_ip_per_vlan)
#12  File "/usr/local/bin/fast-reboot-dump.py", line 221, in send_garp_nd
#12    src_ip_addrs = {vlan_name:get_iface_ip_addr(vlan_name) for vlan_name,_,_ in neighbor_entries}
#12  File "/usr/local/bin/fast-reboot-dump.py", line 221, in <dictcomp>
#12    src_ip_addrs = {vlan_name:get_iface_ip_addr(vlan_name) for vlan_name,_,_ in neighbor_entries}
#12  File "/usr/local/bin/fast-reboot-dump.py", line 195, in get_iface_ip_addr
#12    return get_if(iff, SIOCGIFADDR)[20:24]
#12  File "/usr/local/bin/fast-reboot-dump.py", line 185, in get_if
#12    ifreq = ioctl(s, cmd, struct.pack("16s16x",iff))
#12  struct.error: argument for 's' must be a bytes object
```

Signed-off-by: bingwang <bingwang@microsoft.com>
  • Loading branch information
bingwang-ms authored Dec 17, 2020
1 parent 269c317 commit 281b157
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def generate_fdb_entries(filename):

def get_if(iff, cmd):
s = socket.socket()
ifreq = ioctl(s, cmd, struct.pack("16s16x",iff))
ifreq = ioctl(s, cmd, struct.pack("16s16x",bytes(iff.encode())))
s.close()
return ifreq

Expand Down

0 comments on commit 281b157

Please sign in to comment.