diff --git a/cinderclient/shell.py b/cinderclient/shell.py index 575370330..3938bacca 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -469,8 +469,8 @@ class OpenStackCinderShell(object): if hasattr(requests, 'logging'): requests.logging.getLogger(requests.__name__).addHandler(ch) - ks_logger = logging.getLogger("keystoneauth") - ks_logger.setLevel(logging.DEBUG) + self.ks_logger = logging.getLogger("keystoneauth") + self.ks_logger.setLevel(logging.DEBUG) def _delimit_metadata_args(self, argv): """This function adds -- separator at the appropriate spot diff --git a/cinderclient/tests/unit/test_shell.py b/cinderclient/tests/unit/test_shell.py index 3f0a272e2..c49d9df93 100644 --- a/cinderclient/tests/unit/test_shell.py +++ b/cinderclient/tests/unit/test_shell.py @@ -228,6 +228,17 @@ class ShellTest(utils.TestCase): self.assertEqual(False, _shell.cs.client.verify_cert) + @mock.patch.object(cinderclient.client.SessionClient, 'authenticate', + side_effect=exceptions.Unauthorized('No')) + def test_session_client_debug_logger(self, mock_session): + _shell = shell.OpenStackCinderShell() + # This "fails" but instantiates the client. + self.assertRaises(exceptions.CommandError, _shell.main, + ['--debug', 'list']) + # In case of SessionClient when --debug switch is specified + # 'keystoneauth' logger should be initialized. + self.assertEqual('keystoneauth', _shell.cs.client.logger.name) + @mock.patch('keystoneauth1.session.Session.__init__', side_effect=RuntimeError()) def test_http_client_with_cert(self, mock_session):