Update get_port_binding_host for multiple bindings
With the adoption of multiple port bindings, get_port_binding_host is updated to select only the active binding Change-Id: I57ee16aa970527de2c2d787ebf0df71241f01e74 Partial-Bug: #1580880
This commit is contained in:
parent
03db94ebaa
commit
390b6a531f
|
@ -215,10 +215,11 @@ def get_port_binding_host(context, port_id):
|
||||||
try:
|
try:
|
||||||
with db_api.context_manager.reader.using(context):
|
with db_api.context_manager.reader.using(context):
|
||||||
query = (context.session.query(models.PortBinding).
|
query = (context.session.query(models.PortBinding).
|
||||||
filter(models.PortBinding.port_id.startswith(port_id)).
|
filter(models.PortBinding.port_id.startswith(port_id)))
|
||||||
one())
|
query = query.filter(
|
||||||
|
models.PortBinding.status == n_const.ACTIVE).one()
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
LOG.debug("No binding found for port %(port_id)s",
|
LOG.debug("No active binding found for port %(port_id)s",
|
||||||
{'port_id': port_id})
|
{'port_id': port_id})
|
||||||
return
|
return
|
||||||
except exc.MultipleResultsFound:
|
except exc.MultipleResultsFound:
|
||||||
|
|
|
@ -62,11 +62,13 @@ class Ml2DBTestCase(testlib_api.SqlTestCase):
|
||||||
port.create()
|
port.create()
|
||||||
return port
|
return port
|
||||||
|
|
||||||
def _setup_neutron_portbinding(self, port_id, vif_type, host):
|
def _setup_neutron_portbinding(self, port_id, vif_type, host,
|
||||||
|
status=constants.ACTIVE):
|
||||||
with db_api.context_manager.writer.using(self.ctx):
|
with db_api.context_manager.writer.using(self.ctx):
|
||||||
self.ctx.session.add(models.PortBinding(port_id=port_id,
|
self.ctx.session.add(models.PortBinding(port_id=port_id,
|
||||||
vif_type=vif_type,
|
vif_type=vif_type,
|
||||||
host=host))
|
host=host,
|
||||||
|
status=status))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _sort_segments(segments):
|
def _sort_segments(segments):
|
||||||
|
@ -217,10 +219,13 @@ class Ml2DBTestCase(testlib_api.SqlTestCase):
|
||||||
network_id = uuidutils.generate_uuid()
|
network_id = uuidutils.generate_uuid()
|
||||||
port_id = uuidutils.generate_uuid()
|
port_id = uuidutils.generate_uuid()
|
||||||
host = 'fake_host'
|
host = 'fake_host'
|
||||||
|
other_host = 'other_fake_host'
|
||||||
vif_type = portbindings.VIF_TYPE_UNBOUND
|
vif_type = portbindings.VIF_TYPE_UNBOUND
|
||||||
self._setup_neutron_network(network_id)
|
self._setup_neutron_network(network_id)
|
||||||
self._setup_neutron_port(network_id, port_id)
|
self._setup_neutron_port(network_id, port_id)
|
||||||
self._setup_neutron_portbinding(port_id, vif_type, host)
|
self._setup_neutron_portbinding(port_id, vif_type, host)
|
||||||
|
self._setup_neutron_portbinding(port_id, vif_type, other_host,
|
||||||
|
status=constants.INACTIVE)
|
||||||
|
|
||||||
port_host = ml2_db.get_port_binding_host(self.ctx, port_id)
|
port_host = ml2_db.get_port_binding_host(self.ctx, port_id)
|
||||||
self.assertEqual(host, port_host)
|
self.assertEqual(host, port_host)
|
||||||
|
|
Loading…
Reference in New Issue