From: fumihiko kakuma Date: Sat, 8 Aug 2015 14:20:45 +0000 (+0900) Subject: Python 3: specify a bytes to an argument for a format type 's' of struct.pack() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9744ef78e6916f6eca8dd73da6417d0f1f79563e;p=openstack-build%2Fneutron-build.git Python 3: specify a bytes to an argument for a format type 's' of struct.pack() In python 3, a format type 's' of struct.pack() requires a bytes object to an argument. Change-Id: Ia4640b31c31b5b7454cd1582af46562fb1885726 Blueprint: neutron-python3 --- diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index 30d3f5cc0..3594a1b38 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -33,6 +33,7 @@ from oslo_log import log as logging from oslo_log import loggers from oslo_rootwrap import client from oslo_utils import excutils +import six from six.moves import http_client as httplib from neutron.agent.common import config @@ -149,8 +150,10 @@ def get_interface_mac(interface): MAC_START = 18 MAC_END = 24 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - info = fcntl.ioctl(s.fileno(), 0x8927, - struct.pack('256s', interface[:constants.DEVICE_NAME_MAX_LEN])) + dev = interface[:constants.DEVICE_NAME_MAX_LEN] + if isinstance(dev, six.text_type): + dev = dev.encode('utf-8') + info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', dev)) return ''.join(['%02x:' % ord(char) for char in info[MAC_START:MAC_END]])[:-1] diff --git a/tox.ini b/tox.ini index f5094b0cc..7cbbbe9b2 100644 --- a/tox.ini +++ b/tox.ini @@ -208,6 +208,7 @@ commands = python -m testtools.run \ neutron.tests.unit.agent.linux.test_bridge_lib \ neutron.tests.unit.agent.linux.test_ip_link_support \ neutron.tests.unit.agent.linux.test_interface \ + neutron.tests.unit.agent.linux.test_utils \ neutron.tests.unit.agent.dhcp.test_agent \ neutron.tests.unit.test_manager \ neutron.tests.unit.test_service \