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