From daa8e1b1b0c2ec5353b20aae155cea668c637ffc Mon Sep 17 00:00:00 2001 From: lilintan Date: Wed, 28 Sep 2016 14:12:38 +0800 Subject: [PATCH] Neutron server was not compatible with member actions Register a new extension into Neutron server, and this extension contains a member action. if new member action contains the "update" string. As a result, Neutron server check the target whether contains "ATTRIBUTES_TO_UPDATE". Because this is a member action so that neutron server will not go "_update" method normally but "_handle_action" method. So the exception happens KeyError: 'attributes_to_update'. Co-Authored-By: zhang ping Change-Id: Ie8bb7b9af42a82aada28d2bcdfd5b0e573ad9778 Closes-Bug: #1606455 --- neutron/policy.py | 2 +- neutron/tests/unit/test_policy.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/neutron/policy.py b/neutron/policy.py index 19541a99218..05426a041c1 100644 --- a/neutron/policy.py +++ b/neutron/policy.py @@ -85,7 +85,7 @@ def set_rules(policies, overwrite=True): def _is_attribute_explicitly_set(attribute_name, resource, target, action): """Verify that an attribute is present and is explicitly set.""" - if 'update' in action: + if target.get(const.ATTRIBUTES_TO_UPDATE): # In the case of update, the function should not pay attention to a # default value of an attribute, but check whether it was explicitly # marked as being updated instead. diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index 59b21cccae4..6ebf1927449 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -463,6 +463,12 @@ class NeutronPolicyTestCase(base.BaseTestCase): result = policy._build_match_rule(action, target, None) self.assertEqual("rule:" + action, str(result)) + def test_build_match_rule_normal_pluralized_when_update(self): + action = "update_" + FAKE_RESOURCE_NAME + target = {} + result = policy._build_match_rule(action, target, None) + self.assertEqual("rule:" + action, str(result)) + def test_enforce_subattribute(self): action = "create_" + FAKE_RESOURCE_NAME target = {'tenant_id': 'fake', 'attr': {'sub_attr_1': 'x'}}