diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-03 15:07:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-04 16:24:31 -0500 |
commit | 527b1587e102906ab46846099339759deb824fb8 (patch) | |
tree | 970bef456ec0f8037d532f27f579cc69f9a0af68 /keystone | |
parent | 99733f172f0a668a02cdc0d539cc35f59b834be2 (diff) | |
download | keystone-527b1587e102906ab46846099339759deb824fb8.tar.gz |
Use inspect instead of Inspector.from_engine()
SQLAlchemy is likely going to deprecate
Inspector.from_engine() which will start emitting a deprecation
warning in 1.4. Use sqlalchemy.inspect() instead.
Change-Id: I287ba10f2e3308950b9caf6f51f3ee1db29a6448
Diffstat (limited to 'keystone')
4 files changed, 9 insertions, 10 deletions
diff --git a/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py b/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py index fc06605e2..86eaeae3f 100644 --- a/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py +++ b/keystone/common/sql/contract_repo/versions/014_contract_add_domain_id_to_user_table.py @@ -12,7 +12,6 @@ import migrate import sqlalchemy as sql -from sqlalchemy.engine import reflection from keystone.common.sql import upgrades @@ -20,7 +19,7 @@ from keystone.common.sql import upgrades def upgrade(migrate_engine): meta = sql.MetaData() meta.bind = migrate_engine - inspector = reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) user = sql.Table('user', meta, autoload=True) local_user = sql.Table('local_user', meta, autoload=True) diff --git a/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py b/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py index ab5159f78..72a3f315f 100644 --- a/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py +++ b/keystone/common/sql/contract_repo/versions/037_contract_remove_service_and_region_fk_for_registered_limit.py @@ -22,7 +22,7 @@ def upgrade(migrate_engine): service_table = sql.Table('service', meta, autoload=True) region_table = sql.Table('region', meta, autoload=True) - inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) for fk in inspector.get_foreign_keys('registered_limit'): if fk['referred_table'] == 'service': fkey = ForeignKeyConstraint([registered_limit_table.c.service_id], diff --git a/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py b/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py index b5b31e07b..d750bde53 100644 --- a/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py +++ b/keystone/common/sql/contract_repo/versions/047_contract_expand_update_pk_for_unified_limit.py @@ -26,7 +26,7 @@ def upgrade(migrate_engine): if migrate_engine.name != 'sqlite': project_table = sql.Table('project', meta, autoload=True) - inspector = sql.engine.reflection.Inspector.from_engine(migrate_engine) + inspector = sql.inspect(migrate_engine) for fk in inspector.get_foreign_keys('limit'): fkey = migrate.ForeignKeyConstraint( [limit_table.c.project_id], diff --git a/keystone/tests/unit/test_sql_upgrade.py b/keystone/tests/unit/test_sql_upgrade.py index 2e56b8a67..494797b58 100644 --- a/keystone/tests/unit/test_sql_upgrade.py +++ b/keystone/tests/unit/test_sql_upgrade.py @@ -56,8 +56,8 @@ from oslo_log import log from oslo_serialization import jsonutils from oslotest import base as test_base import pytz -from sqlalchemy.engine import reflection import sqlalchemy.exc +from sqlalchemy import inspect from testtools import matchers from keystone.cmd import cli @@ -312,13 +312,13 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin, def does_pk_exist(self, table, pk_column): """Check whether a column is primary key on a table.""" - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) pk_columns = inspector.get_pk_constraint(table)['constrained_columns'] return pk_column in pk_columns def does_fk_exist(self, table, fk_column): - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) for fk in inspector.get_foreign_keys(table): if fk_column in fk['constrained_columns']: return True @@ -333,7 +333,7 @@ class SqlMigrateBase(db_fixtures.OpportunisticDBTestMixin, return index_name in [idx.name for idx in table.indexes] def does_unique_constraint_exist(self, table_name, column_names): - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints(table_name) for c in constraints: if (len(c['column_names']) == 1 and @@ -668,7 +668,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase): def test_add_trust_unique_constraint_upgrade(self): self.upgrade(86) - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints('trust') constraint_names = [constraint['name'] for constraint in constraints] self.assertIn('duplicate_trust_constraint', constraint_names) @@ -701,7 +701,7 @@ class SqlLegacyRepoUpgradeTests(SqlMigrateBase): session = self.sessionmaker() self.assertTableColumns('role', ['id', 'name', 'domain_id', 'extra']) # Check the domain_id has been added to the uniqueness constraint - inspector = reflection.Inspector.from_engine(self.engine) + inspector = inspect(self.engine) constraints = inspector.get_unique_constraints('role') constraint_columns = [ constraint['column_names'] for constraint in constraints |