Merge "Delete baremetal interfaces when their parent node is deleted"
This commit is contained in:
commit
1b9b66ba21
@ -108,6 +108,40 @@ class BareMetalNodesTestCase(base.BMDBTestCase):
|
||||
r = db.bm_node_get_all(self.context)
|
||||
self.assertEquals(len(r), 5)
|
||||
|
||||
def test_destroy_with_interfaces(self):
|
||||
self._create_nodes()
|
||||
|
||||
if_a_id = db.bm_interface_create(self.context, self.ids[0],
|
||||
'aa:aa:aa:aa:aa:aa', None, None)
|
||||
if_b_id = db.bm_interface_create(self.context, self.ids[0],
|
||||
'bb:bb:bb:bb:bb:bb', None, None)
|
||||
if_x_id = db.bm_interface_create(self.context, self.ids[1],
|
||||
'11:22:33:44:55:66', None, None)
|
||||
|
||||
db.bm_node_destroy(self.context, self.ids[0])
|
||||
|
||||
self.assertRaises(
|
||||
exception.NovaException,
|
||||
db.bm_interface_get,
|
||||
self.context, if_a_id)
|
||||
|
||||
self.assertRaises(
|
||||
exception.NovaException,
|
||||
db.bm_interface_get,
|
||||
self.context, if_b_id)
|
||||
|
||||
# Another node's interface is not affected
|
||||
if_x = db.bm_interface_get(self.context, if_x_id)
|
||||
self.assertEqual(self.ids[1], if_x['bm_node_id'])
|
||||
|
||||
self.assertRaises(
|
||||
exception.InstanceNotFound,
|
||||
db.bm_node_get,
|
||||
self.context, self.ids[0])
|
||||
|
||||
r = db.bm_node_get_all(self.context)
|
||||
self.assertEquals(len(r), 5)
|
||||
|
||||
def test_find_free(self):
|
||||
self._create_nodes()
|
||||
fn = db.bm_node_find_free(self.context, 'host2')
|
||||
|
@ -182,6 +182,11 @@ def bm_node_set_uuid_safe(context, bm_node_id, values):
|
||||
|
||||
@sqlalchemy_api.require_admin_context
|
||||
def bm_node_destroy(context, bm_node_id):
|
||||
# First, delete all interfaces belonging to the node.
|
||||
# Delete physically since these have unique columns.
|
||||
model_query(context, models.BareMetalInterface, read_deleted="no").\
|
||||
filter_by(bm_node_id=bm_node_id).\
|
||||
delete()
|
||||
model_query(context, models.BareMetalNode).\
|
||||
filter_by(id=bm_node_id).\
|
||||
update({'deleted': True,
|
||||
|
Loading…
Reference in New Issue
Block a user