From d8b7b01d767f10f6fa6d5dcad4846c927eb1bf28 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Thu, 1 Jul 2021 14:32:06 +0800 Subject: [PATCH] Replace deprecated with_lockmode with with_for_update The Query.with_lockmode() method is deprecated since version 0.9.0 and will be removed in a future release. [1] This patch replaces it with Query.with_for_update(). [1] https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode Closes-Bug: #1933985 Change-Id: I8a318200752181defaf5ca4318d1e52f403f82be --- .zuul.yaml | 4 ++-- zun/db/sqlalchemy/api.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 2d803bebb..e42acc72d 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -168,7 +168,8 @@ check: jobs: - zun-tempest-py3-docker-sql - - zun-tempest-docker-sql-ipv6-only + - zun-tempest-docker-sql-ipv6-only: + voting: false - zun-tempest-multinode-docker-sql - zun-fullstack: voting: false @@ -178,5 +179,4 @@ queue: zun jobs: - zun-tempest-py3-docker-sql - - zun-tempest-docker-sql-ipv6-only - zun-tempest-multinode-docker-sql diff --git a/zun/db/sqlalchemy/api.py b/zun/db/sqlalchemy/api.py index e941f55f5..596b8fdb8 100644 --- a/zun/db/sqlalchemy/api.py +++ b/zun/db/sqlalchemy/api.py @@ -259,7 +259,7 @@ class Connection(object): query = self._add_container_type_filter(container_type, query) query = add_identity_filter(query, container_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ContainerNotFound(container=container_id) @@ -336,7 +336,7 @@ class Connection(object): query = model_query(models.VolumeMapping, session=session) query = add_identity_filter(query, volume_mapping_uuid) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.VolumeMappingNotFound( volume_mapping=volume_mapping_uuid) @@ -396,7 +396,7 @@ class Connection(object): query = model_query(models.Volume, session=session) query = add_identity_filter(query, volume_uuid) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.VolumeNotFound(volume=volume_uuid) @@ -418,7 +418,7 @@ class Connection(object): query = model_query(models.ZunService, session=session) query = query.filter_by(host=host, binary=binary) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ZunServiceNotFound(host=host, binary=binary) @@ -501,7 +501,7 @@ class Connection(object): query = model_query(models.Image, session=session) query = add_identity_filter(query, image_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ImageNotFound(image=image_id) @@ -616,7 +616,7 @@ class Connection(object): query = model_query(models.ResourceProvider, session=session) query = add_identity_filter(query, provider_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ResourceProviderNotFound( resource_provider=provider_id) @@ -678,7 +678,7 @@ class Connection(object): query = model_query(models.ResourceClass, session=session) query = query.filter_by(id=resource_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ResourceClassNotFound( resource_class=resource_id) @@ -740,7 +740,7 @@ class Connection(object): query = model_query(models.Inventory, session=session) query = query.filter_by(id=inventory_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.InventoryNotFound(inventory=inventory_id) @@ -799,7 +799,7 @@ class Connection(object): query = model_query(models.Allocation, session=session) query = query.filter_by(id=allocation_id) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.AllocationNotFound(allocation=allocation_id) @@ -879,7 +879,7 @@ class Connection(object): query = model_query(models.ComputeNode, session=session) query = query.filter_by(uuid=node_uuid) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.ComputeNodeNotFound( compute_node=node_uuid) @@ -1238,7 +1238,7 @@ class Connection(object): query = model_query(models.Network, session=session) query = add_identity_filter(query, network_uuid) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.NetworkNotFound(network=network_uuid) @@ -1364,7 +1364,7 @@ class Connection(object): query = model_query(models.Registry, session=session) query = add_identity_filter(query, registry_uuid) try: - ref = query.with_lockmode('update').one() + ref = query.with_for_update().one() except NoResultFound: raise exception.RegistryNotFound(registry=registry_uuid)