OVO MACAddress field isn't serializable

Bug #1638664 reported by Kevin Benton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Undecided
Kevin Benton

Bug Description

The OVO MACAddress field can't be serialized to JSON because it is represented as a EUI object from netaddr without a to_primitive method.

This is what happens if you try to json encode an EUI object.

>>> json.dumps({'mac-address': netaddr.EUI('AA-BB-CC-DD-EE-FF')})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: EUI('AA-BB-CC-DD-EE-FF') is not JSON serializable

Changed in neutron:
assignee: nobody → Kevin Benton (kevinbenton)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/392931

Changed in neutron:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/392931
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=d400c04095e1e09468b3bd009ae7004b400fddea
Submitter: Jenkins
Branch: master

commit d400c04095e1e09468b3bd009ae7004b400fddea
Author: Kevin Benton <email address hidden>
Date: Wed Nov 2 11:38:15 2016 -0700

    Add 'to_primitive' for MACAddress and IPNetwork

    Both of these OVO common types did not have a to_primitive
    method, so their native netaddr objects were being passed
    to the json serializer.

    For the MACAdddress object, this resulted in an traceback
    because EUI types are not json encodable. For the IPNetwork,
    this resulted in a list of every IP address in the network.

    This fixes both by adding a 'to_primitive' method that calls
    str on the netaddr objects, which results in sane representations
    (string mac address and string CIDR).

    This adds a base test the common types test case to ensure
    all primitive representations are json serializable.

    Closes-Bug: #1638664
    Change-Id: Ic0032e3fc12de643e6900702249e69d3946faa19

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 10.0.0.0b1

This issue was fixed in the openstack/neutron 10.0.0.0b1 development milestone.

tags: added: neutron-proactive-backport-potential
tags: removed: neutron-proactive-backport-potential
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.