db: Replace use of deprecated API
We were missing a number of users of SQLALchemy APIs that were either changed or removed in 2.0. These were yielding the following errors in 2.0. TypeError: MetaData.__init__() got an unexpected keyword argument 'bind' TypeError: TableClause.insert() got an unexpected keyword argument 'values' TypeError: TableClause.update() got an unexpected keyword argument 'values' AttributeError: 'Engine' object has no attribute 'execute' Resolve these issues. We will fix the test class issue in a follow-up. Change-Id: I8724b0738f097739f55cd8566bb30b7ddbe154d9 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
d7e9a330f0
commit
f71603d695
@ -31,10 +31,23 @@ depends_on = None
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
connection = context.get_bind()
|
connection = context.get_bind()
|
||||||
metadata = MetaData(bind=connection)
|
|
||||||
resource_providers = Table('resource_providers', metadata, autoload=True)
|
meta = MetaData()
|
||||||
query = select(sqlfunc.count()).select_from(resource_providers).where(
|
meta.reflect(bind=connection)
|
||||||
resource_providers.c.root_provider_id == sa.null())
|
resource_providers = Table(
|
||||||
|
'resource_providers',
|
||||||
|
meta,
|
||||||
|
autoload_with=connection,
|
||||||
|
)
|
||||||
|
|
||||||
|
query = select(
|
||||||
|
sqlfunc.count(),
|
||||||
|
).select_from(
|
||||||
|
resource_providers,
|
||||||
|
).where(
|
||||||
|
resource_providers.c.root_provider_id == sa.null()
|
||||||
|
)
|
||||||
|
|
||||||
if connection.scalar(query):
|
if connection.scalar(query):
|
||||||
raise Exception('There is at least one resource provider table '
|
raise Exception('There is at least one resource provider table '
|
||||||
'record which is missing its root provider id. '
|
'record which is missing its root provider id. '
|
||||||
|
@ -31,12 +31,16 @@ depends_on = None
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
connection = context.get_bind()
|
connection = context.get_bind()
|
||||||
metadata = sa.MetaData(bind=connection)
|
|
||||||
consumers = sa.Table('consumers', metadata, autoload=True)
|
meta = sa.MetaData()
|
||||||
allocations = sa.Table('allocations', metadata, autoload=True)
|
meta.reflect(bind=connection)
|
||||||
|
consumers = sa.Table('consumers', meta, autoload_with=connection)
|
||||||
|
allocations = sa.Table('allocations', meta, autoload_with=connection)
|
||||||
|
|
||||||
alloc_to_consumer = sa.outerjoin(
|
alloc_to_consumer = sa.outerjoin(
|
||||||
allocations, consumers,
|
allocations, consumers,
|
||||||
allocations.c.consumer_id == consumers.c.uuid)
|
allocations.c.consumer_id == consumers.c.uuid,
|
||||||
|
)
|
||||||
sel = sa.select(sqlfunc.count())
|
sel = sa.select(sqlfunc.count())
|
||||||
sel = sel.select_from(alloc_to_consumer)
|
sel = sel.select_from(alloc_to_consumer)
|
||||||
sel = sel.where(consumers.c.id.is_(None))
|
sel = sel.where(consumers.c.id.is_(None))
|
||||||
|
@ -177,10 +177,12 @@ class MigrationCheckersMixin(object):
|
|||||||
self.migration_api.upgrade('b4ed3a175331')
|
self.migration_api.upgrade('b4ed3a175331')
|
||||||
# Now insert a resource provider with no root.
|
# Now insert a resource provider with no root.
|
||||||
rps = db_utils.get_table(self.engine, 'resource_providers')
|
rps = db_utils.get_table(self.engine, 'resource_providers')
|
||||||
ins_stmt = rps.insert(values={
|
ins_stmt = rps.insert().values(
|
||||||
'name': 'fake-rp-name', 'uuid': uuids.rp_uuid
|
name='fake-rp-name',
|
||||||
})
|
uuid=uuids.rp_uuid,
|
||||||
rp_id = self.engine.execute(ins_stmt).inserted_primary_key[0]
|
)
|
||||||
|
with self.engine.connect() as conn, conn.begin():
|
||||||
|
rp_id = conn.execute(ins_stmt).inserted_primary_key[0]
|
||||||
# Now run the blocker migration and it should raise an error.
|
# Now run the blocker migration and it should raise an error.
|
||||||
ex = self.assertRaises( # noqa H202
|
ex = self.assertRaises( # noqa H202
|
||||||
Exception, self.migration_api.upgrade, '611cd6dffd7b')
|
Exception, self.migration_api.upgrade, '611cd6dffd7b')
|
||||||
@ -189,10 +191,11 @@ class MigrationCheckersMixin(object):
|
|||||||
'record which is missing its root provider id.',
|
'record which is missing its root provider id.',
|
||||||
str(ex))
|
str(ex))
|
||||||
# Now update the resource provider with a root_provider_id.
|
# Now update the resource provider with a root_provider_id.
|
||||||
update_stmt = rps.update(
|
update_stmt = rps.update().values(
|
||||||
values={'root_provider_id': rp_id}).where(
|
root_provider_id=rp_id,
|
||||||
rps.c.id == rp_id)
|
).where(rps.c.id == rp_id)
|
||||||
self.engine.execute(update_stmt)
|
with self.engine.connect() as conn, conn.begin():
|
||||||
|
conn.execute(update_stmt)
|
||||||
# Re-run the upgrade and it should be OK.
|
# Re-run the upgrade and it should be OK.
|
||||||
self.migration_api.upgrade('611cd6dffd7b')
|
self.migration_api.upgrade('611cd6dffd7b')
|
||||||
|
|
||||||
@ -205,18 +208,23 @@ class MigrationCheckersMixin(object):
|
|||||||
self.migration_api.upgrade('b4ed3a175331')
|
self.migration_api.upgrade('b4ed3a175331')
|
||||||
# Now insert a resource provider to build off
|
# Now insert a resource provider to build off
|
||||||
rps = db_utils.get_table(self.engine, 'resource_providers')
|
rps = db_utils.get_table(self.engine, 'resource_providers')
|
||||||
ins_stmt = rps.insert(values={
|
ins_stmt = rps.insert().values(
|
||||||
'name': 'fake-rp-name', 'uuid': uuids.rp_uuid,
|
name='fake-rp-name',
|
||||||
'root_provider_id': 1
|
uuid=uuids.rp_uuid,
|
||||||
})
|
root_provider_id=1,
|
||||||
rp_id = self.engine.execute(ins_stmt).inserted_primary_key[0]
|
)
|
||||||
|
with self.engine.connect() as conn, conn.begin():
|
||||||
|
rp_id = conn.execute(ins_stmt).inserted_primary_key[0]
|
||||||
# Now insert an allocation
|
# Now insert an allocation
|
||||||
allocations = db_utils.get_table(self.engine, 'allocations')
|
allocations = db_utils.get_table(self.engine, 'allocations')
|
||||||
ins_stmt = allocations.insert(values={
|
ins_stmt = allocations.insert().values(
|
||||||
'resource_provider_id': rp_id, 'resource_class_id': 1,
|
resource_provider_id=rp_id,
|
||||||
'used': 5, 'consumer_id': uuids.consumer1
|
resource_class_id=1,
|
||||||
})
|
used=5,
|
||||||
self.engine.execute(ins_stmt).inserted_primary_key[0]
|
consumer_id=uuids.consumer1,
|
||||||
|
)
|
||||||
|
with self.engine.connect() as conn, conn.begin():
|
||||||
|
conn.execute(ins_stmt).inserted_primary_key[0]
|
||||||
# Now run the blocker migration and it should raise an error.
|
# Now run the blocker migration and it should raise an error.
|
||||||
ex = self.assertRaises( # noqa H202
|
ex = self.assertRaises( # noqa H202
|
||||||
Exception, self.migration_api.upgrade, 'b5c396305c25')
|
Exception, self.migration_api.upgrade, 'b5c396305c25')
|
||||||
@ -226,10 +234,13 @@ class MigrationCheckersMixin(object):
|
|||||||
str(ex))
|
str(ex))
|
||||||
# Add a (faked) consumer record and try again
|
# Add a (faked) consumer record and try again
|
||||||
consumers = db_utils.get_table(self.engine, 'consumers')
|
consumers = db_utils.get_table(self.engine, 'consumers')
|
||||||
ins_stmt = consumers.insert(values={
|
ins_stmt = consumers.insert().values(
|
||||||
'uuid': uuids.consumer1, 'project_id': 1, 'user_id': 1
|
uuid=uuids.consumer1,
|
||||||
})
|
project_id=1,
|
||||||
self.engine.execute(ins_stmt).inserted_primary_key[0]
|
user_id=1,
|
||||||
|
)
|
||||||
|
with self.engine.connect() as conn, conn.begin():
|
||||||
|
conn.execute(ins_stmt).inserted_primary_key[0]
|
||||||
self.migration_api.upgrade('b5c396305c25')
|
self.migration_api.upgrade('b5c396305c25')
|
||||||
|
|
||||||
def test_consumer_types_422ece571366(self):
|
def test_consumer_types_422ece571366(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user