Log a more useful error when neutron isn't configured

When the [neutron] section of nova.conf isn't configured for
auth with the networking service, end users of the compute
REST API get a 500 error and the logs contain this mostly
unhelpful error message:

  Unauthorized: Unknown auth type: None

This change adds a more useful error log message indicating
the root problem and provides a link to the networking service
install guide for how to resolve it.

Change-Id: I18f162c4f8d1964cb4d0c184ff2149c76e1e86b4
Partial-Bug: #1761487
This commit is contained in:
Matt Riedemann 2018-04-05 11:25:49 -04:00
parent c5fd4c7612
commit 587eb4303b
2 changed files with 15 additions and 1 deletions

View File

@ -72,6 +72,16 @@ def _load_auth_plugin(conf):
if auth_plugin:
return auth_plugin
if conf.neutron.auth_type is None:
# If we're coming in through a REST API call for something like
# creating a server, the end user is going to get a 500 response
# which is accurate since the system is mis-configured, but we should
# leave a breadcrumb for the operator that is checking the logs.
LOG.error('The [neutron] section of your nova configuration file '
'must be configured for authentication with the networking '
'service endpoint. See the networking service install guide '
'for details: '
'https://docs.openstack.org/neutron/latest/install/')
err_msg = _('Unknown auth type: %s') % conf.neutron.auth_type
raise neutron_client_exc.Unauthorized(message=err_msg)

View File

@ -263,12 +263,16 @@ class TestNeutronClient(test.NoDBTestCase):
client1.list_networks(retrieve_all=False)
self.assertEqual('new_token2', client1.httpclient.auth.get_token(None))
@mock.patch('nova.network.neutronv2.api.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
from neutronclient.common import exceptions as neutron_client_exc
self.assertRaises(neutron_client_exc.Unauthorized,
neutronapi._load_auth_plugin, CONF)
mock_log_err.assert_called()
self.assertIn('The [neutron] section of your nova configuration file',
mock_log_err.call_args[0][0])
@mock.patch.object(client.Client, "list_networks",
side_effect=exceptions.Unauthorized())