Faulty XML deserialization

Bug #798262 reported by Salvatore Orlando
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Critical
Salvatore Orlando
quantum (Ubuntu)
Fix Released
Undecided
Unassigned
Nominated for Precise by Yolanda Robla

Bug Description

Deserialization of XML responses does not work well with lists:

For instance:
<networks>
    <network id="047"/>
    <network id="045"/>
    <network id="044"/>
    <network id="043"/>
    <network id="002"/>
    <network id="001"/>
    <network id="026"/>
    <network id="021"/>
    <network id="020"/>
    <network id="023"/>
    <network id="022"/>
    <network id="033"/>
    <network id="046"/>
    <network id="009"/>
    <network id="008"/>
    <network id="029"/>
    <network id="028"/>
    <network id="041"/>
    <network id="040"/>
    <network id="024"/>
    <network id="027"/>
    <network id="007"/>
    <network id="006"/>
</networks>

When deserialized, is transformed into the following dictionary:

{u'networks': {u'network': {u'id': u'006'}}}

Related branches

Changed in quantum:
assignee: nobody → Salvatore Orlando (salvatore-orlando)
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

There are two components in this bug:
1) the test case in which it was found was not using the deserializer properly, as metadata for plurals (eg.: networks/network) were not specified
2) the code for handling building the set corresponding to a collection of XML nodes was not filtering out text nodes.

Changed in quantum:
status: New → In Progress
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

Waiting for unit-tests branch to land in trunk before proposing for merge

Changed in quantum:
importance: Undecided → Medium
Changed in quantum:
status: In Progress → Fix Committed
Revision history for this message
dan wendlandt (danwent) wrote :

Hi Salvatore, I still seem to be seeing this with the latest trunk when using the client lib. Not sure why the unit tests are not seeing this.

For example, the client gets the following XML back, showing 4 networks:

<networks><network id="a61a7eab-1c93-43df-9225-6f166f122fea"/><network id="4a50deb5-c960-4e73-b23d-a60cc4c6b94f"/><network id="6bbeac1a-48ce-4ab3-9c64-d531473016dd"/><network id="78641c7b-8aef-4223-b8ba-d5769e9a9212"/></networks>

But the deserialized data looks like:

 {u'networks': {u'network': {u'id': u'78641c7b-8aef-4223-b8ba-d5769e9a9212'}}}

Can easily be reproduced by changing the format in quantum/cli.py to xml, then running:

PYTHONPATH=.:$PYTHONPATH python quantum/cli.py create_net foo net1
PYTHONPATH=.:$PYTHONPATH python quantum/cli.py create_net foo net2
$PYTHONPATH python quantum/cli.py list_nets foo

The list_net command will blow up with:

Traceback (most recent call last):
  File "quantum/cli.py", line 386, in <module>
    commands[cmd]["api_func"](client, *args)
  File "quantum/cli.py", line 52, in api_list_nets
    net_id = n["id"]
TypeError: string indices must be integers

Changed in quantum:
status: Fix Committed → New
milestone: none → diablo-4
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

I think this can be sorted out by instantiating the deserializer with appropriate metadata.

If you look at APITest.setUp you will that we are allocationg serializers with serialization metadata from network and port API controllers.

Serialization metadata contains useful instructions for XML serializing and deserializing. The issue you're seeing is probably caused by a missing "plurals" directive; these directives are used to make sure the xml deserializer correctly renders a set of xml elements with the same name as a list rather than a dictionary.

Please let me know if using metadata solves your issue. Otherwise I will have another look into this bug.

Changed in quantum:
status: New → In Progress
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

Raising level to critical; if this bug is still open this implies Quantum API cannot support XML, and that would be terribly bad

Changed in quantum:
importance: Medium → Critical
Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

Hi Dan,

did you had a chance to try using the serializer initialized with metadata?

Revision history for this message
Salvatore Orlando (salvatore-orlando) wrote :

I can confirm the issue was due to missing serialization metadata in the client module.

The newly attached branch fixes this issue.

dan wendlandt (danwent)
Changed in quantum:
status: In Progress → Fix Committed
dan wendlandt (danwent)
Changed in quantum:
status: Fix Committed → Fix Released
Changed in quantum (Ubuntu):
status: New → Fix Released
tags: added: neutron-proactive-backport-potential
tags: removed: neutron-proactive-backport-potential
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.