Fix missing of debug info after we use session

After the introduce of this patch set[1], cli user can't get debug
info even --debug is passed. With the patch set[1], the request
action will be performed in keystoneclient.session.Session.
However the default log level of keystoneclient module is WARNING,
so user can't get debug info from keystoneclient.session.Session.

This change set the root log level to DEBUG when --debug is
passed.

[1]: https://review.openstack.org/#/c/262220/

Change-Id: I0db0fd7ab07a0d61082b86829a671d8dbc0f2963
Closes-bug: 1551076
This commit is contained in:
Cao ShuFeng
2016-03-17 19:14:59 +08:00
parent 04e1ea73a5
commit 87c8c933bd
2 changed files with 21 additions and 0 deletions

View File

@@ -581,6 +581,12 @@ class OpenStackImagesShell(object):
if not args.os_password and options.os_password:
args.os_password = options.os_password
if args.debug:
# Set up the root logger to debug so that the submodules can
# print debug messages
logging.basicConfig(level=logging.DEBUG)
# for iso8601 < 0.1.11
logging.getLogger('iso8601').setLevel(logging.WARNING)
LOG = logging.getLogger('glanceclient')
LOG.addHandler(logging.StreamHandler())
LOG.setLevel(logging.DEBUG if args.debug else logging.INFO)

View File

@@ -20,6 +20,7 @@ try:
except ImportError:
from ordereddict import OrderedDict
import hashlib
import logging
import os
import sys
import uuid
@@ -541,6 +542,20 @@ class ShellTest(testutils.TestCase):
self.assertIn('Command-line interface to the OpenStack Images API',
sys.stdout.getvalue())
@mock.patch('glanceclient.v2.client.Client')
@mock.patch('glanceclient.v1.shell.do_image_list')
@mock.patch('glanceclient.shell.logging.basicConfig')
def test_setup_debug(self, conf, func, v2_client):
cli2 = mock.MagicMock()
v2_client.return_value = cli2
cli2.http_client.get.return_value = (None, {'versions': []})
args = '--debug image-list'
glance_shell = openstack_shell.OpenStackImagesShell()
glance_shell.main(args.split())
glance_logger = logging.getLogger('glanceclient')
self.assertEqual(glance_logger.getEffectiveLevel(), logging.DEBUG)
conf.assert_called_with(level=logging.DEBUG)
class ShellTestWithKeystoneV3Auth(ShellTest):
# auth environment to use