Merge "Check for ports in subnet before deleting it from Nuage VSD"

This commit is contained in:
Jenkins 2014-09-18 22:53:10 +00:00 committed by Gerrit Code Review
commit e6c81f1bd2
2 changed files with 20 additions and 0 deletions

View File

@ -691,6 +691,12 @@ class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
super(NuagePlugin, self).delete_subnet(context, id)
return self._delete_nuage_sharedresource(id)
filters = {'fixed_ips': {'subnet_id': [id]}}
ports = self.get_ports(context, filters)
for port in ports:
if port['device_owner'] != os_constants.DEVICE_OWNER_DHCP:
raise n_exc.SubnetInUse(subnet_id=id)
subnet_l2dom = nuagedb.get_subnet_l2dom_by_id(context.session, id)
if subnet_l2dom:
try:

View File

@ -343,6 +343,20 @@ class TestNuageSubnetsV2(NuagePluginV2TestCase,
subnet_res = subnet_req.get_response(self.api)
self.assertEqual(exc.HTTPCreated.code, subnet_res.status_int)
def test_delete_subnet_port_exists_returns_409(self):
gateway_ip = '10.0.0.1'
cidr = '10.0.0.0/24'
res = self._create_network(fmt=self.fmt, name='net',
admin_state_up=True)
network = self.deserialize(self.fmt, res)
subnet = self._make_subnet(self.fmt, network, gateway_ip,
cidr, ip_version=4)
self._create_port(self.fmt,
network['network']['id'])
req = self.new_delete_request('subnets', subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(409, res.status_int)
class TestNuagePluginPortBinding(NuagePluginV2TestCase,
test_bindings.PortBindingsTestCase):