[OVO] UT fails when setting new_facade to True

Bug #1750735 reported by Lujin Luo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Undecided
Lujin Luo

Bug Description

How to reproduce:
1) Set new_facade = True in any OVO object. I tried PortBinding(), Port() and Network().
2) Run python -m testtools.run neutron/tests/unit/objects/test_network.py
   or python -m testtools.run neutron/tests/unit/objects/test_port.py
3) Example of failures:
======================================================================
ERROR: neutron.tests.unit.objects.test_network.NetworkObjectIfaceTestCase.test_update_updates_from_db_object
----------------------------------------------------------------------
Traceback (most recent call last):
  File "neutron/tests/base.py", line 132, in func
    return f(self, *args, **kwargs)
  File "neutron/tests/base.py", line 132, in func
    return f(self, *args, **kwargs)
  File "/home/stack/small_port_2/neutron/.tox/py27/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "neutron/tests/unit/objects/test_base.py", line 1167, in test_update_updates_from_db_object
    obj.update()
  File "neutron/objects/base.py", line 319, in decorator
    self.obj_context.session.refresh(self.db_obj)
  File "/home/stack/small_port_2/neutron/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1498, in refresh
    self._expire_state(state, attribute_names)
  File "/home/stack/small_port_2/neutron/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1600, in _expire_state
    self._validate_persistent(state)
  File "/home/stack/small_port_2/neutron/.tox/py27/local/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2042, in _validate_persistent
    state_str(state))
sqlalchemy.exc.InvalidRequestError: Instance '<Network at 0x7febff8aea90>' is not persistent within this Session

I believe something merged after Feb. 9th breaks them. As in [1], no codes changes from Feb. 9th but it fails on recheck on Feb. 20th.

[1] https://review.openstack.org/#/c/537320/

Update ==============================================================
I think it is [1] which introduces new_facade attr is causing trouble. I need to double check.

[1] https://github.com/openstack/neutron/commit/6f83466307fb21aee5bb596974644d457ae1fa60#diff-e900a9020bbb5db562fe3b148873a78d

=====================================================================
Update on 06/03/2018
After some more digging, I found the root cause of this bug is due to new engine facade will start a new session. then these two lines [2] are not applied.

(py27) stack@luo-dev:~/small_port_2/neutron$ python -m testtools.run neutron.tests.unit.objects.test_ports.PortIfaceObjTestCase.test_get_object_unique_key
Tests running...
> /home/stack/small_port_2/neutron/neutron/tests/unit/objects/test_base.py(803)test_get_object_unique_key()
-> print self.context
(Pdb) c
<neutron_lib.context.Context object at 0x7f486878a550>
<sqlalchemy.orm.session.Session object at 0x7f48683d6610>
> /home/stack/small_port_2/neutron/neutron/objects/base.py(553)get_object()
-> print context
(Pdb) c
<neutron_lib.context.Context object at 0x7f486878a550>
<sqlalchemy.orm.session.Session object at 0x7f48683d6610>
> /home/stack/small_port_2/neutron/neutron/objects/base.py(557)get_object()
-> print context
(Pdb) c
<neutron_lib.context.Context object at 0x7f486878a550>
<sqlalchemy.orm.session.Session object at 0x7f4867e9ee50>

[2] https://github.com/openstack/neutron/blob/master/neutron/tests/unit/objects/test_base.py#L695-L696

Lujin Luo (luo-lujin)
description: updated
Lujin Luo (luo-lujin)
Changed in neutron:
assignee: nobody → Lujin Luo (luo-lujin)
Lujin Luo (luo-lujin)
description: updated
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/551192

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/551192
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=3002df76d1133697cd0c3494c272cd41606d5899
Submitter: Zuul
Branch: master

commit 3002df76d1133697cd0c3494c272cd41606d5899
Author: Lujin <email address hidden>
Date: Fri Mar 9 16:05:05 2018 +0900

    Fix UTs to accommodate new_facade flag in OVO objects

    In current UTs, in tests that do not actually touch databases,
    we mock out refresh and expunge in current context. This will
    not work under new engine facade, as new sessions are created
    everytime.

    We will need this fix when we set any object's new_facade flag
    to True.

    Closes-Bug: #1750735

    Change-Id: I3a8bc06a671e37959e3014f8672b9a5e118c5c52

Changed in neutron:
status: In Progress → Fix Released
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/553754

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/553754
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=97730821ef43d7abf76212865b5b24007f2f7f63
Submitter: Zuul
Branch: master

commit 97730821ef43d7abf76212865b5b24007f2f7f63
Author: Lujin <email address hidden>
Date: Fri Mar 16 20:24:47 2018 +0900

    Add a test class to validate UTs fixes of new_facade flag

    In I3a8bc06a671e37959e3014f8672b9a5e118c5c52, we added mocks to
    avoid touching databases when switching to new engine facade.
    However, currently we do not have test codes to catch those failure.
    This patch adds a fake object setting new_facade to True, to validate
    without I3a8bc06a671e37959e3014f8672b9a5e118c5c52, the test class
    would fail.

    Change-Id: I968806b237f9c1275e7624a0995189c1d0bc75fb
    Closes-Bug: #1750735

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

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

tags: added: neutron-proactive-backport-potential
tags: added: neutron-easy-proactive-backport-potential
tags: removed: neutron-easy-proactive-backport-potential 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.