Reuse _set_instances_share_data for replicas.

Replicas are just special instances after all, no need for
duplicate code and missing on improvements like exception handling
on NotFound error.

Change-Id: I31fabebc6a60814a4cfc04ae0deb49dcb66cab0f
Closes-Bug: #1923566
This commit is contained in:
Maurice Escher 2021-04-13 09:36:48 +02:00
parent ad4315eb36
commit 29a943fde7
No known key found for this signature in database
GPG Key ID: CC56DEC23EE46750
2 changed files with 10 additions and 16 deletions

View File

@ -1822,17 +1822,6 @@ def _share_replica_get_with_filters(context, share_id=None, replica_id=None,
return query
def _set_replica_share_data(context, replicas, session):
if replicas and not isinstance(replicas, list):
replicas = [replicas]
for replica in replicas:
parent_share = share_get(context, replica['share_id'], session=session)
replica.set_share_data(parent_share)
return replicas
@require_context
def share_replicas_get_all(context, with_share_data=False,
with_share_server=True, session=None):
@ -1843,7 +1832,7 @@ def share_replicas_get_all(context, with_share_data=False,
context, with_share_server=with_share_server, session=session).all()
if with_share_data:
result = _set_replica_share_data(context, result, session)
result = _set_instances_share_data(context, result, session)
return result
@ -1860,7 +1849,7 @@ def share_replicas_get_all_by_share(context, share_id,
share_id=share_id, session=session).all()
if with_share_data:
result = _set_replica_share_data(context, result, session)
result = _set_instances_share_data(context, result, session)
return result
@ -1879,7 +1868,7 @@ def share_replicas_get_available_active_replica(context, share_id,
status=constants.STATUS_AVAILABLE, session=session).first()
if result and with_share_data:
result = _set_replica_share_data(context, result, session)[0]
result = _set_instances_share_data(context, result, session)[0]
return result
@ -1898,7 +1887,7 @@ def share_replica_get(context, replica_id, with_share_data=False,
raise exception.ShareReplicaNotFound(replica_id=replica_id)
if with_share_data:
result = _set_replica_share_data(context, result, session)[0]
result = _set_instances_share_data(context, result, session)[0]
return result
@ -1917,7 +1906,7 @@ def share_replica_update(context, share_replica_id, values,
context, share_replica_id, values, session=session)
if with_share_data:
updated_share_replica = _set_replica_share_data(
updated_share_replica = _set_instances_share_data(
context, updated_share_replica, session)[0]
return updated_share_replica

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed NotFound error in share replica periodic tasks. It could happen that
the parent share of the replica that was being worked on had already been
deleted.