CI: DB: Don't return inside of node get wrappers
Previously, we did query object handlers with model_query where we woudl then return the handler, however that was problematic because we returned ORM objects. Now we have selects, but the data has to be extrated to a set before we close out the reader session with the database. Returning the overall object means that the call seems to sometimes not completely execute on newer python versions in unit tests, which create unit test failures. We now hold off the database query and operation to a variable, exit the reader, and return the variable. Change-Id: I6ae9e4442bcb473ab5ccff6e167bf61f3daa0f7e
This commit is contained in:
parent
ce5183bfde
commit
4beeef777f
@ -763,31 +763,34 @@ class Connection(api.Connection):
|
||||
try:
|
||||
query = _get_node_select()
|
||||
with _session_for_read() as session:
|
||||
return session.scalars(
|
||||
res = session.scalars(
|
||||
query.filter_by(id=node_id).limit(1)
|
||||
).unique().one()
|
||||
except NoResultFound:
|
||||
raise exception.NodeNotFound(node=node_id)
|
||||
return res
|
||||
|
||||
def get_node_by_uuid(self, node_uuid):
|
||||
try:
|
||||
query = _get_node_select()
|
||||
with _session_for_read() as session:
|
||||
return session.scalars(
|
||||
res = session.scalars(
|
||||
query.filter_by(uuid=node_uuid).limit(1)
|
||||
).unique().one()
|
||||
except NoResultFound:
|
||||
raise exception.NodeNotFound(node=node_uuid)
|
||||
return res
|
||||
|
||||
def get_node_by_name(self, node_name):
|
||||
try:
|
||||
query = _get_node_select()
|
||||
with _session_for_read() as session:
|
||||
return session.scalars(
|
||||
res = session.scalars(
|
||||
query.filter_by(name=node_name).limit(1)
|
||||
).unique().one()
|
||||
except NoResultFound:
|
||||
raise exception.NodeNotFound(node=node_name)
|
||||
return res
|
||||
|
||||
def get_node_by_instance(self, instance):
|
||||
if not uuidutils.is_uuid_like(instance):
|
||||
@ -796,11 +799,12 @@ class Connection(api.Connection):
|
||||
try:
|
||||
query = _get_node_select()
|
||||
with _session_for_read() as session:
|
||||
return session.scalars(
|
||||
res = session.scalars(
|
||||
query.filter_by(instance_uuid=instance).limit(1)
|
||||
).unique().one()
|
||||
except NoResultFound:
|
||||
raise exception.InstanceNotFound(instance_uuid=instance)
|
||||
return res
|
||||
|
||||
@oslo_db_api.retry_on_deadlock
|
||||
def destroy_node(self, node_id):
|
||||
|
Loading…
x
Reference in New Issue
Block a user