Account for Py2/Py3 differences in fcntl.ioctl return value
Closes-Bug: #1630439 Change-Id: Icc7bc9372d87dfd6cc15a2b472e38250479ac4ec
This commit is contained in:
parent
80d4df144d
commit
eb1efc7ace
|
@ -33,6 +33,7 @@ from oslo_log import log as logging
|
||||||
from oslo_rootwrap import client
|
from oslo_rootwrap import client
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from six import iterbytes
|
||||||
from six.moves import http_client as httplib
|
from six.moves import http_client as httplib
|
||||||
|
|
||||||
from neutron._i18n import _, _LE
|
from neutron._i18n import _, _LE
|
||||||
|
@ -155,8 +156,7 @@ def get_interface_mac(interface):
|
||||||
dev = interface[:constants.DEVICE_NAME_MAX_LEN]
|
dev = interface[:constants.DEVICE_NAME_MAX_LEN]
|
||||||
dev = encodeutils.to_utf8(dev)
|
dev = encodeutils.to_utf8(dev)
|
||||||
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', dev))
|
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', dev))
|
||||||
return ''.join(['%02x:' % ord(char)
|
return ':'.join(["%02x" % b for b in iterbytes(info[MAC_START:MAC_END])])
|
||||||
for char in info[MAC_START:MAC_END]])[:-1]
|
|
||||||
|
|
||||||
|
|
||||||
def find_child_pids(pid):
|
def find_child_pids(pid):
|
||||||
|
|
|
@ -174,9 +174,9 @@ class AgentUtilsGetInterfaceMAC(base.BaseTestCase):
|
||||||
def test_get_interface_mac(self):
|
def test_get_interface_mac(self):
|
||||||
expect_val = '01:02:03:04:05:06'
|
expect_val = '01:02:03:04:05:06'
|
||||||
with mock.patch('fcntl.ioctl') as ioctl:
|
with mock.patch('fcntl.ioctl') as ioctl:
|
||||||
ioctl.return_value = ''.join(['\x00' * 18,
|
ioctl.return_value = b''.join([b'\x00' * 18,
|
||||||
'\x01\x02\x03\x04\x05\x06',
|
b'\x01\x02\x03\x04\x05\x06',
|
||||||
'\x00' * 232])
|
b'\x00' * 232])
|
||||||
actual_val = utils.get_interface_mac('eth0')
|
actual_val = utils.get_interface_mac('eth0')
|
||||||
self.assertEqual(actual_val, expect_val)
|
self.assertEqual(actual_val, expect_val)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue