summaryrefslogtreecommitdiff
path: root/nova/cmd
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-08-17 14:48:32 +0100
committerStephen Finucane <stephenfin@redhat.com>2021-11-12 09:58:16 +0000
commitcd3e5a23c948be1239bb662f1b35c81fc79f59e3 (patch)
tree54277614acd00ca4bdcdf100b2df5585638933c6 /nova/cmd
parent52bd1e51d675a1eb1226a45e3e952b17bda712a2 (diff)
downloadnova-cd3e5a23c948be1239bb662f1b35c81fc79f59e3.tar.gz
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 <stephenfin@redhat.com>
Diffstat (limited to 'nova/cmd')
-rw-r--r--nova/cmd/status.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/nova/cmd/status.py b/nova/cmd/status.py
index f95a1a4a93..082116201b 100644
--- a/nova/cmd/status.py
+++ b/nova/cmd/status.py
@@ -87,10 +87,15 @@ class UpgradeCommands(upgradecheck.UpgradeCommands):
# table, or by only counting compute nodes with a service version of at
# least 15 which was the highest service version when Newton was
# released.
- meta = sa.MetaData(bind=main_db_api.get_engine(context=context))
- compute_nodes = sa.Table('compute_nodes', meta, autoload=True)
- return sa.select([sqlfunc.count()]).select_from(compute_nodes).where(
- compute_nodes.c.deleted == 0).scalar()
+ meta = sa.MetaData()
+ engine = main_db_api.get_engine(context=context)
+ compute_nodes = sa.Table('compute_nodes', meta, autoload_with=engine)
+ with engine.connect() as conn:
+ return conn.execute(
+ sa.select(sqlfunc.count()).select_from(compute_nodes).where(
+ compute_nodes.c.deleted == 0
+ )
+ ).scalars().first()
def _check_cellsv2(self):
"""Checks to see if cells v2 has been setup.
@@ -104,7 +109,7 @@ class UpgradeCommands(upgradecheck.UpgradeCommands):
for compute nodes if there are no host mappings on a fresh install.
"""
meta = sa.MetaData()
- meta.bind = api_db_api.get_engine()
+ engine = api_db_api.get_engine()
cell_mappings = self._get_cell_mappings()
count = len(cell_mappings)
@@ -123,9 +128,13 @@ class UpgradeCommands(upgradecheck.UpgradeCommands):
'retry.')
return upgradecheck.Result(upgradecheck.Code.FAILURE, msg)
- host_mappings = sa.Table('host_mappings', meta, autoload=True)
- count = sa.select([sqlfunc.count()]).select_from(host_mappings)\
- .scalar()
+ host_mappings = sa.Table('host_mappings', meta, autoload_with=engine)
+
+ with engine.connect() as conn:
+ count = conn.execute(
+ sa.select(sqlfunc.count()).select_from(host_mappings)
+ ).scalars().first()
+
if count == 0:
# This may be a fresh install in which case there may not be any
# compute_nodes in the cell database if the nova-compute service