enable linuxbridge for agent scheduler

Bug #1135793
blueprint quantum-scheduler

In addition, we refactor agent scheduler so that we will make
it easier to enable plugin to support agent scheduler.

Change-Id: I0d5cc8bcea644720a3c5cbe92486ce8d8ecd248c
This commit is contained in:
gongysh 2013-03-01 17:06:23 +08:00
parent 3bb157628c
commit fdad941d3e
8 changed files with 72 additions and 39 deletions

View File

@ -15,21 +15,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.orm import exc
from sqlalchemy.orm import joinedload
from quantum.api.v2 import attributes
from quantum.common import constants
from quantum.db import agents_db
from quantum.db import model_base
from quantum.db import models_v2
from quantum.extensions import agentscheduler
from quantum.openstack.common import log as logging
from quantum.openstack.common import uuidutils
LOG = logging.getLogger(__name__)
@ -57,7 +53,8 @@ class RouterL3AgentBinding(model_base.BASEV2, models_v2.HasId):
ondelete='CASCADE'))
class AgentSchedulerDbMixin(agentscheduler.AgentSchedulerPluginBase):
class AgentSchedulerDbMixin(agentscheduler.AgentSchedulerPluginBase,
agents_db.AgentDbMixin):
"""Mixin class to add agent scheduler extension to db_plugin_base_v2."""
dhcp_agent_notifier = None
@ -362,3 +359,22 @@ class AgentSchedulerDbMixin(agentscheduler.AgentSchedulerPluginBase):
"""
for router in routers:
self.schedule_router(context, router)
def update_agent(self, context, id, agent):
original_agent = self.get_agent(context, id)
result = super(AgentSchedulerDbMixin, self).update_agent(
context, id, agent)
agent_data = agent['agent']
if ('admin_state_up' in agent_data and
original_agent['admin_state_up'] != agent_data['admin_state_up']):
if (original_agent['agent_type'] == constants.AGENT_TYPE_DHCP and
self.dhcp_agent_notifier):
self.dhcp_agent_notifier.agent_updated(
context, agent_data['admin_state_up'],
original_agent['host'])
elif (original_agent['agent_type'] == constants.AGENT_TYPE_L3 and
self.l3_agent_notifier):
self.l3_agent_notifier.agent_updated(
context, agent_data['admin_state_up'],
original_agent['host'])
return result

View File

@ -30,7 +30,9 @@ down_revision = '3b54bf9e29f7'
# Change to ['*'] if this migration applies to all plugins
migration_for_plugins = [
'quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2'
'quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2',
'quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2',
'quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2',
]
from alembic import op

View File

@ -32,6 +32,7 @@ down_revision = '363468ac592c'
migration_for_plugins = [
'quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2',
'quantum.plugins.linuxbridge.lb_quantum_plugin.LinuxBridgePluginV2',
'quantum.plugins.nicira.nicira_nvp_plugin.QuantumPlugin.NvpPluginV2',
]
from alembic import op

View File

@ -20,6 +20,7 @@
from oslo.config import cfg
from quantum.agent.common import config
from quantum import scheduler
DEFAULT_VLAN_RANGES = []
DEFAULT_INTERFACE_MAPPINGS = []
@ -51,5 +52,6 @@ agent_opts = [
cfg.CONF.register_opts(vlan_opts, "VLANS")
cfg.CONF.register_opts(bridge_opts, "LINUX_BRIDGE")
cfg.CONF.register_opts(agent_opts, "AGENT")
cfg.CONF.register_opts(scheduler.AGENTS_SCHEDULER_OPTS)
config.register_agent_state_opts_helper(cfg.CONF)
config.register_root_helper(cfg.CONF)

View File

@ -18,6 +18,8 @@ import sys
from oslo.config import cfg
from quantum.agent import securitygroups_rpc as sg_rpc
from quantum.api.rpc.agentnotifiers import dhcp_rpc_agent_api
from quantum.api.rpc.agentnotifiers import l3_rpc_agent_api
from quantum.api.v2 import attributes
from quantum.common import constants as q_const
from quantum.common import exceptions as q_exc
@ -25,6 +27,7 @@ from quantum.common import rpc as q_rpc
from quantum.common import topics
from quantum.common import utils
from quantum.db import agents_db
from quantum.db import agentschedulers_db
from quantum.db import api as db_api
from quantum.db import db_base_plugin_v2
from quantum.db import dhcp_rpc_base
@ -36,6 +39,7 @@ from quantum.db import securitygroups_rpc_base as sg_db_rpc
from quantum.extensions import portbindings
from quantum.extensions import providernet as provider
from quantum.extensions import securitygroup as ext_sg
from quantum.openstack.common import importutils
from quantum.openstack.common import log as logging
from quantum.openstack.common import rpc
from quantum.openstack.common.rpc import proxy
@ -174,7 +178,7 @@ class AgentNotifierApi(proxy.RpcProxy,
class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
extraroute_db.ExtraRoute_db_mixin,
sg_db_rpc.SecurityGroupServerRpcMixin,
agents_db.AgentDbMixin):
agentschedulers_db.AgentSchedulerDbMixin):
"""Implement the Quantum abstractions using Linux bridging.
A new VLAN is created for each network. An agent is relied upon
@ -199,7 +203,8 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
__native_sorting_support = True
supported_extension_aliases = ["provider", "router", "binding", "quotas",
"security-group", "agent", "extraroute"]
"security-group", "agent", "extraroute",
"agent_scheduler"]
network_view = "extension:provider_network:view"
network_set = "extension:provider_network:set"
@ -219,6 +224,10 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
self.tenant_network_type)
sys.exit(1)
self._setup_rpc()
self.network_scheduler = importutils.import_object(
cfg.CONF.network_scheduler_driver)
self.router_scheduler = importutils.import_object(
cfg.CONF.router_scheduler_driver)
LOG.debug(_("Linux Bridge Plugin initialization complete"))
def _setup_rpc(self):
@ -232,6 +241,8 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
# Consume from all consumers in a thread
self.conn.consume_in_thread()
self.notifier = AgentNotifierApi(topics.AGENT)
self.dhcp_agent_notifier = dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
self.l3_agent_notifier = l3_rpc_agent_api.L3AgentNotify
def _parse_network_vlan_ranges(self):
self.network_vlan_ranges = {}

