Skip to content

Commit cd3e5a2

Browse files
committed
db: Replace use of Executable.scalar(), Executable.execute()
Resolve the following RemovedIn20Warning warnings: The Executable.scalar() method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. Scalar execution in SQLAlchemy 2.0 is performed by the Connection.scalar() method of Connection, or in the ORM by the Session.scalar() method of Session. The Executable.execute() method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0. All statement execution in SQLAlchemy 2.0 is performed by the Connection.execute() method of Connection, or in the ORM by the Session.execute() method of Session. Note that while we're resolving these issues, we also head off other issues that are currently ignored but will ultimately need to be resolved such as switching to the modern calling style of 'select()' Change-Id: Idebcba02a6704df21e5520fdbf60296b8187e79c Signed-off-by: Stephen Finucane <[email protected]>
1 parent 52bd1e5 commit cd3e5a2

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

nova/cmd/status.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ def _count_compute_nodes(self, context=None):
8787
# table, or by only counting compute nodes with a service version of at
8888
# least 15 which was the highest service version when Newton was
8989
# released.
90-
meta = sa.MetaData(bind=main_db_api.get_engine(context=context))
91-
compute_nodes = sa.Table('compute_nodes', meta, autoload=True)
92-
return sa.select([sqlfunc.count()]).select_from(compute_nodes).where(
93-
compute_nodes.c.deleted == 0).scalar()
90+
meta = sa.MetaData()
91+
engine = main_db_api.get_engine(context=context)
92+
compute_nodes = sa.Table('compute_nodes', meta, autoload_with=engine)
93+
with engine.connect() as conn:
94+
return conn.execute(
95+
sa.select(sqlfunc.count()).select_from(compute_nodes).where(
96+
compute_nodes.c.deleted == 0
97+
)
98+
).scalars().first()
9499

95100
def _check_cellsv2(self):
96101
"""Checks to see if cells v2 has been setup.
@@ -104,7 +109,7 @@ def _check_cellsv2(self):
104109
for compute nodes if there are no host mappings on a fresh install.
105110
"""
106111
meta = sa.MetaData()
107-
meta.bind = api_db_api.get_engine()
112+
engine = api_db_api.get_engine()
108113

109114
cell_mappings = self._get_cell_mappings()
110115
count = len(cell_mappings)
@@ -123,9 +128,13 @@ def _check_cellsv2(self):
123128
'retry.')
124129
return upgradecheck.Result(upgradecheck.Code.FAILURE, msg)
125130

126-
host_mappings = sa.Table('host_mappings', meta, autoload=True)
127-
count = sa.select([sqlfunc.count()]).select_from(host_mappings)\
128-
.scalar()
131+
host_mappings = sa.Table('host_mappings', meta, autoload_with=engine)
132+
133+
with engine.connect() as conn:
134+
count = conn.execute(
135+
sa.select(sqlfunc.count()).select_from(host_mappings)
136+
).scalars().first()
137+
129138
if count == 0:
130139
# This may be a fresh install in which case there may not be any
131140
# compute_nodes in the cell database if the nova-compute service

nova/tests/fixtures/nova.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -925,18 +925,6 @@ def setUp(self):
925925
message=r'Using strings to indicate relationship names .*',
926926
category=sqla_exc.SADeprecationWarning)
927927

928-
warnings.filterwarnings(
929-
'ignore',
930-
module='nova',
931-
message=r'The Executable.execute\(\) method is considered .*',
932-
category=sqla_exc.SADeprecationWarning)
933-
934-
warnings.filterwarnings(
935-
'ignore',
936-
module='nova',
937-
message=r'The Executable.scalar\(\) method is considered .*',
938-
category=sqla_exc.SADeprecationWarning)
939-
940928
warnings.filterwarnings(
941929
'ignore',
942930
module='nova',

0 commit comments

Comments
 (0)