Add the ability to configure glanceclient debug logging

It's currently not possible to configure debug logging
for glanceclient, it's hard-coded to warning level. It
would be great to be able to just change config and
restart nova-compute, for example, when needing to debug
issues with glance.

Change-Id: I964e40085b68561af48b476c82288fc84d02bcc4
This commit is contained in:
Matt Riedemann 2016-07-27 11:48:47 -04:00
parent 1d8836828b
commit eb5dc52407
3 changed files with 25 additions and 3 deletions

View File

@ -76,6 +76,9 @@ Glance v2 will be a hard requirement in Ocata.
default=False,
help='Require Nova to perform signature verification on '
'each image downloaded from Glance.'),
cfg.BoolOpt('debug',
default=False,
help='Enable or disable debug logging with glanceclient.'),
]

View File

@ -26,16 +26,18 @@ from nova import version
CONF = nova.conf.CONF
_EXTRA_DEFAULT_LOG_LEVELS = ['glanceclient=WARN']
def parse_args(argv, default_config_files=None, configure_db=True,
init_rpc=True):
log.register_options(CONF)
# We use the oslo.log default log levels which includes suds=INFO
# and add only the extra levels that Nova needs
if CONF.glance.debug:
extra_default_log_levels = ['glanceclient=DEBUG']
else:
extra_default_log_levels = ['glanceclient=WARN']
log.set_defaults(default_log_levels=log.get_default_log_levels() +
_EXTRA_DEFAULT_LOG_LEVELS)
extra_default_log_levels)
rpc.set_defaults(control_exchange='nova')
config.set_middleware_defaults()

View File

@ -16,9 +16,11 @@ import os
import tempfile
import fixtures
import mock
from oslo_config import cfg
import nova.conf.virt
from nova import config
from nova import test
@ -80,3 +82,18 @@ class ConfTest(test.NoDBTestCase):
# a dict.
actual = [{'node': '0', 'size': '2048', 'count': '64'}]
self.assertEqual(actual, self.conf.reserved_huge_pages)
class TestParseArgs(test.NoDBTestCase):
@mock.patch.object(config.log, 'register_options')
def test_parse_args_glance_debug_false(self, register_options):
self.flags(debug=False, group='glance')
config.parse_args([], configure_db=False, init_rpc=False)
self.assertIn('glanceclient=WARN', config.CONF.default_log_levels)
@mock.patch.object(config.log, 'register_options')
def test_parse_args_glance_debug_true(self, register_options):
self.flags(debug=True, group='glance')
config.parse_args([], configure_db=False, init_rpc=False)
self.assertIn('glanceclient=DEBUG', config.CONF.default_log_levels)