From 3190e5b672ac21f9c82110d319473f2041bf64f7 Mon Sep 17 00:00:00 2001 From: Divya ChanneGowda Date: Fri, 6 Jun 2014 14:29:21 -0700 Subject: [PATCH] Change default netpartition behavior in nuage plugin Allows the nuage plugin handle the case where default netpartition already exists on the VSD (back-end controller) Change-Id: Ia5785c1c313cf30b8bad6cda1d0e9819784e06d8 Closes-Bug: #1319892 --- neutron/plugins/nuage/plugin.py | 21 +++++++++++++------ neutron/tests/unit/nuage/fake_nuageclient.py | 9 ++++++++ neutron/tests/unit/nuage/test_netpartition.py | 9 ++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/neutron/plugins/nuage/plugin.py b/neutron/plugins/nuage/plugin.py index d5d9d34d9d6..bf95c1eecf0 100644 --- a/neutron/plugins/nuage/plugin.py +++ b/neutron/plugins/nuage/plugin.py @@ -806,14 +806,23 @@ class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2, return self._make_net_partition_dict(net_partitioninst) def _create_default_net_partition(self, default_net_part): - self.nuageclient.check_del_def_net_partition(default_net_part) + def_netpart = self.nuageclient.get_def_netpartition_data( + default_net_part) session = db.get_session() - net_partition = nuagedb.get_net_partition_by_name(session, - default_net_part) - if net_partition: + if def_netpart: + net_partition = nuagedb.get_net_partition_by_name( + session, default_net_part) with session.begin(subtransactions=True): - nuagedb.delete_net_partition(session, net_partition) - self._create_net_partition(session, default_net_part) + if net_partition: + nuagedb.delete_net_partition(session, net_partition) + net_part = nuagedb.add_net_partition(session, + def_netpart['np_id'], + def_netpart['l3dom_tid'], + def_netpart['l2dom_tid'], + default_net_part) + return self._make_net_partition_dict(net_part) + else: + return self._create_net_partition(session, default_net_part) def create_net_partition(self, context, net_partition): ent = net_partition['net_partition'] diff --git a/neutron/tests/unit/nuage/fake_nuageclient.py b/neutron/tests/unit/nuage/fake_nuageclient.py index 6465c403ee8..2abcd8ddc5e 100644 --- a/neutron/tests/unit/nuage/fake_nuageclient.py +++ b/neutron/tests/unit/nuage/fake_nuageclient.py @@ -72,6 +72,15 @@ class FakeNuageClient(object): } return fake_net_partition + def get_def_netpartition_data(self, default_net_part): + if default_net_part == 'default_test_np': + fake_defnetpart_data = { + 'np_id': uuidutils.generate_uuid(), + 'l3dom_tid': uuidutils.generate_uuid(), + 'l2dom_tid': uuidutils.generate_uuid(), + } + return fake_defnetpart_data + def delete_net_partition(self, id, l3dom_id=None, l2dom_id=None): pass diff --git a/neutron/tests/unit/nuage/test_netpartition.py b/neutron/tests/unit/nuage/test_netpartition.py index 2bf52f7f20f..bf51bc40a05 100644 --- a/neutron/tests/unit/nuage/test_netpartition.py +++ b/neutron/tests/unit/nuage/test_netpartition.py @@ -18,6 +18,7 @@ import contextlib import uuid import webob.exc +from neutron import manager from neutron.plugins.nuage.extensions import netpartition as netpart_ext from neutron.tests.unit.nuage import test_nuage_plugin from neutron.tests.unit import test_extensions @@ -89,3 +90,11 @@ class NetPartitionTestCase(test_nuage_plugin.NuagePluginV2TestCase): res = self.deserialize(self.fmt, req.get_response(self.ext_api)) self.assertEqual(res['net_partition']['name'], npart['net_partition']['name']) + + def test_create_existing_default_netpartition(self): + name = 'default_test_np' + netpart1 = self._make_netpartition(self.fmt, name) + nuage_plugin = manager.NeutronManager.get_plugin() + netpart2 = nuage_plugin._create_default_net_partition(name) + self.assertEqual(netpart1['net_partition']['name'], + netpart2['name'])