Add port bindings to ports created in Midonet
Currently Midokura uses its own script (mm-ctl) to bind ports. However, support for using this script is left out of the nova and neutron projects. This causes confusion and makes deployments unnecessarily complicated for customers using Havana. This fix is to change Neutron to properly set up port bindings to use the "midonet" vif driver when creating a port. Corresponding changes will be submitted to the devstack and Nova projects. Change-Id: I91f2e4fe7135da0c22fb408081efdc63fff748df Closes-Bug: 1235134
This commit is contained in:
parent
02275773ec
commit
110e7a7e39
@ -44,10 +44,12 @@ VIF_TYPE_BRIDGE = 'bridge'
|
||||
VIF_TYPE_802_QBG = '802.1qbg'
|
||||
VIF_TYPE_802_QBH = '802.1qbh'
|
||||
VIF_TYPE_HYPERV = 'hyperv'
|
||||
VIF_TYPE_MIDONET = 'midonet'
|
||||
VIF_TYPE_OTHER = 'other'
|
||||
VIF_TYPES = [VIF_TYPE_UNBOUND, VIF_TYPE_BINDING_FAILED, VIF_TYPE_OVS,
|
||||
VIF_TYPE_IVS, VIF_TYPE_BRIDGE, VIF_TYPE_802_QBG,
|
||||
VIF_TYPE_802_QBH, VIF_TYPE_HYPERV, VIF_TYPE_OTHER]
|
||||
VIF_TYPE_802_QBH, VIF_TYPE_HYPERV, VIF_TYPE_MIDONET,
|
||||
VIF_TYPE_OTHER]
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
|
@ -38,9 +38,11 @@ from neutron.db import dhcp_rpc_base
|
||||
from neutron.db import external_net_db
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import portbindings_db
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.extensions import external_net as ext_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron.openstack.common import excutils
|
||||
from neutron.openstack.common import log as logging
|
||||
@ -195,13 +197,14 @@ class MidonetPluginException(n_exc.NeutronException):
|
||||
|
||||
|
||||
class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
portbindings_db.PortBindingMixin,
|
||||
external_net_db.External_net_db_mixin,
|
||||
l3_db.L3_NAT_db_mixin,
|
||||
agentschedulers_db.DhcpAgentSchedulerDbMixin,
|
||||
securitygroups_db.SecurityGroupDbMixin):
|
||||
|
||||
supported_extension_aliases = ['external-net', 'router', 'security-group',
|
||||
'agent' 'dhcp_agent_scheduler']
|
||||
'agent' 'dhcp_agent_scheduler', 'binding']
|
||||
__native_bulk_support = False
|
||||
|
||||
def __init__(self):
|
||||
@ -229,6 +232,12 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self.setup_rpc()
|
||||
db.configure_db()
|
||||
|
||||
self.base_binding_dict = {
|
||||
portbindings.VIF_TYPE: portbindings.VIF_TYPE_MIDONET,
|
||||
portbindings.CAPABILITIES: {
|
||||
portbindings.CAP_PORT_FILTER:
|
||||
'security-group' in self.supported_extension_aliases}}
|
||||
|
||||
def _get_provider_router(self):
|
||||
if self.provider_router is None:
|
||||
self.provider_router = self.client.get_router(
|
||||
@ -529,7 +538,7 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
if _is_vif_port(port_data):
|
||||
# Bind security groups to the port
|
||||
sg_ids = self._get_security_groups_on_port(context, port)
|
||||
self._bind_port_to_sgs(context, port_data, sg_ids)
|
||||
self._bind_port_to_sgs(context, new_port, sg_ids)
|
||||
|
||||
# Create port chains
|
||||
port_chains = {}
|
||||
@ -561,6 +570,8 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self.client.add_dhcp_route_option(bridge, cidr, ip,
|
||||
METADATA_DEFAULT_IP)
|
||||
|
||||
self._process_portbindings_create_and_update(context,
|
||||
port_data, new_port)
|
||||
except Exception as ex:
|
||||
# Try removing the MidoNet port before raising an exception.
|
||||
with excutils.save_and_reraise_exception():
|
||||
@ -569,8 +580,8 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
{"net_id": port_data["network_id"], "err": ex})
|
||||
self.client.delete_port(bridge_port.get_id())
|
||||
|
||||
LOG.debug(_("MidonetPluginV2.create_port exiting: port=%r"), port_data)
|
||||
return port_data
|
||||
LOG.debug(_("MidonetPluginV2.create_port exiting: port=%r"), new_port)
|
||||
return new_port
|
||||
|
||||
def get_port(self, context, id, fields=None):
|
||||
"""Retrieve port."""
|
||||
@ -677,6 +688,9 @@ class MidonetPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
sg_ids = self._get_security_groups_on_port(context, port)
|
||||
self._bind_port_to_sgs(context, p, sg_ids)
|
||||
|
||||
self._process_portbindings_create_and_update(context,
|
||||
port['port'],
|
||||
p)
|
||||
return p
|
||||
|
||||
def create_router(self, context, router):
|
||||
|
@ -25,6 +25,8 @@ import os
|
||||
import sys
|
||||
|
||||
import neutron.common.test_lib as test_lib
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
||||
import neutron.tests.unit.midonet.mock_lib as mock_lib
|
||||
import neutron.tests.unit.test_db_plugin as test_plugin
|
||||
import neutron.tests.unit.test_extension_security_group as sg
|
||||
@ -138,3 +140,18 @@ class TestMidonetPortsV2(test_plugin.TestPortsV2,
|
||||
|
||||
def test_requested_subnet_id_v4_and_v6(self):
|
||||
pass
|
||||
|
||||
def test_vif_port_binding(self):
|
||||
with self.port(name='myname') as port:
|
||||
self.assertEqual('midonet', port['port']['binding:vif_type'])
|
||||
self.assertTrue(port['port']['admin_state_up'])
|
||||
|
||||
|
||||
class TestMidonetPluginPortBinding(test_bindings.PortBindingsTestCase,
|
||||
MidonetPluginV2TestCase):
|
||||
|
||||
VIF_TYPE = portbindings.VIF_TYPE_MIDONET
|
||||
HAS_PORT_FILTER = True
|
||||
|
||||
def setUp(self):
|
||||
super(TestMidonetPluginPortBinding, self).setUp()
|
||||
|
Loading…
Reference in New Issue
Block a user