diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 0ad7460be3..05397b26f7 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -2697,7 +2697,7 @@ class ConductorManager(base_manager.BaseConductorManager): # any Port associated to the PortGroup, otherwise # PortgroupNotEmpty exception is raised. associated_ports = self.dbapi.get_ports_by_portgroup_id( - portgroup_uuid) + portgroup_obj.id) if associated_ports: action = _("Portgroup %(portgroup)s can not be associated " "with node %(node)s because there are ports " diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index 166683b35e..3a30529e74 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -5373,7 +5373,7 @@ class UpdatePortgroupTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.service.update_portgroup(self.context, portgroup) portgroup.refresh() self.assertEqual(update_node.id, portgroup.node_id) - mock_get_ports.assert_called_once_with(portgroup.uuid) + mock_get_ports.assert_called_once_with(portgroup.id) mock_val.assert_called_once_with(mock.ANY, mock.ANY) mock_pgc.assert_called_once_with(mock.ANY, mock.ANY, portgroup) @@ -5399,7 +5399,7 @@ class UpdatePortgroupTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.service.update_portgroup(self.context, portgroup) portgroup.refresh() self.assertEqual(update_node.id, portgroup.node_id) - mock_get_ports.assert_called_once_with(portgroup.uuid) + mock_get_ports.assert_called_once_with(portgroup.id) mock_val.assert_called_once_with(mock.ANY, mock.ANY) mock_pgc.assert_called_once_with(mock.ANY, mock.ANY, portgroup) @@ -5425,7 +5425,7 @@ class UpdatePortgroupTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.service.update_portgroup(self.context, portgroup) portgroup.refresh() self.assertEqual(update_node.id, portgroup.node_id) - mock_get_ports.assert_called_once_with(portgroup.uuid) + mock_get_ports.assert_called_once_with(portgroup.id) mock_val.assert_called_once_with(mock.ANY, mock.ANY) mock_pgc.assert_called_once_with(mock.ANY, mock.ANY, portgroup) @@ -5454,7 +5454,7 @@ class UpdatePortgroupTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.assertEqual(exception.PortgroupNotEmpty, exc.exc_info[0]) portgroup.refresh() self.assertEqual(old_node_id, portgroup.node_id) - mock_get_ports.assert_called_once_with(portgroup.uuid) + mock_get_ports.assert_called_once_with(portgroup.id) self.assertFalse(mock_val.called) self.assertFalse(mock_pgc.called) diff --git a/releasenotes/notes/fix-portgroup-update-logic-156ebe0ef9bc2d58.yaml b/releasenotes/notes/fix-portgroup-update-logic-156ebe0ef9bc2d58.yaml new file mode 100644 index 0000000000..70dbac8025 --- /dev/null +++ b/releasenotes/notes/fix-portgroup-update-logic-156ebe0ef9bc2d58.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes an issue around handling of portgroup updates where the associated + node ID is changed. While a rare operation, it exists as a capability + and a bug existed from the wrong ID value being used to query the + database. The correct ID value is now utilized.