From 87c8c933bd9b79a2cf06f9f0bc02160b21e8920d Mon Sep 17 00:00:00 2001 From: Cao ShuFeng Date: Thu, 17 Mar 2016 19:14:59 +0800 Subject: [PATCH] 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 --- glanceclient/shell.py | 6 ++++++ glanceclient/tests/unit/test_shell.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 86e6107..d8998f0 100755 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -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) diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index e0f9ff7..3a63639 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -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