Fix error: Starting cue with empty config_dir causes runtime error

This patch corrects an error encountered when starting the cue app
with an empty config_dir commandline parameter.

Change-Id: I38dea66677d61819d76fb8a0c4ddfd98352ee4bb
This commit is contained in:
Michael Krotscheck 2015-12-03 13:18:12 -08:00 committed by Min Pae
parent 3bb4942e84
commit e283ffc208
2 changed files with 54 additions and 4 deletions

View File

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Hewlett-Packard Enterprise Development Company, L.P.
#
# 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 mock
from oslo_config import cfg
from cue.common import policy
from cue.tests.functional import api
class TestPolicyHarness(api.APITest):
"""Test that the API Test Policy harness is only initialized once."""
@mock.patch('cue.common.policy.init')
def setUp(self, mock_policy_init):
super(TestPolicyHarness, self).setUp()
self.mock_init = mock_policy_init
def test_assert_init_called_once(self):
"""Assert that policy is only initialized once in the test harness."""
self.assertEqual(1, self.mock_init.call_count)
class TestPolicyOsloConfig(api.APITest):
"""Test the policy harness initialization configuration states."""
def test_init_with_uninitialized_config_dir(self):
self.assertNotIn('config_dir', cfg.CONF)
try:
policy.init()
except Exception as e:
self.fail("Policy initialization failed with: " + e.message)
def test_init_with_empty_oslo_config_dir(self):
self.CONF.conf(args=[], project='cue')
try:
policy.init()
except Exception as e:
self.fail("Policy initialization failed with: " + e.message)

View File

@ -33,7 +33,6 @@ from cue.db.sqlalchemy import api as db_api
from cue.manage import database
from cue import objects
from cue.tests.functional.fixtures import database as database_fixture
from cue.tests.functional.fixtures import policy
test_opts = [
@ -65,8 +64,7 @@ class FunctionalTestCase(base.BaseTestCase):
self.flags(state_path='/tmp')
self.flags(connection="sqlite://", group="database")
self.CONF = config_fixture.Config()
self.useFixture(self.CONF)
self.CONF = self.useFixture(config_fixture.Config(cfg.CONF))
self._include_default_fixtures()
@ -128,7 +126,7 @@ class FunctionalTestCase(base.BaseTestCase):
sqlite_clean_db=CONF.sqlite_clean_db,
)
self.useFixture(DB_CACHE)
self.useFixture(policy.PolicyFixture())
# self.useFixture(policy.PolicyFixture())
def flags(self, group=None, **kw):
"""Override flag variables for a test."""