Merge "Kill contention between update and delete"

This commit is contained in:
Jenkins 2015-08-29 19:45:11 +00:00 committed by Gerrit Code Review
commit aabf6d42a0
2 changed files with 29 additions and 18 deletions

View File

@ -332,6 +332,20 @@ class Firewall_db_mixin(fw_ext.FirewallPluginBase, base_db.CommonDbMixin):
raise fw_ext.FirewallNotFound(firewall_id=id)
return self.get_firewall(context, id)
def update_firewall_status(self, context, id, status, not_in=None):
"""Conditionally update firewall status.
Status transition is performed only if firewall is not in the specified
states as defined by 'not_in' list.
"""
# filter in_ wants iterable objects, None isn't.
not_in = not_in or []
with context.session.begin(subtransactions=True):
return (context.session.query(Firewall).
filter(Firewall.id == id).
filter(~Firewall.status.in_(not_in)).
update({'status': status}, synchronize_session=False))
def delete_firewall(self, context, id):
LOG.debug("delete_firewall() called")
with context.session.begin(subtransactions=True):

View File

@ -41,24 +41,21 @@ class FirewallCallbacks(object):
def set_firewall_status(self, context, firewall_id, status, **kwargs):
"""Agent uses this to set a firewall's status."""
LOG.debug("set_firewall_status() called")
with context.session.begin(subtransactions=True):
fw_db = self.plugin._get_firewall(context, firewall_id)
# ignore changing status if firewall expects to be deleted
# That case means that while some pending operation has been
# performed on the backend, neutron server received delete request
# and changed firewall status to const.PENDING_DELETE
if fw_db.status == const.PENDING_DELETE:
LOG.debug("Firewall %(fw_id)s in PENDING_DELETE state, "
"not changing to %(status)s",
{'fw_id': firewall_id, 'status': status})
return False
if status in (const.ACTIVE, const.DOWN, const.INACTIVE):
fw_db.status = status
return True
else:
fw_db.status = const.ERROR
return False
LOG.debug("Setting firewall %s to status: %s" % (firewall_id, status))
# Sanitize status first
if status in (const.ACTIVE, const.DOWN, const.INACTIVE):
to_update = status
else:
to_update = const.ERROR
# ignore changing status if firewall expects to be deleted
# That case means that while some pending operation has been
# performed on the backend, neutron server received delete request
# and changed firewall status to PENDING_DELETE
updated = self.plugin.update_firewall_status(
context, firewall_id, to_update, not_in=(const.PENDING_DELETE,))
if updated:
LOG.debug("firewall %s status set: %s" % (firewall_id, to_update))
return updated and to_update != const.ERROR
def firewall_deleted(self, context, firewall_id, **kwargs):
"""Agent uses this to indicate firewall is deleted."""