From eb5dc52407757d7dc16c10f836fd1520540d09e6 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 27 Jul 2016 11:48:47 -0400 Subject: [PATCH] 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 --- nova/conf/glance.py | 3 +++ nova/config.py | 8 +++++--- nova/tests/unit/test_conf.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nova/conf/glance.py b/nova/conf/glance.py index c701cebc55a9..e6586fd2d6bc 100644 --- a/nova/conf/glance.py +++ b/nova/conf/glance.py @@ -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.'), ] diff --git a/nova/config.py b/nova/config.py index 22233624db72..db64ddf8f74a 100644 --- a/nova/config.py +++ b/nova/config.py @@ -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() diff --git a/nova/tests/unit/test_conf.py b/nova/tests/unit/test_conf.py index 17f3630cea25..d6e62cf375d7 100644 --- a/nova/tests/unit/test_conf.py +++ b/nova/tests/unit/test_conf.py @@ -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)