Log reason for remove_host action failing

If removing a host from an aggregate fails, the API route handler
just returns a new error message without the original failure being
logged. This logs the error before returning the error response with
the generic message.

Alternative to this we could just put the exception message in the
response text but I figured people might bristle at changing the
(mostly unhelpful) error message so I went the non-controversial route.

Change-Id: I8b41f8313f74aa3766c13c1265f6ee1f0fc03f67
This commit is contained in:
Matt Riedemann 2019-11-04 09:40:13 -05:00
parent 61a528311d
commit 0982a3fa62
2 changed files with 19 additions and 3 deletions

View File

@ -17,6 +17,8 @@
import datetime
from oslo_log import log as logging
import six
from webob import exc
from nova.api.openstack import api_version_request
@ -31,6 +33,8 @@ from nova import exception
from nova.i18n import _
from nova.policies import aggregates as aggr_policies
LOG = logging.getLogger(__name__)
def _get_context(req):
return req.environ['nova.context']
@ -173,13 +177,19 @@ class AggregateController(wsgi.Controller):
context.can(aggr_policies.POLICY_ROOT % 'remove_host')
try:
aggregate = self.api.remove_host_from_aggregate(context, id, host)
except (exception.AggregateNotFound, exception.AggregateHostNotFound,
exception.HostMappingNotFound, exception.ComputeHostNotFound):
except (exception.AggregateNotFound,
exception.AggregateHostNotFound,
exception.HostMappingNotFound,
exception.ComputeHostNotFound) as e:
LOG.error('Failed to remove host %s from aggregate %s. Error: %s',
host, id, six.text_type(e))
msg = _('Cannot remove host %(host)s in aggregate %(id)s') % {
'host': host, 'id': id}
raise exc.HTTPNotFound(explanation=msg)
except (exception.InvalidAggregateAction,
exception.ResourceProviderUpdateConflict):
exception.ResourceProviderUpdateConflict) as e:
LOG.error('Failed to remove host %s from aggregate %s. Error: %s',
host, id, six.text_type(e))
msg = _('Cannot remove host %(host)s in aggregate %(id)s') % {
'host': host, 'id': id}
raise exc.HTTPConflict(explanation=msg)

View File

@ -563,6 +563,9 @@ class AggregateTestCaseV21(test.NoDBTestCase):
self.assertRaises(exc.HTTPNotFound, eval(self.remove_host),
self.req, "1", body={"remove_host": {"host": "bogushost"}})
mock_rem.assert_called_once_with(self.context, "1", "bogushost")
self.assertIn('Failed to remove host bogushost from aggregate 1. '
'Error: Compute host bogushost could not be found.',
self.stdlog.logger.output)
def test_remove_host_with_missing_host(self):
self.assertRaises(self.bad_request, eval(self.remove_host),
@ -599,6 +602,9 @@ class AggregateTestCaseV21(test.NoDBTestCase):
self.req, "1",
body={"remove_host": {"host": "bogushost"}})
mock_rem.assert_called_once_with(self.context, "1", "bogushost")
self.assertIn('Failed to remove host bogushost from aggregate 1. '
'Error: A conflict was encountered attempting to update '
'resource provider', self.stdlog.logger.output)
def test_set_metadata(self):
body = {"set_metadata": {"metadata": {"foo": "bar"}}}