Merge "Fix internal server error on deleting nodes with allocations"

This commit is contained in:
Zuul 2020-06-24 13:23:17 +00:00 committed by Gerrit Code Review
commit b220d39cc7
3 changed files with 14 additions and 1 deletions

View File

@ -564,7 +564,7 @@ class Connection(api.Connection):
@oslo_db_api.retry_on_deadlock
def destroy_node(self, node_id):
with _session_for_write():
with _session_for_write() as session:
query = model_query(models.Node)
query = add_identity_filter(query, node_id)
@ -573,6 +573,11 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.NodeNotFound(node=node_id)
# Orphan allocation, if any. On the API level this is only allowed
# with maintenance on.
node_ref.allocation_id = None
node_ref.save(session)
# Get node ID, if an UUID was supplied. The ID is
# required for deleting all ports, attached to the node.
if uuidutils.is_uuid_like(node_id):

View File

@ -595,6 +595,8 @@ class DbNodeTestCase(base.DbTestCase):
node = utils.create_test_node()
allocation = utils.create_test_allocation(node_id=node.id)
node = self.dbapi.update_node(node.id,
{'allocation_id': allocation.id})
self.dbapi.destroy_node(node.uuid)
self.assertRaises(exception.AllocationNotFound,

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes deleting nodes with maintenance mode on and an allocation present.
Previously it caused an internal server error. See `story 2007823
<https://storyboard.openstack.org/#!/story/2007823>`_ for details.