Add logging to cli if keystone.conf is not found

If keystone.conf is not found at one of ./etc/keystone.conf,
~/.keystone/keystone.conf, ~/keystone.conf,
/etc/keystone/keystone.conf, or /etc/keystone.conf, the keystone-manage
command will use defaults configured in keystone.common.config[1] (or
elsewhere, e.g. keystone.common.sql.core[2]). If it does not find a
default value for a parameter it needs to use, it will error at that
point (for example, the samp_idp_metadata command errors when
idp_entity_id is not set). However, if all of the parameters it is
using have default values, which is the case for commands like db_sync
and ssl_setup, keystone-manage will silently proceed with those
defaults. This is not obvious to the user, who may have misplaced the
keystone.conf or is lacking permissions to read keystone.conf. This
patch adds a warning that will notify the user if it can't find the
config file, but otherwise proceeds as normal.

Why not fix this in oslo.config? The behavior of silently continuing if
config files aren't found is longstanding, so changing that behavior
would probably not be backwards-compatible. Moreover, other projects
might want to handle this differently or not handle it at all.

[1] http://git.openstack.org/cgit/openstack/keystone/tree/keystone/common/config.py
[2] http://git.openstack.org/cgit/openstack/keystone/tree/keystone/common/sql/core.py#n73

Closes-bug: #1273273

Change-Id: I276c671a0da78e3d1d2aa7336e55f65be41d8cca
This commit is contained in:
Colleen Murphy 2016-03-31 10:47:02 -07:00 committed by Morgan Fainberg
parent 4e0fdfabb4
commit 32203d4951
2 changed files with 29 additions and 0 deletions

View File

@ -966,5 +966,7 @@ def main(argv=None, config_files=None):
version=pbr.version.VersionInfo('keystone').version_string(),
usage='%(prog)s [' + '|'.join([cmd.name for cmd in CMDS]) + ']',
default_config_files=config_files)
if not CONF.default_config_files:
LOG.warning(_LW('Config file not found, using default configs.'))
config.setup_logging()
CONF.command.cmd_class.main()

View File

@ -12,12 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
import uuid
import fixtures
import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslotest import mockpatch
from six.moves import range
from testtools import matchers
@ -44,6 +47,30 @@ class CliTestCase(unit.SQLDriverOverrides, unit.TestCase):
cli.TokenFlush.main()
class CliNoConfigTestCase(unit.BaseTestCase):
def setUp(self):
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.config_fixture.register_cli_opt(cli.command_opt)
super(CliNoConfigTestCase, self).setUp()
# NOTE(crinkle): the command call doesn't have to actually work,
# that's what the other unit tests are for. So just mock it out.
class FakeConfCommand(object):
def __init__(self):
self.cmd_class = mock.Mock()
self.useFixture(mockpatch.PatchObject(
CONF, 'command', FakeConfCommand()))
self.logging = self.useFixture(
fixtures.FakeLogger(level=logging.WARN))
def test_cli(self):
expected_msg = 'Config file not found, using default configs.'
cli.main(argv=['keystone-manage', 'db_sync'])
self.assertThat(self.logging.output, matchers.Contains(expected_msg))
class CliBootStrapTestCase(unit.SQLDriverOverrides, unit.TestCase):
def setUp(self):