lp834694 fix integrity error when deleting network with unattached ports. Add unit test.
This commit is contained in:
parent
fa4e2c4c7d
commit
a74d433e15
@ -142,6 +142,13 @@ def network_destroy(net_id):
|
||||
net = session.query(models.Network).\
|
||||
filter_by(uuid=net_id).\
|
||||
one()
|
||||
|
||||
ports = session.query(models.Port).\
|
||||
filter_by(network_id=net_id).\
|
||||
all()
|
||||
for p in ports:
|
||||
session.delete(p)
|
||||
|
||||
session.delete(net)
|
||||
session.flush()
|
||||
return net
|
||||
|
@ -261,6 +261,26 @@ class APITest(unittest.TestCase):
|
||||
self.assertEqual(delete_network_res.status_int, 421)
|
||||
LOG.debug("_test_delete_network_in_use - format:%s - END", format)
|
||||
|
||||
def _test_delete_network_with_unattached_port(self, format):
|
||||
LOG.debug("_test_delete_network_with_unattached_port "\
|
||||
"- format:%s - START", format)
|
||||
content_type = "application/%s" % format
|
||||
port_state = "ACTIVE"
|
||||
network_id = self._create_network(format)
|
||||
LOG.debug("Deleting network %(network_id)s"\
|
||||
" of tenant %(tenant_id)s", locals())
|
||||
port_id = self._create_port(network_id, port_state, format)
|
||||
|
||||
LOG.debug("Deleting network %(network_id)s"\
|
||||
" of tenant %(tenant_id)s", locals())
|
||||
delete_network_req = testlib.network_delete_request(self.tenant_id,
|
||||
network_id,
|
||||
format)
|
||||
delete_network_res = delete_network_req.get_response(self.api)
|
||||
self.assertEqual(delete_network_res.status_int, 204)
|
||||
LOG.debug("_test_delete_network_with_unattached_port "\
|
||||
"- format:%s - END", format)
|
||||
|
||||
def _test_list_ports(self, format):
|
||||
LOG.debug("_test_list_ports - format:%s - START", format)
|
||||
content_type = "application/%s" % format
|
||||
@ -848,6 +868,12 @@ class APITest(unittest.TestCase):
|
||||
def test_delete_network_in_use_xml(self):
|
||||
self._test_delete_network_in_use('xml')
|
||||
|
||||
def test_delete_network_with_unattached_port_xml(self):
|
||||
self._test_delete_network_with_unattached_port('xml')
|
||||
|
||||
def test_delete_network_with_unattached_port_json(self):
|
||||
self._test_delete_network_with_unattached_port('json')
|
||||
|
||||
def test_list_ports_json(self):
|
||||
self._test_list_ports('json')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user