Browse Source

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
(cherry picked from commit 29a943fde7)
changes/04/786904/1
Maurice Escher 5 months ago
committed by Goutham Pacha Ravi
parent
commit
5bd8e46da5
  1. 21
      manila/db/sqlalchemy/api.py
  2. 5
      releasenotes/notes/bug-1923566-fix-notfound-replica-parent-share-d8e50659c02b941a.yaml

21
manila/db/sqlalchemy/api.py

@ -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

5
releasenotes/notes/bug-1923566-fix-notfound-replica-parent-share-d8e50659c02b941a.yaml

@ -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.
Loading…
Cancel
Save