From 609f01a1ddca64ec191cb15a4f6fb93d219c3336 Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Thu, 23 Jan 2014 17:37:49 -0800 Subject: [PATCH] Support Port Binding Extension in Cisco N1kv plugin Change-Id: I9bcacb2b1f1bb1500b9176a49736aac128938de8 Closes-Bug: #1272128 --- .../plugins/cisco/n1kv/n1kv_neutron_plugin.py | 40 +++++++++++++------ .../tests/unit/cisco/n1kv/test_n1kv_plugin.py | 7 +++- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index 682edd740..ceef16b6f 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -35,6 +35,8 @@ from neutron.db import dhcp_rpc_base from neutron.db import external_net_db from neutron.db import l3_db from neutron.db import l3_rpc_base +from neutron.db import portbindings_db +from neutron.extensions import portbindings from neutron.extensions import providernet from neutron.openstack.common import log as logging from neutron.openstack.common import rpc @@ -74,6 +76,7 @@ class N1kvRpcCallbacks(dhcp_rpc_base.DhcpRpcCallbackMixin, class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, external_net_db.External_net_db_mixin, l3_db.L3_NAT_db_mixin, + portbindings_db.PortBindingMixin, n1kv_db_v2.NetworkProfile_db_mixin, n1kv_db_v2.PolicyProfile_db_mixin, network_db_v2.Credential_db_mixin, @@ -93,16 +96,23 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, supported_extension_aliases = ["provider", "agent", "n1kv_profile", "network_profile", "policy_profile", "external-net", "router", - "credential"] + "binding", "credential"] def __init__(self, configfile=None): """ Initialize Nexus1000V Neutron plugin. - 1. Initialize Nexus1000v and Credential DB - 2. Establish communication with Cisco Nexus1000V + 1. Initialize VIF type to OVS + 2. Initialize Nexus1000v and Credential DB + 3. Establish communication with Cisco Nexus1000V """ super(N1kvNeutronPluginV2, self).__init__() + self.base_binding_dict = { + portbindings.VIF_TYPE: portbindings.VIF_TYPE_OVS, + portbindings.VIF_DETAILS: { + # TODO(rkukura): Replace with new VIF security details + portbindings.CAP_PORT_FILTER: + 'security-group' in self.supported_extension_aliases}} c_cred.Store.initialize() self._initialize_network_ranges() self._setup_vsm() @@ -1198,6 +1208,9 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, port) n1kv_db_v2.add_port_binding(session, pt['id'], profile_id) self._extend_port_dict_profile(context, pt) + self._process_portbindings_create_and_update(context, + port['port'], + pt) try: self._send_create_port_request(context, pt) except(cisco_exceptions.VSMError, @@ -1216,11 +1229,14 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, :returns: updated port object """ LOG.debug(_("Update port: %s"), id) - if self.agent_vsm: - super(N1kvNeutronPluginV2, self).get_port(context, id) - port = super(N1kvNeutronPluginV2, self).update_port(context, id, port) - self._extend_port_dict_profile(context, port) - return port + with context.session.begin(subtransactions=True): + updated_port = super(N1kvNeutronPluginV2, + self).update_port(context, id, port) + self._process_portbindings_create_and_update(context, + port['port'], + updated_port) + self._extend_port_dict_profile(context, updated_port) + return updated_port def delete_port(self, context, id, l3_port_check=True): """ @@ -1228,15 +1244,15 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2, :param context: neutron api request context :param id: UUID representing the port to delete - :returns: deleted port object """ # if needed, check to see if this is a port owned by # and l3-router. If so, we should prevent deletion. if l3_port_check: self.prevent_l3_port_deletion(context, id) - self.disassociate_floatingips(context, id) - self._send_delete_port_request(context, id) - return super(N1kvNeutronPluginV2, self).delete_port(context, id) + with context.session.begin(subtransactions=True): + self.disassociate_floatingips(context, id) + self._send_delete_port_request(context, id) + super(N1kvNeutronPluginV2, self).delete_port(context, id) def get_port(self, context, id, fields=None): """ diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py index 72761f449..ad67c709f 100644 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py @@ -24,6 +24,7 @@ from neutron.api import extensions as neutron_extensions from neutron.api.v2 import attributes from neutron import context import neutron.db.api as db +from neutron.extensions import portbindings from neutron.plugins.cisco.db import n1kv_db_v2 from neutron.plugins.cisco.db import network_db_v2 as cdb from neutron.plugins.cisco import extensions @@ -31,6 +32,7 @@ from neutron.plugins.cisco.extensions import n1kv_profile from neutron.plugins.cisco.extensions import network_profile from neutron.plugins.cisco.n1kv import n1kv_client from neutron.plugins.cisco.n1kv import n1kv_neutron_plugin +from neutron.tests.unit import _test_extension_portbindings as test_bindings from neutron.tests.unit import test_api_v2 from neutron.tests.unit import test_db_plugin as test_plugin @@ -304,7 +306,10 @@ class TestN1kvHTTPResponse(test_plugin.TestV2HTTPResponse, class TestN1kvPorts(test_plugin.TestPortsV2, - N1kvPluginTestCase): + N1kvPluginTestCase, + test_bindings.PortBindingsTestCase): + VIF_TYPE = portbindings.VIF_TYPE_OVS + HAS_PORT_FILTER = False def test_create_port_with_default_n1kv_profile_id(self): """Test port create without passing policy profile id.""" -- 2.45.2