use graduated oslo.policy

- Add oslo.policy to requirements.txt
- Remove in-tree copy of oslo.policy

Change-Id: Ia6fef939cfe0df33476ccee365934a5d2878f90d
Partial-Bug: #1458945
This commit is contained in:
Jeffrey Zhang 2015-07-02 23:58:10 +08:00
parent 15389435aa
commit d12a073815
3 changed files with 6 additions and 7 deletions

View File

@ -16,10 +16,10 @@ import os
import fixtures import fixtures
from oslo_config import cfg from oslo_config import cfg
from oslo_policy import policy as oslo_policy
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import six import six
from nova.openstack.common import policy as common_policy
from nova import paths from nova import paths
import nova.policy import nova.policy
from nova.tests.unit import fake_policy from nova.tests.unit import fake_policy
@ -48,15 +48,14 @@ class RealPolicyFixture(fixtures.Fixture):
# policy_file can be overridden by subclasses # policy_file can be overridden by subclasses
self.policy_file = paths.state_path_def('etc/nova/policy.json') self.policy_file = paths.state_path_def('etc/nova/policy.json')
self._prepare_policy() self._prepare_policy()
CONF.set_override('policy_file', self.policy_file) CONF.set_override('policy_file', self.policy_file, group='oslo_policy')
nova.policy.reset() nova.policy.reset()
nova.policy.init() nova.policy.init()
self.addCleanup(nova.policy.reset) self.addCleanup(nova.policy.reset)
def set_rules(self, rules): def set_rules(self, rules):
policy = nova.policy._ENFORCER policy = nova.policy._ENFORCER
policy.set_rules({k: common_policy.parse_rule(v) policy.set_rules(oslo_policy.Rules.from_dict(rules))
for k, v in rules.items()})
class PolicyFixture(RealPolicyFixture): class PolicyFixture(RealPolicyFixture):
@ -80,7 +79,7 @@ class PolicyFixture(RealPolicyFixture):
'policy.json') 'policy.json')
with open(self.policy_file, 'w') as f: with open(self.policy_file, 'w') as f:
f.write(fake_policy.policy_data) f.write(fake_policy.policy_data)
CONF.set_override('policy_dirs', []) CONF.set_override('policy_dirs', [], group='oslo_policy')
class RoleBasedPolicyFixture(RealPolicyFixture): class RoleBasedPolicyFixture(RealPolicyFixture):
@ -101,7 +100,7 @@ class RoleBasedPolicyFixture(RealPolicyFixture):
self.role = role self.role = role
def _prepare_policy(self): def _prepare_policy(self):
policy = jsonutils.load(open(CONF.policy_file)) policy = jsonutils.load(open(CONF.oslo_policy.policy_file))
# Convert all actions to require specified role # Convert all actions to require specified role
for action, rule in six.iteritems(policy): for action, rule in six.iteritems(policy):

View File

@ -44,6 +44,7 @@ oslo.utils>=2.8.0 # Apache-2.0
oslo.db>=3.2.0 # Apache-2.0 oslo.db>=3.2.0 # Apache-2.0
oslo.rootwrap>=2.0.0 # Apache-2.0 oslo.rootwrap>=2.0.0 # Apache-2.0
oslo.messaging!=2.8.0,>2.6.1 # Apache-2.0 oslo.messaging!=2.8.0,>2.6.1 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0 oslo.i18n>=1.5.0 # Apache-2.0
oslo.service>=0.12.0 # Apache-2.0 oslo.service>=0.12.0 # Apache-2.0
rfc3986>=0.2.0 # Apache-2.0 rfc3986>=0.2.0 # Apache-2.0

View File

@ -36,7 +36,6 @@ oslo.config.opts =
nova.scheduler = nova.scheduler.opts:list_opts nova.scheduler = nova.scheduler.opts:list_opts
nova.virt = nova.virt.opts:list_opts nova.virt = nova.virt.opts:list_opts
nova.openstack.common.memorycache = nova.openstack.common.memorycache:list_opts nova.openstack.common.memorycache = nova.openstack.common.memorycache:list_opts
nova.openstack.common.policy = nova.openstack.common.policy:list_opts
nova.compute.monitors.cpu = nova.compute.monitors.cpu =
virt_driver = nova.compute.monitors.cpu.virt_driver:Monitor virt_driver = nova.compute.monitors.cpu.virt_driver:Monitor