From b752717f253f0c3eb45cc7ae5530bc8f295b4c22 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Fri, 6 Apr 2018 14:52:13 -0400 Subject: [PATCH] Log a more useful error when cinder auth isn't configured This is similar to I18f162c4f8d1964cb4d0c184ff2149c76e1e86b4, except all REST API interactions that hit the Cinder API use the request user token, so configuring auth for [cinder] was only recently added (in Queens) and is not required. However, it is needed for certain scenarios where there is no user token, like with periodic tasks to shutdown an instance and detach its volumes. As such, we need to provide a more useful error message to help an operator debug the problem if this don't have the configuration needed for some operations. Change-Id: I7adaa003a86503b711e87be671e9ef9c0e52b152 Related-Bug: #1761487 --- nova/tests/unit/volume/test_cinder.py | 6 +++++- nova/volume/cinder.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/volume/test_cinder.py b/nova/tests/unit/volume/test_cinder.py index 081025dfc083..06712e715ed2 100644 --- a/nova/tests/unit/volume/test_cinder.py +++ b/nova/tests/unit/volume/test_cinder.py @@ -1062,11 +1062,15 @@ class CinderClientTestCase(test.NoDBTestCase): get_volume_api.assert_called_once_with( self.mock_session.get_endpoint.return_value) + @mock.patch('nova.volume.cinder.LOG.error') @mock.patch.object(ks_loading, 'load_auth_from_conf_options') - def test_load_auth_plugin_failed(self, mock_load_from_conf): + def test_load_auth_plugin_failed(self, mock_load_from_conf, mock_log_err): mock_load_from_conf.return_value = None self.assertRaises(cinder_exception.Unauthorized, cinder._load_auth_plugin, CONF) + mock_log_err.assert_called() + self.assertIn('The [cinder] section of your nova configuration file', + mock_log_err.call_args[0][0]) @mock.patch('nova.volume.cinder._ADMIN_AUTH') def test_admin_context_without_token(self, diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index cd513f71914b..8f0b2a8c3596 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -70,6 +70,10 @@ def _load_auth_plugin(conf): if auth_plugin: return auth_plugin + if conf.cinder.auth_type is None: + LOG.error('The [cinder] section of your nova configuration file ' + 'must be configured for authentication with the ' + 'block-storage service endpoint.') err_msg = _('Unknown auth type: %s') % conf.cinder.auth_type raise cinder_exception.Unauthorized(401, message=err_msg)