Merge "Kill contention between update and delete"
This commit is contained in:
commit
aabf6d42a0
|
@ -332,6 +332,20 @@ class Firewall_db_mixin(fw_ext.FirewallPluginBase, base_db.CommonDbMixin):
|
||||||
raise fw_ext.FirewallNotFound(firewall_id=id)
|
raise fw_ext.FirewallNotFound(firewall_id=id)
|
||||||
return self.get_firewall(context, 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):
|
def delete_firewall(self, context, id):
|
||||||
LOG.debug("delete_firewall() called")
|
LOG.debug("delete_firewall() called")
|
||||||
with context.session.begin(subtransactions=True):
|
with context.session.begin(subtransactions=True):
|
||||||
|
|
|
@ -41,24 +41,21 @@ class FirewallCallbacks(object):
|
||||||
|
|
||||||
def set_firewall_status(self, context, firewall_id, status, **kwargs):
|
def set_firewall_status(self, context, firewall_id, status, **kwargs):
|
||||||
"""Agent uses this to set a firewall's status."""
|
"""Agent uses this to set a firewall's status."""
|
||||||
LOG.debug("set_firewall_status() called")
|
LOG.debug("Setting firewall %s to status: %s" % (firewall_id, status))
|
||||||
with context.session.begin(subtransactions=True):
|
# Sanitize status first
|
||||||
fw_db = self.plugin._get_firewall(context, firewall_id)
|
if status in (const.ACTIVE, const.DOWN, const.INACTIVE):
|
||||||
# ignore changing status if firewall expects to be deleted
|
to_update = status
|
||||||
# That case means that while some pending operation has been
|
else:
|
||||||
# performed on the backend, neutron server received delete request
|
to_update = const.ERROR
|
||||||
# and changed firewall status to const.PENDING_DELETE
|
# ignore changing status if firewall expects to be deleted
|
||||||
if fw_db.status == const.PENDING_DELETE:
|
# That case means that while some pending operation has been
|
||||||
LOG.debug("Firewall %(fw_id)s in PENDING_DELETE state, "
|
# performed on the backend, neutron server received delete request
|
||||||
"not changing to %(status)s",
|
# and changed firewall status to PENDING_DELETE
|
||||||
{'fw_id': firewall_id, 'status': status})
|
updated = self.plugin.update_firewall_status(
|
||||||
return False
|
context, firewall_id, to_update, not_in=(const.PENDING_DELETE,))
|
||||||
if status in (const.ACTIVE, const.DOWN, const.INACTIVE):
|
if updated:
|
||||||
fw_db.status = status
|
LOG.debug("firewall %s status set: %s" % (firewall_id, to_update))
|
||||||
return True
|
return updated and to_update != const.ERROR
|
||||||
else:
|
|
||||||
fw_db.status = const.ERROR
|
|
||||||
return False
|
|
||||||
|
|
||||||
def firewall_deleted(self, context, firewall_id, **kwargs):
|
def firewall_deleted(self, context, firewall_id, **kwargs):
|
||||||
"""Agent uses this to indicate firewall is deleted."""
|
"""Agent uses this to indicate firewall is deleted."""
|
||||||
|
|
Loading…
Reference in New Issue