From 3d869bca2691abfca77257ae971ccf40423f2c41 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Fri, 23 Jun 2023 16:02:40 -0700 Subject: [PATCH] Fix test_migrations with firmware information. Two issues existed in our test migrations: 1) We took a sqlalchemy orm-ey object and returned it. The handler closed but the connection stays open. 2) In the test we mocked data, saved data, checked data, but there is a constraint that would prevent nodes from being deleted before the firmware_information data. Also fixes some additional assignment of object value pattern of usage elsewhere in the test migrations as pointed out in code review. Co-Authored-By: Jay Faulkner Change-Id: I91429f33ce01f40ecd665b2f76b27a162354bc6f --- .../unit/db/sqlalchemy/test_migrations.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ironic/tests/unit/db/sqlalchemy/test_migrations.py b/ironic/tests/unit/db/sqlalchemy/test_migrations.py index fa6a86c3fa..a1ffbdfb6c 100644 --- a/ironic/tests/unit/db/sqlalchemy/test_migrations.py +++ b/ironic/tests/unit/db/sqlalchemy/test_migrations.py @@ -719,7 +719,9 @@ class MigrationCheckersMixin(object): models.Node.uuid == data['uuid'] ) node = connection.execute(node_stmt).first() - data['id'] = node.id + # WARNING: Always copy, never directly return a db object or + # piece of a db object. It is a sqlalchemy thing. + data['id'] = int(node.id) return data def _check_b4130a7fc904(self, engine, data): @@ -755,7 +757,9 @@ class MigrationCheckersMixin(object): models.Node.id ).where(models.Node.uuid == data['uuid']) node = connection.execute(node_stmt).first() - data['id'] = node.id + # WARNING: Always copy, never directly return a db object or + # piece of a db object. It is a sqlalchemy thing. + data['id'] = int(node.id) return data def _check_82c315d60161(self, engine, data): @@ -1274,7 +1278,9 @@ class MigrationCheckersMixin(object): models.Node.id ).where(models.Node.uuid == data['uuid']) node = connection.execute(node_stmt).first() - data['id'] = node.id + # WARNING: Always copy, never directly return a db object or + # piece of a db object. It is a sqlalchemy thing. + data['id'] = int(node.id) return data @@ -1324,6 +1330,12 @@ class MigrationCheckersMixin(object): ) fw_component = connection.execute(fw_cmp_stmt).first() self.assertEqual('v1.0.0', fw_component['initial_version']) + del_stmt = ( + sqlalchemy.delete( + models.FirmwareInformation + ).where(models.FirmwareInformation.node_id == data['id']) + ) + connection.execute(del_stmt) def test_upgrade_and_version(self): with patch_with_engine(self.engine):