Add support to the port binding extension for the NVP plugin.

Also, this patch removes the non-serializable object for
port profile. This went undetected for quite some time.

Implements blueprint nvp-port-binding-extension

Change-Id: I380570f08e92f75d6431dcda6fac2a770887bb48
This commit is contained in:
armando-migliaccio 2013-06-04 15:45:06 -07:00
parent 709a509aa0
commit c0f80bf720
4 changed files with 29 additions and 3 deletions

View File

@ -32,6 +32,7 @@ down_revision = 'grizzly'
migration_for_plugins = [ migration_for_plugins = [
'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2',
'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2',
'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2',
] ]
from alembic import op from alembic import op

View File

@ -70,6 +70,10 @@ class PortBindingMixin(object):
def _process_portbindings_create_and_update(self, context, port_data, def _process_portbindings_create_and_update(self, context, port_data,
port): port):
binding_profile = port.get(portbindings.PROFILE)
binding_profile_set = attributes.is_attr_set(binding_profile)
if not binding_profile_set and binding_profile is not None:
del port[portbindings.PROFILE]
host = port_data.get(portbindings.HOST_ID) host = port_data.get(portbindings.HOST_ID)
host_set = attributes.is_attr_set(host) host_set = attributes.is_attr_set(host)
if not host_set: if not host_set:

View File

@ -46,11 +46,13 @@ from neutron.db import extraroute_db
from neutron.db import l3_db from neutron.db import l3_db
from neutron.db import l3_gwmode_db from neutron.db import l3_gwmode_db
from neutron.db import models_v2 from neutron.db import models_v2
from neutron.db import portbindings_db
from neutron.db import portsecurity_db from neutron.db import portsecurity_db
from neutron.db import quota_db # noqa from neutron.db import quota_db # noqa
from neutron.db import securitygroups_db from neutron.db import securitygroups_db
from neutron.extensions import extraroute from neutron.extensions import extraroute
from neutron.extensions import l3 from neutron.extensions import l3
from neutron.extensions import portbindings as pbin
from neutron.extensions import portsecurity as psec from neutron.extensions import portsecurity as psec
from neutron.extensions import providernet as pnet from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as ext_sg from neutron.extensions import securitygroup as ext_sg
@ -130,6 +132,7 @@ class NVPRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin):
class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2, class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
extraroute_db.ExtraRoute_db_mixin, extraroute_db.ExtraRoute_db_mixin,
l3_gwmode_db.L3_NAT_db_mixin, l3_gwmode_db.L3_NAT_db_mixin,
portbindings_db.PortBindingMixin,
portsecurity_db.PortSecurityDbMixin, portsecurity_db.PortSecurityDbMixin,
securitygroups_db.SecurityGroupDbMixin, securitygroups_db.SecurityGroupDbMixin,
mac_db.MacLearningDbMixin, mac_db.MacLearningDbMixin,
@ -145,6 +148,7 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
""" """
supported_extension_aliases = ["agent", supported_extension_aliases = ["agent",
"binding",
"dhcp_agent_scheduler", "dhcp_agent_scheduler",
"ext_gw_mode", "ext_gw_mode",
"extraroute", "extraroute",
@ -196,6 +200,12 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
self.nvp_opts.concurrent_connections, self.nvp_opts.concurrent_connections,
self.nvp_opts.nvp_gen_timeout) self.nvp_opts.nvp_gen_timeout)
self.extra_binding_dict = {
pbin.VIF_TYPE: pbin.VIF_TYPE_OVS,
pbin.CAPABILITIES: {
pbin.CAP_PORT_FILTER:
'security-group' in self.supported_extension_aliases}}
db.configure_db() db.configure_db()
# Extend the fault map # Extend the fault map
self._extend_fault_map() self._extend_fault_map()
@ -1079,8 +1089,7 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
return net return net
def get_ports(self, context, filters=None, fields=None): def get_ports(self, context, filters=None, fields=None):
if filters is None: filters = filters or {}
filters = {}
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
neutron_lports = super(NvpPluginV2, self).get_ports( neutron_lports = super(NvpPluginV2, self).get_ports(
context, filters) context, filters)
@ -1256,6 +1265,8 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
del port_data[ext_qos.QUEUE] del port_data[ext_qos.QUEUE]
self._extend_port_port_security_dict(context, port_data) self._extend_port_port_security_dict(context, port_data)
self._extend_port_qos_queue(context, port_data) self._extend_port_qos_queue(context, port_data)
self._process_portbindings_create_and_update(context,
port, port_data)
net = self.get_network(context, port_data['network_id']) net = self.get_network(context, port_data['network_id'])
self.schedule_network(context, net) self.schedule_network(context, net)
if notify_dhcp_agent: if notify_dhcp_agent:
@ -1360,6 +1371,9 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
# remove since it will be added in extend based on policy # remove since it will be added in extend based on policy
del ret_port[ext_qos.QUEUE] del ret_port[ext_qos.QUEUE]
self._extend_port_qos_queue(context, ret_port) self._extend_port_qos_queue(context, ret_port)
self._process_portbindings_create_and_update(context,
port['port'],
port)
return ret_port return ret_port
def delete_port(self, context, id, l3_port_check=True, def delete_port(self, context, id, l3_port_check=True,

View File

@ -25,6 +25,7 @@ from neutron.common import constants
import neutron.common.test_lib as test_lib import neutron.common.test_lib as test_lib
from neutron import context from neutron import context
from neutron.extensions import l3 from neutron.extensions import l3
from neutron.extensions import portbindings
from neutron.extensions import providernet as pnet from neutron.extensions import providernet as pnet
from neutron.extensions import securitygroup as secgrp from neutron.extensions import securitygroup as secgrp
from neutron import manager from neutron import manager
@ -36,6 +37,7 @@ from neutron.plugins.nicira import NeutronPlugin
from neutron.plugins.nicira import NvpApiClient from neutron.plugins.nicira import NvpApiClient
from neutron.plugins.nicira.NvpApiClient import NVPVersion from neutron.plugins.nicira.NvpApiClient import NVPVersion
from neutron.plugins.nicira import nvplib from neutron.plugins.nicira import nvplib
from neutron.tests.unit import _test_extension_portbindings as test_bindings
from neutron.tests.unit.nicira import fake_nvpapiclient from neutron.tests.unit.nicira import fake_nvpapiclient
import neutron.tests.unit.nicira.test_networkgw as test_l2_gw import neutron.tests.unit.nicira.test_networkgw as test_l2_gw
import neutron.tests.unit.test_db_plugin as test_plugin import neutron.tests.unit.test_db_plugin as test_plugin
@ -105,7 +107,12 @@ class TestNiciraV2HTTPResponse(test_plugin.TestV2HTTPResponse,
pass pass
class TestNiciraPortsV2(test_plugin.TestPortsV2, NiciraPluginV2TestCase): class TestNiciraPortsV2(test_plugin.TestPortsV2,
NiciraPluginV2TestCase,
test_bindings.PortBindingsTestCase):
VIF_TYPE = portbindings.VIF_TYPE_OVS
HAS_PORT_FILTER = True
def test_exhaust_ports_overlay_network(self): def test_exhaust_ports_overlay_network(self):
cfg.CONF.set_override('max_lp_per_overlay_ls', 1, group='NVP') cfg.CONF.set_override('max_lp_per_overlay_ls', 1, group='NVP')