Fix internal server error on deleting nodes with allocations
We allow deleting allocated nodes if maintenance is True, but it fails with HTTP 500 because of a foreign constraint on the nodes table. Story: #2007823 Task: #40102 Change-Id: I7a689c8c403b613fca412fa70e31df40cce8ad95
This commit is contained in:
parent
df439697ae
commit
1d84df93d1
@ -564,7 +564,7 @@ class Connection(api.Connection):
|
|||||||
|
|
||||||
@oslo_db_api.retry_on_deadlock
|
@oslo_db_api.retry_on_deadlock
|
||||||
def destroy_node(self, node_id):
|
def destroy_node(self, node_id):
|
||||||
with _session_for_write():
|
with _session_for_write() as session:
|
||||||
query = model_query(models.Node)
|
query = model_query(models.Node)
|
||||||
query = add_identity_filter(query, node_id)
|
query = add_identity_filter(query, node_id)
|
||||||
|
|
||||||
@ -573,6 +573,11 @@ class Connection(api.Connection):
|
|||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
raise exception.NodeNotFound(node=node_id)
|
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
|
# Get node ID, if an UUID was supplied. The ID is
|
||||||
# required for deleting all ports, attached to the node.
|
# required for deleting all ports, attached to the node.
|
||||||
if uuidutils.is_uuid_like(node_id):
|
if uuidutils.is_uuid_like(node_id):
|
||||||
|
@ -595,6 +595,8 @@ class DbNodeTestCase(base.DbTestCase):
|
|||||||
node = utils.create_test_node()
|
node = utils.create_test_node()
|
||||||
|
|
||||||
allocation = utils.create_test_allocation(node_id=node.id)
|
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.dbapi.destroy_node(node.uuid)
|
||||||
self.assertRaises(exception.AllocationNotFound,
|
self.assertRaises(exception.AllocationNotFound,
|
||||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user