Merge "Fix l2pop regression" into stable/liberty

This commit is contained in:
Jenkins 2015-10-23 00:57:47 +00:00 committed by Gerrit Code Review
commit 21de9f610d
3 changed files with 52 additions and 2 deletions

View File

@ -47,10 +47,14 @@ class L2populationDbMixin(base_db.CommonDbMixin):
return configuration.get('l2pop_network_types')
def get_agent_by_host(self, session, agent_host):
"""Return a L2 agent on the host."""
with session.begin(subtransactions=True):
query = session.query(agents_db.Agent)
query = query.filter(agents_db.Agent.host == agent_host)
return query.first()
for agent in query:
if self.get_agent_ip(agent):
return agent
def _get_active_network_ports(self, session, network_id):
with session.begin(subtransactions=True):

View File

@ -36,7 +36,11 @@ class TestConnectivitySameNetwork(base.BaseFullStackTestCase):
def setUp(self):
host_descriptions = [
environment.HostDescription() for _ in range(2)]
# There's value in enabling L3 agents registration when l2pop
# is enabled, because l2pop code makes assumptions about the
# agent types present on machines.
environment.HostDescription(
l3_agent=self.l2_pop) for _ in range(2)]
env = environment.Environment(
environment.EnvironmentDescription(
network_type=self.network_type,

View File

@ -0,0 +1,42 @@
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.common import constants
from neutron import context
from neutron.plugins.ml2.drivers.l2pop import db as l2pop_db
from neutron.tests.common import helpers
from neutron.tests.unit import testlib_api
class TestL2PopulationDBTestCase(testlib_api.SqlTestCase):
def setUp(self):
super(TestL2PopulationDBTestCase, self).setUp()
self.db_mixin = l2pop_db.L2populationDbMixin()
def test_get_agent_by_host(self):
# Register a L2 agent + A bunch of other agents on the same host
helpers.register_l3_agent()
helpers.register_dhcp_agent()
helpers.register_ovs_agent()
agent = self.db_mixin.get_agent_by_host(
context.get_admin_context().session, helpers.HOST)
self.assertEqual(constants.AGENT_TYPE_OVS, agent.agent_type)
def test_get_agent_by_host_no_candidate(self):
# Register a bunch of non-L2 agents on the same host
helpers.register_l3_agent()
helpers.register_dhcp_agent()
agent = self.db_mixin.get_agent_by_host(
context.get_admin_context().session, helpers.HOST)
self.assertIsNone(agent)