Merge "Integration of L3HARouterAgentPortBinding in ml2/drivers/l2pop/db.py"
This commit is contained in:
commit
75c1cf0abb
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib import constants as const
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
from sqlalchemy import func
|
||||
@ -19,6 +20,8 @@ from sqlalchemy import func
|
||||
from neutron.agent.common import utils
|
||||
from neutron.db.models import agent as agent_model
|
||||
from neutron.db.models import l3agent as rb_model
|
||||
from neutron.db.models import l3ha as l3ha_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
from neutron.objects import utils as obj_utils
|
||||
@ -114,3 +117,30 @@ class Agent(base.NeutronDbObject):
|
||||
agents = [cls._load_object(context, record[0]) for record in query]
|
||||
|
||||
return agents
|
||||
|
||||
@classmethod
|
||||
def get_ha_agents(cls, context, network_id=None, router_id=None):
|
||||
if not (network_id or router_id):
|
||||
return []
|
||||
query = context.session.query(agent_model.Agent.host)
|
||||
query = query.join(l3ha_model.L3HARouterAgentPortBinding,
|
||||
l3ha_model.L3HARouterAgentPortBinding.l3_agent_id ==
|
||||
agent_model.Agent.id)
|
||||
if router_id:
|
||||
query = query.filter(
|
||||
l3ha_model.L3HARouterAgentPortBinding.router_id ==
|
||||
router_id).all()
|
||||
elif network_id:
|
||||
query = query.join(models_v2.Port, models_v2.Port.device_id ==
|
||||
l3ha_model.L3HARouterAgentPortBinding.router_id)
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status ==
|
||||
const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner.in_(
|
||||
(const.DEVICE_OWNER_HA_REPLICATED_INT,
|
||||
const.DEVICE_OWNER_ROUTER_SNAT))).all()
|
||||
# L3HARouterAgentPortBinding will have l3 agent ids of hosting agents.
|
||||
# But we need l2 agent(for tunneling ip) while creating FDB entries.
|
||||
hosts = [host[0] for host in query]
|
||||
agents = cls.get_objects(context, host=hosts)
|
||||
return agents
|
||||
|
@ -21,6 +21,7 @@ from sqlalchemy import orm
|
||||
from neutron.db.models import agent as agent_model
|
||||
from neutron.db.models import l3ha as l3ha_model
|
||||
from neutron.db import models_v2
|
||||
from neutron.objects import agent as agent_objs
|
||||
from neutron.plugins.ml2 import models as ml2_models
|
||||
|
||||
|
||||
@ -28,14 +29,21 @@ HA_ROUTER_PORTS = (const.DEVICE_OWNER_HA_REPLICATED_INT,
|
||||
const.DEVICE_OWNER_ROUTER_SNAT)
|
||||
|
||||
|
||||
def get_agent_ip_by_host(session, agent_host):
|
||||
agent = get_agent_by_host(session, agent_host)
|
||||
def get_agent_ip_by_host(context, agent_host):
|
||||
agent = get_agent_by_host(context, agent_host)
|
||||
if agent:
|
||||
return get_agent_ip(agent)
|
||||
|
||||
|
||||
def _get_agent_conf_dict(agent):
|
||||
configuration = agent.configurations
|
||||
if not isinstance(configuration, dict):
|
||||
configuration = jsonutils.loads(configuration)
|
||||
return configuration
|
||||
|
||||
|
||||
def get_agent_ip(agent):
|
||||
configuration = jsonutils.loads(agent.configurations)
|
||||
configuration = _get_agent_conf_dict(agent)
|
||||
return configuration.get('tunneling_ip')
|
||||
|
||||
|
||||
@ -45,40 +53,38 @@ def get_agent_uptime(agent):
|
||||
|
||||
|
||||
def get_agent_tunnel_types(agent):
|
||||
configuration = jsonutils.loads(agent.configurations)
|
||||
configuration = _get_agent_conf_dict(agent)
|
||||
return configuration.get('tunnel_types')
|
||||
|
||||
|
||||
def get_agent_l2pop_network_types(agent):
|
||||
configuration = jsonutils.loads(agent.configurations)
|
||||
configuration = _get_agent_conf_dict(agent)
|
||||
return configuration.get('l2pop_network_types')
|
||||
|
||||
|
||||
def get_agent_by_host(session, agent_host):
|
||||
def get_agent_by_host(context, agent_host):
|
||||
"""Return a L2 agent on the host."""
|
||||
|
||||
with session.begin(subtransactions=True):
|
||||
query = session.query(agent_model.Agent)
|
||||
query = query.filter(agent_model.Agent.host == agent_host)
|
||||
for agent in query:
|
||||
agents = agent_objs.Agent.get_objects(context, host=agent_host)
|
||||
for agent in agents:
|
||||
if get_agent_ip(agent):
|
||||
return agent
|
||||
|
||||
|
||||
def _get_active_network_ports(session, network_id):
|
||||
with session.begin(subtransactions=True):
|
||||
query = session.query(ml2_models.PortBinding, agent_model.Agent)
|
||||
query = query.join(agent_model.Agent,
|
||||
agent_model.Agent.host == ml2_models.PortBinding.host)
|
||||
query = query.join(models_v2.Port)
|
||||
query = query.options(orm.subqueryload(ml2_models.PortBinding.port))
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status == const.PORT_STATUS_ACTIVE)
|
||||
return query
|
||||
def _get_active_network_ports(context, network_id):
|
||||
query = context.session.query(ml2_models.PortBinding,
|
||||
agent_model.Agent)
|
||||
query = query.join(agent_model.Agent,
|
||||
agent_model.Agent.host == ml2_models.PortBinding.host)
|
||||
query = query.join(models_v2.Port)
|
||||
query = query.options(orm.subqueryload(ml2_models.PortBinding.port))
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status == const.PORT_STATUS_ACTIVE)
|
||||
return query
|
||||
|
||||
|
||||
def _ha_router_interfaces_on_network_query(session, network_id):
|
||||
query = session.query(models_v2.Port)
|
||||
def _ha_router_interfaces_on_network_query(context, network_id):
|
||||
query = context.session.query(models_v2.Port)
|
||||
query = query.join(l3ha_model.L3HARouterAgentPortBinding,
|
||||
l3ha_model.L3HARouterAgentPortBinding.router_id ==
|
||||
models_v2.Port.device_id)
|
||||
@ -87,109 +93,90 @@ def _ha_router_interfaces_on_network_query(session, network_id):
|
||||
models_v2.Port.device_owner.in_(HA_ROUTER_PORTS))
|
||||
|
||||
|
||||
def _get_ha_router_interface_ids(session, network_id):
|
||||
query = _ha_router_interfaces_on_network_query(session, network_id)
|
||||
def _get_ha_router_interface_ids(context, network_id):
|
||||
query = _ha_router_interfaces_on_network_query(context, network_id)
|
||||
return query.from_self(models_v2.Port.id).distinct()
|
||||
|
||||
|
||||
def get_nondistributed_active_network_ports(session, network_id):
|
||||
query = _get_active_network_ports(session, network_id)
|
||||
def get_nondistributed_active_network_ports(context, network_id):
|
||||
query = _get_active_network_ports(context, network_id)
|
||||
# Exclude DVR and HA router interfaces
|
||||
query = query.filter(models_v2.Port.device_owner !=
|
||||
const.DEVICE_OWNER_DVR_INTERFACE)
|
||||
ha_iface_ids_query = _get_ha_router_interface_ids(session, network_id)
|
||||
ha_iface_ids_query = _get_ha_router_interface_ids(context, network_id)
|
||||
query = query.filter(models_v2.Port.id.notin_(ha_iface_ids_query))
|
||||
return [(bind, agent) for bind, agent in query.all()
|
||||
if get_agent_ip(agent)]
|
||||
|
||||
|
||||
def get_dvr_active_network_ports(session, network_id):
|
||||
with session.begin(subtransactions=True):
|
||||
query = session.query(ml2_models.DistributedPortBinding,
|
||||
agent_model.Agent)
|
||||
query = query.join(agent_model.Agent,
|
||||
agent_model.Agent.host ==
|
||||
ml2_models.DistributedPortBinding.host)
|
||||
query = query.join(models_v2.Port)
|
||||
query = query.options(
|
||||
orm.subqueryload(ml2_models.DistributedPortBinding.port))
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status == const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner ==
|
||||
const.DEVICE_OWNER_DVR_INTERFACE)
|
||||
def get_dvr_active_network_ports(context, network_id):
|
||||
query = context.session.query(ml2_models.DistributedPortBinding,
|
||||
agent_model.Agent)
|
||||
query = query.join(agent_model.Agent,
|
||||
agent_model.Agent.host ==
|
||||
ml2_models.DistributedPortBinding.host)
|
||||
query = query.join(models_v2.Port)
|
||||
query = query.options(
|
||||
orm.subqueryload(ml2_models.DistributedPortBinding.port))
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status == const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner ==
|
||||
const.DEVICE_OWNER_DVR_INTERFACE)
|
||||
return [(bind, agent) for bind, agent in query.all()
|
||||
if get_agent_ip(agent)]
|
||||
|
||||
|
||||
def get_distributed_active_network_ports(session, network_id):
|
||||
return (get_dvr_active_network_ports(session, network_id) +
|
||||
get_ha_active_network_ports(session, network_id))
|
||||
def get_distributed_active_network_ports(context, network_id):
|
||||
return (get_dvr_active_network_ports(context, network_id) +
|
||||
get_ha_active_network_ports(context, network_id))
|
||||
|
||||
|
||||
def get_ha_active_network_ports(session, network_id):
|
||||
agents = get_ha_agents(session, network_id=network_id)
|
||||
def get_ha_active_network_ports(context, network_id):
|
||||
agents = get_ha_agents(context, network_id=network_id)
|
||||
return [(None, agent) for agent in agents]
|
||||
|
||||
|
||||
def get_ha_agents(session, network_id=None, router_id=None):
|
||||
query = session.query(agent_model.Agent.host).distinct()
|
||||
query = query.join(l3ha_model.L3HARouterAgentPortBinding,
|
||||
l3ha_model.L3HARouterAgentPortBinding.l3_agent_id ==
|
||||
agent_model.Agent.id)
|
||||
if router_id:
|
||||
query = query.filter(
|
||||
l3ha_model.L3HARouterAgentPortBinding.router_id == router_id)
|
||||
elif network_id:
|
||||
query = query.join(models_v2.Port, models_v2.Port.device_id ==
|
||||
l3ha_model.L3HARouterAgentPortBinding.router_id)
|
||||
query = query.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status == const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner.in_(HA_ROUTER_PORTS))
|
||||
else:
|
||||
return []
|
||||
# L3HARouterAgentPortBinding will have l3 agent ids of hosting agents.
|
||||
# But we need l2 agent(for tunneling ip) while creating FDB entries.
|
||||
agents_query = session.query(agent_model.Agent)
|
||||
agents_query = agents_query.filter(agent_model.Agent.host.in_(query))
|
||||
return [agent for agent in agents_query
|
||||
if get_agent_ip(agent)]
|
||||
def get_ha_agents(context, network_id=None, router_id=None):
|
||||
agents = agent_objs.Agent.get_ha_agents(context,
|
||||
network_id=network_id,
|
||||
router_id=router_id)
|
||||
return [agent for agent in agents if get_agent_ip(agent)]
|
||||
|
||||
|
||||
def get_ha_agents_by_router_id(session, router_id):
|
||||
return get_ha_agents(session, router_id=router_id)
|
||||
def get_ha_agents_by_router_id(context, router_id):
|
||||
return get_ha_agents(context, router_id=router_id)
|
||||
|
||||
|
||||
def get_agent_network_active_port_count(session, agent_host,
|
||||
def get_agent_network_active_port_count(context, agent_host,
|
||||
network_id):
|
||||
with session.begin(subtransactions=True):
|
||||
query = session.query(models_v2.Port)
|
||||
query1 = query.join(ml2_models.PortBinding)
|
||||
query1 = query1.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status ==
|
||||
const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner !=
|
||||
const.DEVICE_OWNER_DVR_INTERFACE,
|
||||
ml2_models.PortBinding.host == agent_host)
|
||||
query = context.session.query(models_v2.Port)
|
||||
query1 = query.join(ml2_models.PortBinding)
|
||||
query1 = query1.filter(models_v2.Port.network_id == network_id,
|
||||
models_v2.Port.status ==
|
||||
const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner !=
|
||||
const.DEVICE_OWNER_DVR_INTERFACE,
|
||||
ml2_models.PortBinding.host == agent_host)
|
||||
|
||||
ha_iface_ids_query = _get_ha_router_interface_ids(session, network_id)
|
||||
query1 = query1.filter(models_v2.Port.id.notin_(ha_iface_ids_query))
|
||||
ha_port_count = get_ha_router_active_port_count(
|
||||
session, agent_host, network_id)
|
||||
ha_iface_ids_query = _get_ha_router_interface_ids(context, network_id)
|
||||
query1 = query1.filter(models_v2.Port.id.notin_(ha_iface_ids_query))
|
||||
ha_port_count = get_ha_router_active_port_count(
|
||||
context, agent_host, network_id)
|
||||
|
||||
query2 = query.join(ml2_models.DistributedPortBinding)
|
||||
query2 = query2.filter(models_v2.Port.network_id == network_id,
|
||||
ml2_models.DistributedPortBinding.status ==
|
||||
const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner ==
|
||||
const.DEVICE_OWNER_DVR_INTERFACE,
|
||||
ml2_models.DistributedPortBinding.host ==
|
||||
agent_host)
|
||||
return (query1.count() + query2.count() + ha_port_count)
|
||||
query2 = query.join(ml2_models.DistributedPortBinding)
|
||||
query2 = query2.filter(models_v2.Port.network_id == network_id,
|
||||
ml2_models.DistributedPortBinding.status ==
|
||||
const.PORT_STATUS_ACTIVE,
|
||||
models_v2.Port.device_owner ==
|
||||
const.DEVICE_OWNER_DVR_INTERFACE,
|
||||
ml2_models.DistributedPortBinding.host ==
|
||||
agent_host)
|
||||
return (query1.count() + query2.count() + ha_port_count)
|
||||
|
||||
|
||||
def get_ha_router_active_port_count(session, agent_host, network_id):
|
||||
def get_ha_router_active_port_count(context, agent_host, network_id):
|
||||
# Return num of HA router interfaces on the given network and host
|
||||
query = _ha_router_interfaces_on_network_query(session, network_id)
|
||||
query = _ha_router_interfaces_on_network_query(context, network_id)
|
||||
query = query.filter(models_v2.Port.status == const.PORT_STATUS_ACTIVE)
|
||||
query = query.join(agent_model.Agent)
|
||||
query = query.filter(agent_model.Agent.host == agent_host)
|
||||
|
@ -24,7 +24,6 @@ from oslo_log import log as logging
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.conf.plugins.ml2.drivers import l2pop as config
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import l3_hamode_db
|
||||
from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db
|
||||
from neutron.plugins.ml2.drivers.l2pop import rpc as l2pop_rpc
|
||||
@ -58,11 +57,11 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
return True
|
||||
|
||||
def _get_ha_port_agents_fdb(
|
||||
self, session, network_id, router_id):
|
||||
self, context, network_id, router_id):
|
||||
other_fdb_ports = {}
|
||||
for agent in l2pop_db.get_ha_agents_by_router_id(session, router_id):
|
||||
for agent in l2pop_db.get_ha_agents_by_router_id(context, router_id):
|
||||
agent_active_ports = l2pop_db.get_agent_network_active_port_count(
|
||||
session, agent.host, network_id)
|
||||
context, agent.host, network_id)
|
||||
if agent_active_ports == 0:
|
||||
ip = l2pop_db.get_agent_ip(agent)
|
||||
other_fdb_ports[ip] = [const.FLOODING_ENTRY]
|
||||
@ -77,10 +76,9 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
plugin_context, context.bottom_bound_segment, port, agent_host)
|
||||
if fdb_entries and l3_hamode_db.is_ha_router_port(
|
||||
plugin_context, port['device_owner'], port['device_id']):
|
||||
session = db_api.get_reader_session()
|
||||
network_id = port['network_id']
|
||||
other_fdb_ports = self._get_ha_port_agents_fdb(
|
||||
session, network_id, port['device_id'])
|
||||
plugin_context, network_id, port['device_id'])
|
||||
fdb_entries[network_id]['ports'] = other_fdb_ports
|
||||
|
||||
self.L2populationAgentNotify.remove_fdb_entries(self.rpc_ctx,
|
||||
@ -114,7 +112,7 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
if not agent_host:
|
||||
return
|
||||
|
||||
agent_ip = l2pop_db.get_agent_ip_by_host(db_api.get_reader_session(),
|
||||
agent_ip = l2pop_db.get_agent_ip_by_host(context._plugin_context,
|
||||
agent_host)
|
||||
|
||||
orig_mac_ip = [l2pop_rpc.PortInfo(mac_address=port['mac_address'],
|
||||
@ -202,15 +200,15 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
|
||||
return True
|
||||
|
||||
def _create_agent_fdb(self, session, agent, segment, network_id):
|
||||
def _create_agent_fdb(self, context, agent, segment, network_id):
|
||||
agent_fdb_entries = {network_id:
|
||||
{'segment_id': segment['segmentation_id'],
|
||||
'network_type': segment['network_type'],
|
||||
'ports': {}}}
|
||||
tunnel_network_ports = (
|
||||
l2pop_db.get_distributed_active_network_ports(session, network_id))
|
||||
l2pop_db.get_distributed_active_network_ports(context, network_id))
|
||||
fdb_network_ports = (
|
||||
l2pop_db.get_nondistributed_active_network_ports(session,
|
||||
l2pop_db.get_nondistributed_active_network_ports(context,
|
||||
network_id))
|
||||
ports = agent_fdb_entries[network_id]['ports']
|
||||
ports.update(self._get_tunnels(
|
||||
@ -260,9 +258,8 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
def update_port_up(self, context):
|
||||
port = context.current
|
||||
agent_host = context.host
|
||||
session = db_api.get_reader_session()
|
||||
port_context = context._plugin_context
|
||||
agent = l2pop_db.get_agent_by_host(session, agent_host)
|
||||
agent = l2pop_db.get_agent_by_host(port_context, agent_host)
|
||||
if not agent:
|
||||
LOG.warning("Unable to retrieve active L2 agent on host %s",
|
||||
agent_host)
|
||||
@ -271,7 +268,7 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
network_id = port['network_id']
|
||||
|
||||
agent_active_ports = l2pop_db.get_agent_network_active_port_count(
|
||||
session, agent_host, network_id)
|
||||
port_context, agent_host, network_id)
|
||||
|
||||
agent_ip = l2pop_db.get_agent_ip(agent)
|
||||
segment = context.bottom_bound_segment
|
||||
@ -285,7 +282,7 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
cfg.CONF.l2pop.agent_boot_time):
|
||||
# First port activated on current agent in this network,
|
||||
# we have to provide it with the whole list of fdb entries
|
||||
agent_fdb_entries = self._create_agent_fdb(session,
|
||||
agent_fdb_entries = self._create_agent_fdb(port_context,
|
||||
agent,
|
||||
segment,
|
||||
network_id)
|
||||
@ -312,11 +309,10 @@ class L2populationMechanismDriver(api.MechanismDriver):
|
||||
|
||||
network_id = port['network_id']
|
||||
|
||||
session = db_api.get_reader_session()
|
||||
agent_active_ports = l2pop_db.get_agent_network_active_port_count(
|
||||
session, agent_host, network_id)
|
||||
context, agent_host, network_id)
|
||||
|
||||
agent = l2pop_db.get_agent_by_host(session,
|
||||
agent = l2pop_db.get_agent_by_host(context,
|
||||
agent_host)
|
||||
if not agent:
|
||||
LOG.warning("Unable to retrieve active L2 agent on host %s",
|
||||
|
@ -89,14 +89,14 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
helpers.register_dhcp_agent()
|
||||
helpers.register_ovs_agent()
|
||||
agent = l2pop_db.get_agent_by_host(
|
||||
self.ctx.session, helpers.HOST)
|
||||
self.ctx, helpers.HOST)
|
||||
self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
|
||||
|
||||
def test_get_agent_by_host_no_candidate(self):
|
||||
helpers.register_l3_agent()
|
||||
helpers.register_dhcp_agent()
|
||||
agent = l2pop_db.get_agent_by_host(
|
||||
self.ctx.session, helpers.HOST)
|
||||
self.ctx, helpers.HOST)
|
||||
self.assertIsNone(agent)
|
||||
|
||||
def _setup_port_binding(self, **kwargs):
|
||||
@ -141,7 +141,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
helpers.register_dhcp_agent()
|
||||
helpers.register_ovs_agent()
|
||||
tunnel_network_ports = l2pop_db.get_distributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, len(tunnel_network_ports))
|
||||
_, agent = tunnel_network_ports[0]
|
||||
self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
|
||||
@ -153,7 +153,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
helpers.register_l3_agent()
|
||||
helpers.register_dhcp_agent()
|
||||
tunnel_network_ports = l2pop_db.get_distributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(0, len(tunnel_network_ports))
|
||||
|
||||
def test_get_nondistributed_active_network_ports(self):
|
||||
@ -163,7 +163,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
helpers.register_dhcp_agent()
|
||||
helpers.register_ovs_agent()
|
||||
fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, len(fdb_network_ports))
|
||||
_, agent = fdb_network_ports[0]
|
||||
self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
|
||||
@ -174,7 +174,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
helpers.register_l3_agent()
|
||||
helpers.register_dhcp_agent()
|
||||
fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(0, len(fdb_network_ports))
|
||||
|
||||
def test__get_ha_router_interface_ids_with_ha_dvr_snat_port(self):
|
||||
@ -186,7 +186,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
ha_iface_ids = l2pop_db._get_ha_router_interface_ids(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, len(list(ha_iface_ids)))
|
||||
|
||||
def test__get_ha_router_interface_ids_with_ha_replicated_port(self):
|
||||
@ -198,7 +198,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_HA_REPLICATED_INT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
ha_iface_ids = l2pop_db._get_ha_router_interface_ids(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, len(list(ha_iface_ids)))
|
||||
|
||||
def test__get_ha_router_interface_ids_with_no_ha_port(self):
|
||||
@ -207,7 +207,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
ha_iface_ids = l2pop_db._get_ha_router_interface_ids(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(0, len(list(ha_iface_ids)))
|
||||
|
||||
def test_active_network_ports_with_dvr_snat_port(self):
|
||||
@ -223,7 +223,7 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_id=TEST_ROUTER_ID)
|
||||
helpers.register_dhcp_agent()
|
||||
fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, len(fdb_network_ports))
|
||||
|
||||
def test_active_network_ports_with_ha_dvr_snat_port(self):
|
||||
@ -238,10 +238,10 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
fdb_network_ports = l2pop_db.get_nondistributed_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(0, len(fdb_network_ports))
|
||||
ha_ports = l2pop_db.get_ha_active_network_ports(
|
||||
self.ctx.session, TEST_NETWORK_ID)
|
||||
self.ctx, TEST_NETWORK_ID)
|
||||
self.assertEqual(2, len(ha_ports))
|
||||
|
||||
def test_active_port_count_with_dvr_snat_port(self):
|
||||
@ -254,10 +254,10 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_id=TEST_ROUTER_ID)
|
||||
helpers.register_dhcp_agent()
|
||||
port_count = l2pop_db.get_agent_network_active_port_count(
|
||||
self.ctx.session, HOST, TEST_NETWORK_ID)
|
||||
self.ctx, HOST, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, port_count)
|
||||
port_count = l2pop_db.get_agent_network_active_port_count(
|
||||
self.ctx.session, HOST_2, TEST_NETWORK_ID)
|
||||
self.ctx, HOST_2, TEST_NETWORK_ID)
|
||||
self.assertEqual(0, port_count)
|
||||
|
||||
def test_active_port_count_with_ha_dvr_snat_port(self):
|
||||
@ -269,10 +269,10 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
port_count = l2pop_db.get_agent_network_active_port_count(
|
||||
self.ctx.session, HOST, TEST_NETWORK_ID)
|
||||
self.ctx, HOST, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, port_count)
|
||||
port_count = l2pop_db.get_agent_network_active_port_count(
|
||||
self.ctx.session, HOST_2, TEST_NETWORK_ID)
|
||||
self.ctx, HOST_2, TEST_NETWORK_ID)
|
||||
self.assertEqual(1, port_count)
|
||||
|
||||
def test_get_ha_agents_by_router_id(self):
|
||||
@ -284,6 +284,6 @@ class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
|
||||
device_owner=constants.DEVICE_OWNER_ROUTER_SNAT,
|
||||
device_id=TEST_ROUTER_ID)
|
||||
agents = l2pop_db.get_ha_agents_by_router_id(
|
||||
self.ctx.session, TEST_ROUTER_ID)
|
||||
self.ctx, TEST_ROUTER_ID)
|
||||
ha_agents = [agent.host for agent in agents]
|
||||
self.assertEqual(tools.UnorderedList([HOST, HOST_2]), ha_agents)
|
||||
|
@ -1262,11 +1262,10 @@ class TestL2PopulationMechDriver(base.BaseTestCase):
|
||||
mock.patch.object(l2pop_db,
|
||||
'get_distributed_active_network_ports',
|
||||
return_value=tunnel_network_ports):
|
||||
session = mock.Mock()
|
||||
agent = mock.Mock()
|
||||
agent.host = HOST
|
||||
segment = {'segmentation_id': 1, 'network_type': 'vxlan'}
|
||||
return mech_driver._create_agent_fdb(session,
|
||||
return mech_driver._create_agent_fdb(context,
|
||||
agent,
|
||||
segment,
|
||||
'network_id')
|
||||
|
Loading…
Reference in New Issue
Block a user