Clean up exception message raised by policy authority module
This PS cleans up an exception message raised by policy authority
module because it is innacurate. When a policy isn't found,
the current message says something like:
Policy action: group:reset_group_snapshot not found in policy file:
None. [0]
However, this isn't very helpful as in this case no custom policy
file is used and besides that, the policy in code is used as a source
for finding the policy. So the message has been changed to (e.g.):
Policy action "group:reset_group_snapshot" not found in policy file:
None or among registered policy in code defaults for service.
[0] http://logs.openstack.org/12/536612/2/check/patrole-admin/7367a52/job-output.txt.gz#_2018-01-23_00_15_27_996109
Change-Id: I754a03d57ae404877ad7521e25bf49a5cc7357b9
diff --git a/patrole_tempest_plugin/policy_authority.py b/patrole_tempest_plugin/policy_authority.py
index 3f4236b..6851942 100644
--- a/patrole_tempest_plugin/policy_authority.py
+++ b/patrole_tempest_plugin/policy_authority.py
@@ -292,8 +292,9 @@
def _try_rule(self, apply_rule, target, access_data, o):
if apply_rule not in self.rules:
- message = "Policy action: {0} not found in policy file: {1}."\
- .format(apply_rule, self.path)
+ message = ("Policy action \"{0}\" not found in policy file: {1} or"
+ " among registered policy in code defaults for service."
+ ).format(apply_rule, self.path)
LOG.debug(message)
raise rbac_exceptions.RbacParsingException(message)
else:
diff --git a/patrole_tempest_plugin/tests/unit/test_policy_authority.py b/patrole_tempest_plugin/tests/unit/test_policy_authority.py
index db651fc..d2074e7 100644
--- a/patrole_tempest_plugin/tests/unit/test_policy_authority.py
+++ b/patrole_tempest_plugin/tests/unit/test_policy_authority.py
@@ -269,8 +269,10 @@
test_tenant_id, test_user_id, "custom_rbac_policy")
fake_rule = 'fake_rule'
- expected_message = "Policy action: {0} not found in policy file: {1}."\
- .format(fake_rule, self.custom_policy_file)
+ expected_message = (
+ "Policy action \"{0}\" not found in policy file: {1} or among "
+ "registered policy in code defaults for service.").format(
+ fake_rule, self.custom_policy_file)
e = self.assertRaises(rbac_exceptions.RbacParsingException,
authority.allowed, fake_rule, None)
@@ -289,9 +291,10 @@
**{'__getitem__.return_value.side_effect': Exception(
mock.sentinel.error)})
- expected_message = "Policy action: {0} not found in "\
- "policy file: {1}.".format(mock.sentinel.rule,
- self.custom_policy_file)
+ expected_message = (
+ "Policy action \"{0}\" not found in policy file: {1} or among "
+ "registered policy in code defaults for service.").format(
+ mock.sentinel.rule, self.custom_policy_file)
e = self.assertRaises(rbac_exceptions.RbacParsingException,
authority.allowed, mock.sentinel.rule, None)