add PolicyFixture for functional test.

At present, policy_data is empty.
And policy_data will be written in a policy.json file in /tmp path.
such as:
    /tmp/tmppgM04u/tmpgVJy4J/policy.json

So we want to pass the authorization for api test, we need to add the policy
item in this policy_data.

Such as:
 policy_data = """
 {
   'nimble:instance:get': '@'
 }
 """

Change-Id: I1a645312ea8ba98310945121c0205280ac740c09
This commit is contained in:
Shaohe Feng 2016-11-15 06:07:23 +08:00
parent d48aa2ad17
commit f9e3c1fb01
2 changed files with 45 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import testscenarios
from nimble.common import config as nimble_config
from nimble.common import context as nimble_context
from nimble.tests import policy_fixture
CONF = cfg.CONF
@ -57,6 +58,7 @@ class TestCase(base.BaseTestCase):
pecan.set_config({}, overwrite=True)
self.addCleanup(reset_pecan)
self.policy = self.useFixture(policy_fixture.PolicyFixture())
def _set_config(self):
self.cfg_fixture = self.useFixture(config_fixture.Config(cfg.CONF))

View File

@ -0,0 +1,43 @@
# Copyright 2016 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import fixtures
from oslo_config import cfg
from oslo_policy import opts as policy_opts
from nimble.common import policy as nimble_policy
CONF = cfg.CONF
policy_data = """
{
}
"""
class PolicyFixture(fixtures.Fixture):
def setUp(self):
super(PolicyFixture, self).setUp()
self.policy_dir = self.useFixture(fixtures.TempDir())
self.policy_file_name = os.path.join(self.policy_dir.path,
'policy.json')
with open(self.policy_file_name, 'w') as policy_file:
policy_file.write(policy_data)
policy_opts.set_defaults(CONF)
CONF.set_override('policy_file', self.policy_file_name, 'oslo_policy')
nimble_policy._ENFORCER = None
self.addCleanup(nimble_policy.get_enforcer().clear)