OVO to_dict() is returning timestamps with microseconds

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

Bug Description

to_dict() doesn't seem to be calling the stringify or to_primitive method on the objects because microseconds are being leaked out when trying to expose the created_at/updated_at fields via the API.

Traceback (most recent call last):
  File "/opt/stack/new/neutron/neutron/tests/tempest/api/test_qos.py", line 338, in test_get_policy_that_is_shared
    self.assertEqual(obtained_policy, policy)
  File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 411, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 498, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: !=:
reference = {u'created_at': u'2016-09-03 01:08:00',
 u'description': u'shared policy',
 u'id': u'b24af3be-d19d-4543-8b12-25ac6d752abd',
 u'name': u'test-policy-shared',
 u'rules': [],
 u'shared': True,
 u'tenant_id': u'a88290171ee648dfa97b8e164b9ede31',
 u'updated_at': u'2016-09-03 01:08:00'}
actual = {u'created_at': u'2016-09-03 01:08:00.106856',
 u'description': u'shared policy',
 u'id': u'b24af3be-d19d-4543-8b12-25ac6d752abd',
 u'name': u'test-policy-shared',
 u'rules': [],
 u'shared': True,
 u'tenant_id': u'a88290171ee648dfa97b8e164b9ede31',
 u'updated_at': u'2016-09-03 01:08:00.106856'}

Changed in neutron:
assignee: nobody → Kevin Benton (kevinbenton)
milestone: none → newton-rc1
summary: - OVO DateTimeField is not compatible with our timestamps
+ OVO to_dict() is returning timestamps with microseconds
description: updated
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/365684

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

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

commit 3756bc510526531e3442da6d825cc90f44faa355
Author: Kevin Benton <email address hidden>
Date: Mon Sep 5 08:26:01 2016 -0600

    Convert OVO fields to primitives for to_dict()

    to_dict() is used for conversions of OVO objects into
    regular dictionaries to be used as plugin return values
    to the API layer, etc. It provides the equivalent of
    make_<resource>_dict that we use now (without the extension
    processing). The values in these dictionaries should be
    ready for representation in the API.

    The issue was that the OVO to_dict() implementation was
    placing complex types right into the dictionary which
    would mean that the API would serialize them just by
    calling str() on them (as part of json encoding). This
    ignored the 'to_primitive' method defined on the OVO
    type that defines how a field should be converted.
    Therefore, when it came to timestamps to_dict() was
    placing native datetime objects into the dictionary
    which would convert to microsecond resolution, violating
    the expected format of the OVO DateTime type.

    This patch fixes the issue by calling 'to_primitive'
    on each non-synthetic field in the to_dict() method
    to ensure we match the expected format of the type before
    we send it out the API.

    Closes-Bug: #1620254
    Change-Id: Ic0be54b1d4b23119e1458d4532e2f70bff0ff9f6

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

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

commit 72c3398dfe865f65eb6ccf642174769784c74cca
Author: Armando Migliaccio <email address hidden>
Date: Fri Sep 2 11:45:56 2016 -0700

    Include timestamps in trunk API test comparisions

    Related-bug: #1620254

    Change-Id: Ied857791c5ee1013e27efd642b7fa271ae683ff4

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 9.0.0.0rc1

This issue was fixed in the openstack/neutron 9.0.0.0rc1 release candidate.

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.