_compare_results incorrectly reports extra list items when items in lists don't match

Bug #1545167 reported by Augustina Ragwitz
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Confirmed
Medium
Vishakha Agarwal

Bug Description

I discovered this bug while refactoring functional tests. This happens in the current Nova master.

The _compare_results function is defined in nova/tests/functional/api_samples_test_base.py

To reproduce, pass two lists to _compare_results that are the same length but have one item not equal.

list1 = [{u'foo': u'bar', u'bar': u'baz'}]

list2 = [{u'foo': u'baz', u'bar': u'baz'}]

_compare_results returns the following:

nova.tests.functional.api_samples_test_base.NoMatch: Extra list items in template:
{u'foo': u'bar', u'bar': u'baz'}
Extra list items in Test:
{u'foo': u'baz', u'bar': u'baz'}

While this is "technically" accurate, it's really hard to debug if you can imagine a lengthy, nested json file dumped into that response.

_compare_results is already checking each item in the list, it should just be returning a list of keys that don't match, not the whole thing!

Tags: testing
Changed in nova:
status: Confirmed → In Progress
Changed in nova:
status: In Progress → Confirmed
Revision history for this message
Sarafraj Singh (sarafraj-singh) wrote :

Auggy,
Are you working on the fix? Please change status to Inprogress if you are, otherwise change Assigned to ->nobody.

Revision history for this message
Takashi Natsume (natsume-takashi) wrote :

A bug report with an assignee should be 'In Progress' status.
So set 'In Progress'.

Changed in nova:
status: Confirmed → In Progress
Revision history for this message
Augustina Ragwitz (auggy) wrote :

This is on my TODO list but I haven't made working on it a priority so moving to unassigned in case anyone else wants to give it a shot.

Changed in nova:
status: In Progress → Confirmed
assignee: Augustina Ragwitz (auggy) → nobody
Prateek Arora (parora)
Changed in nova:
assignee: nobody → Prateek Arora (parora)
Prateek Arora (parora)
Changed in nova:
status: Confirmed → In Progress
Revision history for this message
Prateek Arora (parora) wrote :

The code is not written to handle cases that have nested data structures and in case the nested list won't match word for word, it would fully return the elements as they have not found any match. IMO the compare results need to call itself in case it encounters a dict or a list and retry matching.

Revision history for this message
Prateek Arora (parora) wrote :

Auggy, IMO the nested list(or dicts) comparison is possible only when we have one extra list in the result as well as expected keys, but in case we have more than 1 in both, it is computationally not good to check the closest dictionary in the expected dictionaries and result dictionaries.

Assuming we get 3 not matching lists in result
and 2 not matching lists in expected result

we would have to match 2 lists for each of the 3 lists in the result dict, find the closest companion and print.

However it would be good if we have 1 not matching dict in result as well as expected result and then find the differing keys.I would try to work on this case.

Prateek Arora (parora)
Changed in nova:
status: In Progress → Confirmed
assignee: Prateek Arora (parora) → nobody
Changed in nova:
assignee: nobody → Vishakha Agarwal (vishakha.agarwal)
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.