diff options
author | Stephen Finucane <stephenfin@redhat.com> | 2021-11-12 11:05:37 +0000 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2021-11-15 11:19:46 +0000 |
commit | eac61c5929e52baac59351b52c1ebf4399b2d3c4 (patch) | |
tree | ffef8d3e947f2cd76b9709b15c0b7c07cf1253b5 /nova/tests/unit | |
parent | be4e01c101c7e870e5becaf8627a3eb0067ea428 (diff) | |
download | nova-eac61c5929e52baac59351b52c1ebf4399b2d3c4.tar.gz |
db: Remove use of 'bind' arguments
Resolve the following RemovedIn20Warning warnings:
The MetaData.bind argument is deprecated and will be removed in
SQLAlchemy 2.0.
The ``bind`` argument for schema methods that invoke SQL against an
engine or connection will be required in SQLAlchemy 2.0.
We must retain a couple of workarounds to keep sqlalchemy-migrate happy.
This shouldn't be an issue since this library is not compatible with
SQLAlchemy 2.x and will have to be removed (along with the legacy
migration files themselves) when we eventually support 2.x.
Change-Id: I946b4c7926ba2583b84ab95a1fe7aedc6923d9f8
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'nova/tests/unit')
-rw-r--r-- | nova/tests/unit/db/main/test_api.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/nova/tests/unit/db/main/test_api.py b/nova/tests/unit/db/main/test_api.py index 7d262fd089..c9a9e83154 100644 --- a/nova/tests/unit/db/main/test_api.py +++ b/nova/tests/unit/db/main/test_api.py @@ -5652,7 +5652,7 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): def setUp(self): super(ArchiveTestCase, self).setUp() self.engine = db.get_engine() - self.metadata = sa.MetaData(self.engine) + self.metadata = sa.MetaData() self.conn = self.engine.connect() self.instance_id_mappings = models.InstanceIdMapping.__table__ self.shadow_instance_id_mappings = sqlalchemyutils.get_table( @@ -5684,8 +5684,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): except for specificially named exceptions, are empty. This makes sure that archiving isn't moving unexpected content. """ - metadata = sa.MetaData(bind=self.engine) - metadata.reflect() + metadata = sa.MetaData() + metadata.reflect(bind=self.engine) for table in metadata.tables: if table.startswith("shadow_") and table not in exceptions: rows = self.conn.exec_driver_sql( @@ -5698,8 +5698,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): Shadow tables should have an identical schema to the main table. """ - metadata = sa.MetaData(bind=self.engine) - metadata.reflect() + metadata = sa.MetaData() + metadata.reflect(bind=self.engine) for table_name in metadata.tables: # some tables don't have shadow tables so skip these if table_name in [ @@ -5942,7 +5942,9 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual(len(rows), 0) # Archive 2 rows db._archive_deleted_rows_for_table( - self.metadata, tablename, max_rows=2, before=None, task_log=False) + self.metadata, self.engine, tablename, max_rows=2, before=None, + task_log=False, + ) # Verify we have 4 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 4) @@ -5951,7 +5953,9 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual(len(rows), 2) # Archive 2 more rows db._archive_deleted_rows_for_table( - self.metadata, tablename, max_rows=2, before=None, task_log=False) + self.metadata, self.engine, tablename, max_rows=2, before=None, + task_log=False, + ) # Verify we have 2 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 2) @@ -5960,7 +5964,9 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual(len(rows), 4) # Try to archive more, but there are no deleted rows left. db._archive_deleted_rows_for_table( - self.metadata, tablename, max_rows=2, before=None, task_log=False) + self.metadata, self.engine, tablename, max_rows=2, before=None, + task_log=False, + ) # Verify we still have 2 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 2) @@ -6019,8 +6025,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): # Archiving instances should result in migrations related to the # instances also being archived. num = db._archive_deleted_rows_for_table( - self.metadata, "instances", max_rows=None, before=None, - task_log=False) + self.metadata, self.engine, "instances", max_rows=None, + before=None, task_log=False) self.assertEqual(1, num[0]) self._assert_shadow_tables_empty_except( 'shadow_instances', @@ -6386,7 +6392,8 @@ class RetryOnDeadlockTestCase(test.TestCase): class TestSqlalchemyTypesRepr( - test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase): + test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase, +): def setUp(self): # NOTE(sdague): the oslo_db base test case completely @@ -6397,15 +6404,15 @@ class TestSqlalchemyTypesRepr( super(TestSqlalchemyTypesRepr, self).setUp() self.engine = enginefacade.writer.get_engine() - meta = sa.MetaData(bind=self.engine) + meta = sa.MetaData() self.table = sa.Table( 'cidr_tbl', meta, sa.Column('id', sa.Integer, primary_key=True), sa.Column('addr', col_types.CIDR()) ) - self.table.create() - self.addCleanup(meta.drop_all) + meta.create_all(self.engine) + self.addCleanup(meta.drop_all, self.engine) def test_cidr_repr(self): addrs = [('192.168.3.0/24', '192.168.3.0/24'), |