Account for Py2/Py3 differences in fcntl.ioctl return value

Closes-Bug: #1630439

Change-Id: Icc7bc9372d87dfd6cc15a2b472e38250479ac4ec
This commit is contained in:
Henry Gessau 2016-10-05 22:33:20 -04:00
parent 80d4df144d
commit eb1efc7ace
2 changed files with 5 additions and 5 deletions

View File

@ -33,6 +33,7 @@ from oslo_log import log as logging
from oslo_rootwrap import client
from oslo_utils import encodeutils
from oslo_utils import excutils
from six import iterbytes
from six.moves import http_client as httplib
from neutron._i18n import _, _LE
@ -155,8 +156,7 @@ def get_interface_mac(interface):
dev = interface[:constants.DEVICE_NAME_MAX_LEN]
dev = encodeutils.to_utf8(dev)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', dev))
return ''.join(['%02x:' % ord(char)
for char in info[MAC_START:MAC_END]])[:-1]
return ':'.join(["%02x" % b for b in iterbytes(info[MAC_START:MAC_END])])
def find_child_pids(pid):

View File

@ -174,9 +174,9 @@ class AgentUtilsGetInterfaceMAC(base.BaseTestCase):
def test_get_interface_mac(self):
expect_val = '01:02:03:04:05:06'
with mock.patch('fcntl.ioctl') as ioctl:
ioctl.return_value = ''.join(['\x00' * 18,
'\x01\x02\x03\x04\x05\x06',
'\x00' * 232])
ioctl.return_value = b''.join([b'\x00' * 18,
b'\x01\x02\x03\x04\x05\x06',
b'\x00' * 232])
actual_val = utils.get_interface_mac('eth0')
self.assertEqual(actual_val, expect_val)