Enable passive deletes on trunk deletion

Add missing sqlalchemy cascade="all, delete-orphan" on the
trunk-subports relationship to disable child object loading
on a trunk delete operation, otherwise sqlalchemy would
attempt to update the children with a NULL key, and cause
an integrity violation.

Deleting a trunk with subports is allowed, and a test is
added to cover that.

Partially-implements: blueprint vlan-aware-vms

Change-Id: I143c436ce6d2d3a441c26a4b08730981f1ec2973
This commit is contained in:
Armando Migliaccio 2016-07-20 16:28:24 -07:00
parent 3150196c54
commit 29cc91ef25
2 changed files with 15 additions and 1 deletions

View File

@ -41,7 +41,8 @@ class Trunk(model_base.HasStandardAttributes, model_base.BASEV2,
backref=sa.orm.backref('trunk_port', lazy='joined', uselist=False,
cascade='delete'))
sub_ports = sa.orm.relationship('SubPort', lazy='joined', uselist=True)
sub_ports = sa.orm.relationship(
'SubPort', lazy='joined', uselist=True, cascade="all, delete-orphan")
class SubPort(model_base.BASEV2):

View File

@ -21,6 +21,9 @@ from neutron.tests.tempest.api import base
def trunks_cleanup(client, trunks):
for trunk in trunks:
# NOTE(armax): deleting a trunk with subports is permitted, however
# for testing purposes it is safer to be explicit and clean all the
# resources associated with the trunk beforehand.
subports = test_utils.call_and_ignore_notfound_exc(
client.get_subports, trunk['id'])
if subports:
@ -129,6 +132,16 @@ class TrunkTestJSON(TrunkTestJSONBase):
created_subport = observed_subports[0]
self.assertEqual(subports[0], created_subport)
@test.idempotent_id('ee5fcead-1abf-483a-bce6-43d1e06d6aa0')
def test_delete_trunk_with_subport_is_allowed(self):
network = self.create_network()
port = self.create_port(network)
subports = [{'port_id': port['id'],
'segmentation_type': 'vlan',
'segmentation_id': 2}]
trunk = self._create_trunk_with_network_and_parent(subports)
self.client.delete_trunk(trunk['trunk']['id'])
@test.idempotent_id('96eea398-a03c-4c3e-a99e-864392c2ca53')
def test_remove_subport(self):
subport_parent1 = self.create_port(self.create_network())