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
This commit is contained in:
Matt Riedemann 2018-04-06 14:52:13 -04:00
parent a6d9655d78
commit b752717f25
2 changed files with 9 additions and 1 deletions

View File

@ -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,

View File

@ -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)