You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install ptf 0.9.3, my python version is 3.7.
In my script, just want to get mac address based on device number and port number, such as self.dataplane.get_mac(0, 2).
It throws TypeError error. I think it shouldn't use ord(char) in get_mac function for python3.
After remove ord, it returns correct mac address.
How to resolve this compatible issue for python3? Thanks.
Traceback (most recent call last):
File "ptftests/dhcp_relay_test.py", line 114, in setUp
self.server_iface_mac = self.dataplane.get_mac(0, 2)
File "/env-python3/lib/python3.7/site-packages/ptf/dataplane.py", line 990, in get_mac
return self.ports[(device_number, port_number)].mac()
File "/env-python3/lib/python3.7/site-packages/ptf/dataplane.py", line 198, in mac
return netutils.get_mac(self.interface_name)
File "/env-python3/lib/python3.7/site-packages/ptf/netutils.py", line 57, in get_mac
return ":".join(["%02x" % ord(char) for char in get_if(iff, SIOCGIFHWADDR)[18:24]])
File "/env-python3/lib/python3.7/site-packages/ptf/netutils.py", line 57, in <listcomp>
return ":".join(["%02x" % ord(char) for char in get_if(iff, SIOCGIFHWADDR)[18:24]])
TypeError: ord() expected string of length 1, but int found
>>> import socket
>>> from fcntl import ioctl
>>> import struct
>>> SIOCGIFHWADDR = 0x8927
>>> s = socket.socket()
>>> ifreq = ioctl(s, SIOCGIFHWADDR, struct.pack("16s16x", 'eth2'.encode("utf-8")))
>>> ifreq
b'eth2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\xfeT\x00\xba~\x02\x00\x00\x00\x00\x00\x00\x00\x00'
>>> ":".join(["%02x" % ord(char) for char in ifreq[18:24]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
TypeError: ord() expected string of length 1, but int found
>>> ":".join(["%02x" % char for char in ifreq[18:24]])
'fe:54:00:ba:7e:02'
>>> exit()
(env-python3) root@14d1d69ee82f:~# ifconfig eth2
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9216
inet6 fe80::fc54:ff:feba:7e02 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:ba:7e:02 txqueuelen 1000 (Ethernet)
RX packets 14360 bytes 1683464 (1.6 MiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 703 bytes 69618 (67.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The text was updated successfully, but these errors were encountered:
Why I did it
Migrate ptftests script to python3, in order to do an incremental migration, add python virtual environment firstly, install all required python packages in virtual env as well.
Then migrate ptftests scripts from python2 to python3 one by one avoid impacting non-changed scripts.
Signed-off-by: Zhaohui Sun [email protected]
How I did it
Add python3 virtual environment for docker-ptf.
Add submodule ptf-py3 and install patched ptf 0.9.3 into virtual environment as well, two ptf issues were reported here:
p4lang/ptf#173p4lang/ptf#174
Signed-off-by: Zhaohui Sun <[email protected]>
Install ptf 0.9.3, my python version is 3.7.
In my script, just want to get mac address based on device number and port number, such as
self.dataplane.get_mac(0, 2)
.It throws TypeError error. I think it shouldn't use ord(char) in get_mac function for python3.
After remove ord, it returns correct mac address.
How to resolve this compatible issue for python3? Thanks.
The text was updated successfully, but these errors were encountered: