Merge "Transaction fixes for HA IPs"

This commit is contained in:
Zuul 2019-02-04 17:12:07 +00:00 committed by Gerrit Code Review
commit 96cf38da52
1 changed files with 7 additions and 7 deletions

View File

@ -63,10 +63,10 @@ class PortForHAIPAddress(object):
return query(session).params(
port_id=port_id, ipaddress=ipaddress).first()
def get_port_for_ha_ipaddress(self, ipaddress, network_id):
def get_port_for_ha_ipaddress(self, ipaddress, network_id,
session=None):
"""Returns the Neutron Port ID for the HA IP Addresss."""
session = db_api.get_reader_session()
session = session or db_api.get_reader_session()
query = BAKERY(lambda s: s.query(
HAIPAddressToPortAssocation))
query += lambda q: q.join(
@ -79,7 +79,6 @@ class PortForHAIPAddress(object):
models_v2.Port.network_id == sa.bindparam('network_id'))
port_ha_ip = query(session).params(
ipaddress=ipaddress, network_id=network_id).first()
return port_ha_ip
def get_ha_ipaddresses_for_port(self, port_id):
@ -155,6 +154,7 @@ class HAIPOwnerDbMixin(object):
return ports_to_update
LOG.debug("Got IP owner update: %s", ip_owner_info)
core_plugin = self._get_plugin()
# REVISIT: just use SQLAlchemy session and models_v2.Port?
port = core_plugin.get_port(nctx.get_admin_context(), port_id)
if not port:
LOG.debug("Ignoring update for non-existent port: %s", port_id)
@ -164,16 +164,16 @@ class HAIPOwnerDbMixin(object):
if not ipa:
continue
try:
old_owner = self.ha_ip_handler.get_port_for_ha_ipaddress(
ipa, network_id or port['network_id'])
session = db_api.get_writer_session()
with session.begin(subtransactions=True):
old_owner = self.ha_ip_handler.get_port_for_ha_ipaddress(
ipa, network_id or port['network_id'], session=session)
self.ha_ip_handler.set_port_id_for_ha_ipaddress(port_id,
ipa,
session)
if old_owner and old_owner['port_id'] != port_id:
self.ha_ip_handler.delete_port_id_for_ha_ipaddress(
old_owner['port_id'], ipa, session)
old_owner['port_id'], ipa, session=session)
ports_to_update.add(old_owner['port_id'])
except db_exc.DBReferenceError as dbe:
LOG.debug("Ignoring FK error for port %s: %s", port_id, dbe)