Ensure that bulk port dicts have unix-style MAC addresses

The bulk port code uses the Port OVO object, which encodes MAC address
as a netaddr.EUI object.  The default string representation for a
netaddr.EUI object is the standard IEEE EUI-48 format
("XX-XX-XX-XX-XX-XX") [1].  Having MAC addresses in that format breaks
the midonet gate, so revert to UNIX standard mac addresses
("xx:xx:xx:xx:xx:xx").

[1] https://netaddr.readthedocs.io/en/latest/tutorial_02.html#formatting

Change-Id: I2d2727335c347accdeb39cbac5151722e8a3339c
Closes-Bug: #1822999
This commit is contained in:
Nate Johnston 2019-04-03 09:27:37 -04:00
parent deab12c155
commit dd95246fbe
1 changed files with 5 additions and 1 deletions

View File

@ -15,6 +15,7 @@
import functools
import netaddr
import six
from neutron_lib.api.definitions import network as net_def
@ -203,11 +204,14 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
def _make_port_dict(self, port, fields=None,
process_extensions=True):
mac = port["mac_address"]
if isinstance(mac, netaddr.EUI):
mac.dialect = netaddr.mac_unix_expanded
res = {"id": port["id"],
'name': port['name'],
"network_id": port["network_id"],
'tenant_id': port['tenant_id'],
"mac_address": str(port["mac_address"]),
"mac_address": str(mac),
"admin_state_up": port["admin_state_up"],
"status": port["status"],
"fixed_ips": [{'subnet_id': ip["subnet_id"],