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
This commit is contained in:
Divya ChanneGowda 2014-06-06 14:29:21 -07:00
parent 01c45aecfb
commit 3190e5b672
3 changed files with 33 additions and 6 deletions

View File

@ -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']

View File

@ -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

View File

@ -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'])