From 2468b3d43331effeba89d1560244d7e2a547977f Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 7 Jan 2016 17:27:52 -0800 Subject: [PATCH] Move notifications before DB retry decorator This patch moves the start notifications emitted in the API layer ('network.create.start', etc) to before the DB retry decorator. This prevents benign retry events from resending notifications onto the message bus. Change-Id: I8159692a107ede397a4abeff71310a99fffa4862 Closes-Bug: #1532051 (cherry picked from commit 447f4b14614988f38a26d5d1b8e439ad0a44d8ad) --- neutron/api/v2/base.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index 4b978c4f181..21486fff81d 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -401,13 +401,16 @@ class Controller(object): # We need a way for ensuring that if it has been created, # it is then deleted - @db_api.retry_db_errors def create(self, request, body=None, **kwargs): - """Creates a new instance of the requested entity.""" - parent_id = kwargs.get(self._parent_id_name) self._notifier.info(request.context, self._resource + '.create.start', body) + return self._create(request, body, **kwargs) + + @db_api.retry_db_errors + def _create(self, request, body, **kwargs): + """Creates a new instance of the requested entity.""" + parent_id = kwargs.get(self._parent_id_name) body = Controller.prepare_request_body(request.context, copy.deepcopy(body), True, self._resource, self._attr_info, @@ -519,12 +522,15 @@ class Controller(object): return notify({self._resource: self._view(request.context, obj)}) - @db_api.retry_db_errors def delete(self, request, id, **kwargs): """Deletes the specified entity.""" self._notifier.info(request.context, self._resource + '.delete.start', {self._resource + '_id': id}) + return self._delete(request, id, **kwargs) + + @db_api.retry_db_errors + def _delete(self, request, id, **kwargs): action = self._plugin_handlers[self.DELETE] # Check authz @@ -557,10 +563,8 @@ class Controller(object): result, notifier_method) - @db_api.retry_db_errors def update(self, request, id, body=None, **kwargs): """Updates the specified entity's attributes.""" - parent_id = kwargs.get(self._parent_id_name) try: payload = body.copy() except AttributeError: @@ -570,6 +574,10 @@ class Controller(object): self._notifier.info(request.context, self._resource + '.update.start', payload) + return self._update(request, id, body, **kwargs) + + @db_api.retry_db_errors + def _update(self, request, id, body, **kwargs): body = Controller.prepare_request_body(request.context, body, False, self._resource, self._attr_info, allow_bulk=self._allow_bulk) @@ -583,6 +591,7 @@ class Controller(object): 'default' not in value)] # Ensure policy engine is initialized policy.init() + parent_id = kwargs.get(self._parent_id_name) orig_obj = self._item(request, id, field_list=field_list, parent_id=parent_id) orig_object_copy = copy.copy(orig_obj)