View File

@ -217,7 +217,6 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
qos_db.NVPQoSDbMixin,
nvp_sec.NVPSecurityGroups,
nvp_meta.NvpMetadataAccess,
agents_db.AgentDbMixin,
agentschedulers_db.AgentSchedulerDbMixin):
"""
NvpPluginV2 is a Quantum plugin that provides L2 Virtual Network
@ -2198,15 +2197,3 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
return []
return super(NvpPluginV2, self).get_qos_queues(context, filters,
fields)
def update_agent(self, context, id, agent):
original_agent = self.get_agent(context, id)
result = super(NvpPluginV2, self).update_agent(context, id, agent)
agent_data = agent['agent']
if ('admin_state_up' in agent_data and
original_agent['admin_state_up'] != agent_data['admin_state_up']):
if original_agent['agent_type'] == constants.AGENT_TYPE_DHCP:
self.dhcp_agent_notifier.agent_updated(
context, agent_data['admin_state_up'],
original_agent['host'])
return result

View File

@ -215,7 +215,6 @@ class AgentNotifierApi(proxy.RpcProxy,
class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
extraroute_db.ExtraRoute_db_mixin,
sg_db_rpc.SecurityGroupServerRpcMixin,
agents_db.AgentDbMixin,
agentschedulers_db.AgentSchedulerDbMixin):
"""Implement the Quantum abstractions using Open vSwitch.
@ -644,20 +643,3 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
self.notifier.security_groups_member_updated(
context, port.get(ext_sg.SECURITYGROUPS))
def update_agent(self, context, id, agent):
original_agent = self.get_agent(context, id)
result = super(OVSQuantumPluginV2, self).update_agent(
context, id, agent)
agent_data = agent['agent']
if ('admin_state_up' in agent_data and
original_agent['admin_state_up'] != agent_data['admin_state_up']):
if original_agent['agent_type'] == q_const.AGENT_TYPE_DHCP:
self.dhcp_agent_notifier.agent_updated(
context, agent_data['admin_state_up'],
original_agent['host'])
elif original_agent['agent_type'] == q_const.AGENT_TYPE_L3:
self.l3_agent_notifier.agent_updated(
context, agent_data['admin_state_up'],
original_agent['host'])
return result

View File

@ -0,0 +1,32 @@
# Copyright (c) 2013 OpenStack, LLC.
#
# 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 quantum.tests.unit.openvswitch import test_agent_scheduler
from quantum.tests.unit.linuxbridge import test_linuxbridge_plugin
class LbAgentSchedulerTestCase(
test_agent_scheduler.OvsAgentSchedulerTestCase):
plugin_str = test_linuxbridge_plugin.PLUGIN_NAME
class LbL3AgentNotifierTestCase(
test_agent_scheduler.OvsL3AgentNotifierTestCase):
plugin_str = test_linuxbridge_plugin.PLUGIN_NAME
class LbDhcpAgentNotifierTestCase(
test_agent_scheduler.OvsDhcpAgentNotifierTestCase):
plugin_str = test_linuxbridge_plugin.PLUGIN_NAME