Browse Source

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

tags/15.1.0
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
b220d39cc7
3 changed files with 14 additions and 1 deletions
  1. +6
    -1
      ironic/db/sqlalchemy/api.py
  2. +2
    -0
      ironic/tests/unit/db/test_nodes.py
  3. +6
    -0
      releasenotes/notes/allocation-delete-26c7c2f1651759f5.yaml

+ 6
- 1
ironic/db/sqlalchemy/api.py 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):


+ 2
- 0
ironic/tests/unit/db/test_nodes.py 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,


+ 6
- 0
releasenotes/notes/allocation-delete-26c7c2f1651759f5.yaml 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.

Loading…
Cancel
Save