Merge "Raise RetryRequest on policy parent not found"

This commit is contained in:
Jenkins 2016-01-28 12:49:43 +00:00 committed by Gerrit Code Review
commit cdd9bb3f4e
2 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,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
@ -257,6 +258,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 fixture as op_fixture
from oslo_policy import policy as oslo_policy
from oslo_serialization import jsonutils
@ -537,6 +538,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):