Resolve portgroup deletion failure

Add a join query and fix ``id``/``uuid`` mix-up.

Closes-Bug: #2093853
Change-Id: Ifc00069b075fed6bdf79bf4104cfdee62bb7b42a
This commit is contained in:
cid 2025-01-13 13:52:10 +01:00
parent 62285e7115
commit 6be6999247
3 changed files with 13 additions and 6 deletions

@ -1276,11 +1276,13 @@ class Connection(api.Connection):
def destroy_portgroup(self, portgroup_id):
def portgroup_not_empty(session):
"""Checks whether the portgroup does not have ports."""
with _session_for_read() as session:
res = session.scalar(
sa.select(
sa.func.count(models.Port.id)
).where(models.Port.portgroup_id == portgroup_id)) != 0
res = session.scalar(
sa.select(
sa.func.count(models.Port.id)
).join(
models.Portgroup,
models.Port.portgroup_id == models.Portgroup.id
).where(models.Port.portgroup_id == portgroup_id)) != 0
return res
with _session_for_write() as session:

@ -285,7 +285,7 @@ class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat):
:raises: PortgroupNotEmpty, PortgroupNotFound
"""
self.dbapi.destroy_portgroup(self.uuid)
self.dbapi.destroy_portgroup(self.id)
self.obj_reset_changes()
# NOTE(xek): We don't want to enable RPC on this call just yet. Remotable

@ -0,0 +1,5 @@
---
fixes:
- |
Fix portgroup deletion failure by resolving id/uuid mix-up and adding a
port-to-portgroup join query.