Merge "Raise RetryRequest on policy parent not found" into stable/liberty

This commit is contained in:
Jenkins 2016-02-03 05:58:37 +00:00 committed by Gerrit Code Review
commit 9f3dec1ef0
2 changed files with 21 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import collections
import re
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_policy import policy
from oslo_utils import excutils
@ -261,6 +262,13 @@ class OwnerCheck(policy.Check):
target[parent_foreign_key],
fields=[parent_field])
target[self.target_field] = data[parent_field]
except exceptions.NotFound as e:
# NOTE(kevinbenton): a NotFound exception can occur if a
# list operation is happening at the same time as one of
# the parents and its children being deleted. So we issue
# a RetryRequest so the API will redo the lookup and the
# problem items will be gone.
raise db_exc.RetryRequest(e)
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE('Policy check error while calling %s!'),

View File

@ -16,6 +16,7 @@
"""Test of Policy Engine For Neutron"""
import mock
from oslo_db import exception as db_exc
from oslo_policy import policy as oslo_policy
from oslo_serialization import jsonutils
from oslo_utils import importutils
@ -538,6 +539,18 @@ class NeutronPolicyTestCase(base.BaseTestCase):
action,
target)
def test_retryrequest_on_notfound(self):
failure = exceptions.NetworkNotFound(net_id='whatever')
action = "create_port:mac"
with mock.patch.object(manager.NeutronManager.get_instance().plugin,
'get_network', side_effect=failure):
target = {'network_id': 'whatever'}
try:
policy.enforce(self.context, action, target)
self.fail("Did not raise RetryRequest")
except db_exc.RetryRequest as e:
self.assertEqual(failure, e.inner_exc)
def test_enforce_tenant_id_check_parent_resource_bw_compatibility(self):
def fakegetnetwork(*args, **kwargs):