|
40 | 40 | LOG = logging.getLogger(__name__)
|
41 | 41 |
|
42 | 42 |
|
43 |
| -def rule_if_system(system_rule, non_system_rule, context): |
44 |
| - """Helper function to pick a rule based on system-ness of context. |
45 |
| -
|
46 |
| - This can be used (with functools.partial) to choose between two |
47 |
| - rule names, based on whether or not the context has system |
48 |
| - scope. Specifically if we will fail the parent of a nested policy |
49 |
| - check based on scope_types=['project'], this can be used to choose |
50 |
| - the parent rule name for the error message check in |
51 |
| - common_policy_check(). |
52 |
| -
|
53 |
| - """ |
54 |
| - if context.system_scope: |
55 |
| - return system_rule |
56 |
| - else: |
57 |
| - return non_system_rule |
58 |
| - |
59 |
| - |
60 | 43 | class ServersPolicyTest(base.BasePolicyTest):
|
61 | 44 | """Test Servers APIs policies with all possible context.
|
62 | 45 | This class defines the set of context with different roles
|
@@ -216,7 +199,8 @@ def fake_get_all(context, search_opts=None,
|
216 | 199 | if not CONF.oslo_policy.enforce_scope:
|
217 | 200 | check_rule = rule_name
|
218 | 201 | else:
|
219 |
| - check_rule = functools.partial(rule_if_system, rule, rule_name) |
| 202 | + check_rule = functools.partial( |
| 203 | + base.rule_if_system, rule, rule_name) |
220 | 204 |
|
221 | 205 | self.common_policy_auth(self.all_projects_admin_authorized_contexts,
|
222 | 206 | check_rule,
|
@@ -267,7 +251,8 @@ def fake_get_all(context, search_opts=None,
|
267 | 251 | if not CONF.oslo_policy.enforce_scope:
|
268 | 252 | check_rule = rule_name
|
269 | 253 | else:
|
270 |
| - check_rule = functools.partial(rule_if_system, rule, rule_name) |
| 254 | + check_rule = functools.partial( |
| 255 | + base.rule_if_system, rule, rule_name) |
271 | 256 |
|
272 | 257 | self.common_policy_auth(self.all_projects_admin_authorized_contexts,
|
273 | 258 | check_rule,
|
@@ -664,7 +649,8 @@ def test_rebuild_trusted_certs_server_policy(self, mock_rebuild):
|
664 | 649 | if not CONF.oslo_policy.enforce_scope:
|
665 | 650 | check_rule = rule_name
|
666 | 651 | else:
|
667 |
| - check_rule = functools.partial(rule_if_system, rule, rule_name) |
| 652 | + check_rule = functools.partial( |
| 653 | + base.rule_if_system, rule, rule_name) |
668 | 654 |
|
669 | 655 | self.common_policy_auth(self.project_action_authorized_contexts,
|
670 | 656 | check_rule,
|
@@ -740,7 +726,8 @@ def test_create_image_allow_volume_backed_server_policy(self,
|
740 | 726 | if not CONF.oslo_policy.enforce_scope:
|
741 | 727 | check_rule = rule_name
|
742 | 728 | else:
|
743 |
| - check_rule = functools.partial(rule_if_system, rule, rule_name) |
| 729 | + check_rule = functools.partial( |
| 730 | + base.rule_if_system, rule, rule_name) |
744 | 731 | self.common_policy_auth(self.project_action_authorized_contexts,
|
745 | 732 | check_rule,
|
746 | 733 | self.controller._action_create_image,
|
|
0 commit comments