From 7a5b298f429b9b9d2810e5063ad19510478b84b4 Mon Sep 17 00:00:00 2001 From: Edgar Magana Date: Thu, 5 Dec 2013 15:42:04 -0800 Subject: [PATCH] Implements provider network support in PLUMgrid plugin Includes the provider network extension in PLUMgrid plugin PLUMgrid drivers are updated with the new extension data Unit tests are added Change-Id: Ia7fc011c04d143bdb7fd8f67768a2076be8c5264 Implements: blueprint provider-network-plumgrid --- .../plugins/plumgrid/drivers/fake_plumlib.py | 11 +++++++--- neutron/plugins/plumgrid/drivers/plumlib.py | 4 ++-- .../plumgrid_plugin/plumgrid_plugin.py | 4 ++-- .../unit/plumgrid/test_plumgrid_plugin.py | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/neutron/plugins/plumgrid/drivers/fake_plumlib.py b/neutron/plugins/plumgrid/drivers/fake_plumlib.py index 28f32977c..a0a01023d 100644 --- a/neutron/plugins/plumgrid/drivers/fake_plumlib.py +++ b/neutron/plugins/plumgrid/drivers/fake_plumlib.py @@ -15,7 +15,7 @@ # # @author: Edgar Magana, emagana@plumgrid.com, PLUMgrid, Inc. - +from neutron.extensions import providernet as provider from neutron.openstack.common import log as logging LOG = logging.getLogger(__name__) @@ -38,8 +38,13 @@ class Plumlib(): director_plumgrid + ':' + director_port) pass - def create_network(self, tenant_id, net_db): - pass + def create_network(self, tenant_id, net_db, network): + net_db["network"] = {} + for key in (provider.NETWORK_TYPE, + provider.PHYSICAL_NETWORK, + provider.SEGMENTATION_ID): + net_db["network"][key] = network["network"][key] + return net_db def update_network(self, tenant_id, net_id): pass diff --git a/neutron/plugins/plumgrid/drivers/plumlib.py b/neutron/plugins/plumgrid/drivers/plumlib.py index 18c8a50d5..7a6c98c19 100644 --- a/neutron/plugins/plumgrid/drivers/plumlib.py +++ b/neutron/plugins/plumgrid/drivers/plumlib.py @@ -45,8 +45,8 @@ class Plumlib(object): director_admin, director_password) - def create_network(self, tenant_id, net_db): - self.plumlib.create_network(tenant_id, net_db) + def create_network(self, tenant_id, net_db, network): + self.plumlib.create_network(tenant_id, net_db, network) def update_network(self, tenant_id, net_id): self.plumlib.update_network(tenant_id, net_id) diff --git a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py index fb389c434..70c809122 100644 --- a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py +++ b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py @@ -61,7 +61,7 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2, l3_db.L3_NAT_db_mixin): supported_extension_aliases = ["external-net", "router", "binding", - "quotas"] + "quotas", "provider"] binding_view = "extension:port_binding:view" binding_set = "extension:port_binding:set" @@ -112,7 +112,7 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2, try: LOG.debug(_('PLUMgrid Library: create_network() called')) - self._plumlib.create_network(tenant_id, net_db) + self._plumlib.create_network(tenant_id, net_db, network) except Exception as err_message: raise plum_excep.PLUMgridException(err_msg=err_message) diff --git a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py index 92f020b3d..6cc39ce79 100644 --- a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py +++ b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py @@ -22,6 +22,7 @@ Test cases for Neutron PLUMgrid Plug-in import mock from neutron.extensions import portbindings +from neutron.extensions import providernet as provider from neutron.manager import NeutronManager from neutron.openstack.common import importutils from neutron.plugins.plumgrid.plumgrid_plugin import plumgrid_plugin @@ -127,3 +128,23 @@ class TestPlumgridAllocationPool(PLUMgridPluginV2TestCase): plugin = NeutronManager.get_plugin() pool = plugin._allocate_pools_for_subnet(context, subnet) self.assertEqual(allocation_pool, pool) + + +class TestPlumgridProvidernet(PLUMgridPluginV2TestCase): + + def test_create_provider_network(self): + tenant_id = 'admin' + data = {'network': {'name': 'net1', + 'admin_state_up': True, + 'tenant_id': tenant_id, + provider.NETWORK_TYPE: 'vlan', + provider.SEGMENTATION_ID: 3333, + provider.PHYSICAL_NETWORK: 'phy3333'}} + + network_req = self.new_create_request('networks', data, self.fmt) + net = self.deserialize(self.fmt, network_req.get_response(self.api)) + plumlib = importutils.import_object(PLUM_DRIVER) + plumlib.create_network(tenant_id, net, data) + self.assertEqual(net['network'][provider.NETWORK_TYPE], 'vlan') + self.assertEqual(net['network'][provider.SEGMENTATION_ID], 3333) + self.assertEqual(net['network'][provider.PHYSICAL_NETWORK], 'phy3333') -- 2.45.2