Skip to content

Commit 1af9de4

Browse files
committed
Soft delete virtual_interfaces when instance is destroyed
Like the other reference table entries for an instance, we should soft_delete virtual_interfaces when destroying an instance. Failing to do so can lead to archive issues due to the referential constraint. Change-Id: I04355bdec5477b4c144105fea130089fe1ae6772 Closes-Bug: #1823781
1 parent 083eb4b commit 1af9de4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

nova/db/sqlalchemy/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,8 @@ def instance_destroy(context, instance_uuid, constraint=None):
18061806
model_query(context, models.Migration).\
18071807
filter_by(instance_uuid=instance_uuid).\
18081808
soft_delete()
1809+
model_query(context, models.VirtualInterface).filter_by(
1810+
instance_uuid=instance_uuid).soft_delete()
18091811
model_query(context, models.InstanceIdMapping).filter_by(
18101812
uuid=instance_uuid).soft_delete()
18111813
# NOTE(snikitin): We can't use model_query here, because there is no

nova/tests/unit/db/test_db_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,21 @@ def test_delete_migrations_on_instance_destroy(self):
25742574
self.assertTrue(instance.deleted)
25752575
self.assertEqual(0, len(migrations))
25762576

2577+
def test_delete_virtual_interfaces_on_instance_destroy(self):
2578+
# Create the instance.
2579+
ctxt = context.get_admin_context()
2580+
uuid = uuidsentinel.uuid1
2581+
db.instance_create(ctxt, {'uuid': uuid})
2582+
# Create the VirtualInterface.
2583+
db.virtual_interface_create(ctxt, {'instance_uuid': uuid})
2584+
# Make sure the vif is tied to the instance.
2585+
vifs = db.virtual_interface_get_by_instance(ctxt, uuid)
2586+
self.assertEqual(1, len(vifs))
2587+
# Destroy the instance and verify the vif is gone as well.
2588+
db.instance_destroy(ctxt, uuid)
2589+
self.assertEqual(
2590+
0, len(db.virtual_interface_get_by_instance(ctxt, uuid)))
2591+
25772592
def test_instance_update_and_get_original(self):
25782593
instance = self.create_instance_with_args(vm_state='building')
25792594
(old_ref, new_ref) = db.instance_update_and_get_original(self.ctxt,

0 commit comments

Comments
 (0)