]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commit
Retry port create/update on duplicate db records
authorKevin Benton <blak111@gmail.com>
Fri, 15 Jan 2016 04:23:32 +0000 (20:23 -0800)
committerKevin Benton <blak111@gmail.com>
Fri, 15 Jan 2016 04:40:49 +0000 (20:40 -0800)
commitf67fc3cb08ce4f0e6fc685801a243fe68503578e
treedddd0b9e84badde144b08904feffc35202bc3815
parentfeced76488ea99355c605e0bc719723931621693
Retry port create/update on duplicate db records

Even though we have a duplicate IP check before creating an IP
allocation, there is a window between when that check is completed
and when the record is committed to the database. During this window,
another thread or server may use the same IP address, which will result
in the database commit failing with a DBDuplicateEntry exception.

This patch adds a decorator to convert the exception into a
RetryRequest, which will be caught at the API layer to start the
operation over, at which point the normal duplicate check will find
the IP and return the correct error to the user.

This was done instead of trying to convert the DBDuplicate to the
correct exception since it's on commit and there are possibly many
different sources of the duplicate record beyond the IP allocation
(depending on what mechanism drivers did during pre-commit, etc).
By retrying the request, we ensure that the prechecks run again that
will raise the appropriate exception.

Change-Id: I37a964497bf60a61bc49bdeec94a008f167c384f
Closes-Bug: #1534447
neutron/db/api.py
neutron/plugins/ml2/plugin.py
neutron/tests/unit/db/test_api.py [new file with mode: 0644]
neutron/tests/unit/plugins/ml2/test_plugin.py