def _handle_deprecated_rule(self, default): deprecated_rule = default.deprecated_rule deprecated_msg = ( 'Policy "%(old_name)s":"%(old_check_str)s" was deprecated in ' '%(release)s in favor of "%(name)s":"%(check_str)s". Reason: ' '%(reason)s. Either ensure your deployment is ready for the new ' 'default or copy/paste the deprecated policy into your policy ' 'file and maintain it manually.' % { 'old_name': deprecated_rule.name, 'old_check_str': deprecated_rule.check_str, 'release': default.deprecated_since, 'name': default.name, 'check_str': default.check_str, 'reason': default.deprecated_reason }) LOG.warn(deprecated_msg) oslo_policy_version = pkg_resources.parse_version( pkg_resources.get_distribution("oslo.policy").version) # NOTE(gmann): oslo policy 3.7.0 onwards does not allow to modify # the Rule object check attribute. required_version = pkg_resources.parse_version('3.7.0') if oslo_policy_version >= required_version: return policy.OrCheck([default.check, deprecated_rule.check]) else: default.check = policy.OrCheck([ policy._parser.parse_rule(cs) for cs in [default.check_str, deprecated_rule.check_str] ]) return default.check
def test_call_second_true(self): rules = [mock.Mock(return_value=False), mock.Mock(return_value=True)] check = policy.OrCheck(rules) self.assertEqual(check('target', 'cred', None), True) rules[0].assert_called_once_with('target', 'cred', None) rules[1].assert_called_once_with('target', 'cred', None)
def _handle_deprecated_rule(self, default): deprecated_rule = default.deprecated_rule deprecated_msg = ( 'Policy "%(old_name)s":"%(old_check_str)s" was deprecated in ' '%(release)s in favor of "%(name)s":"%(check_str)s". Reason: ' '%(reason)s. Either ensure your deployment is ready for the new ' 'default or copy/paste the deprecated policy into your policy ' 'file and maintain it manually.' % { 'old_name': deprecated_rule.name, 'old_check_str': deprecated_rule.check_str, 'release': default.deprecated_since, 'name': default.name, 'check_str': default.check_str, 'reason': default.deprecated_reason }) LOG.warn(deprecated_msg) default.check = policy.OrCheck([ policy._parser.parse_rule(cs) for cs in [default.check_str, deprecated_rule.check_str] ])
def test_str(self): check = policy.OrCheck(['rule1', 'rule2']) self.assertEqual(str(check), '(rule1 or rule2)')
def test_add_check(self): check = policy.OrCheck(['rule1', 'rule2']) check.add_check('rule3') self.assertEqual(check.rules, ['rule1', 'rule2', 'rule3'])
def test_init(self): check = policy.OrCheck(['rule1', 'rule2']) self.assertEqual(check.rules, ['rule1', 'rule2'])