From 7b7d18e14243c82c20b49f134a5a007f5f21fcdd Mon Sep 17 00:00:00 2001 From: Maurice Escher Date: Fri, 16 Apr 2021 15:26:20 +0200 Subject: [PATCH] early return for _share_replica_update() if there is no active replica If the parent share of the replica has no active replica, this is an error situation where _share_replica_update() simply returns and logs a warning if the replica being acted on has not been already in error state itself before. Change-Id: I9bdbbaafba413fa4b2a783130fd58a4b6c2cea4b Partial-Bug: #1924230 --- manila/share/manager.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/manila/share/manager.py b/manila/share/manager.py index e64c34c411..a45e082b07 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -2652,9 +2652,22 @@ class ShareManager(manager.SchedulerDependentManager): with_share_data=True, with_share_server=True) ) - _active_replica = [x for x in replica_list - if x['replica_state'] == - constants.REPLICA_STATE_ACTIVE][0] + _active_replica = next((x for x in replica_list + if x['replica_state'] == + constants.REPLICA_STATE_ACTIVE), None) + + if _active_replica is None: + if share_replica['replica_state'] != constants.STATUS_ERROR: + # only log warning if replica_state was not already in error + msg = (("Replica parent share %(id)s has no active " + "replica.") % {'id': share_replica['share_id']}) + LOG.warning(msg) + self.db.share_replica_update(context, share_replica['id'], + {'replica_state': + constants.STATUS_ERROR}) + # without a related active replica, we cannot act on any + # non-active replica + return # Get snapshots for the share. share_snapshots = self.db.share_snapshot_get_all_for_share(