Check share network for share groups before deletion

Share network subnets were not checking for the existence of share
groups while processing a delete request. Then, if a share network
had a share server that was tied to a share group, it would end up
deleting the share server, leaving the share group orphan. When we
triggered the deletion of the share group, it would fail, as the
share server was not known to Manila anymore.

Fix that issue by adding an extra validation step during the share
network subnet delete API.

Closes-Bug: #2004212
Depends-On: https://review.opendev.org/c/openstack/manila-tempest-plugin/+/875981
Change-Id: I563bf925523fa44689c83f432ce5a460276afef7
This commit is contained in:
silvacarloss 2023-01-31 13:22:08 -03:00 committed by Carlos Eduardo
parent 4042d70273
commit 2b52056721
3 changed files with 21 additions and 3 deletions

View File

@ -89,6 +89,15 @@ class ShareNetworkSubnetController(wsgi.Controller):
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
share_groups = db_api.share_group_get_all_by_share_server(
context, share_server['id'])
if share_groups:
msg = _("Cannot delete share network subnet %(id)s, it has "
"one or more share groups.") % {
'id': share_network_subnet_id}
LOG.error(msg)
raise exc.HTTPConflict(explanation=msg)
# NOTE(silvacarlose): Do not allow the deletion of any share server
# if any of them has the flag is_auto_deletable = False
if not self._all_share_servers_are_auto_deletable(

View File

@ -1094,7 +1094,9 @@ class ShareServer(BASE, ManilaBase):
'ShareInstance.deleted == "False")')
share_groups = orm.relationship(
"ShareGroup", backref='share_server', primaryjoin='and_('
"ShareGroup",
backref='share_server',
primaryjoin='and_('
'ShareServer.id == ShareGroup.share_server_id,'
'ShareGroup.deleted == "False")')

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixed an issue that allowed share network subnets to be deleted when they
were still related to a share group. An exception will now be raised when
Manila identify such existing relationship. For more details, please refer
to `Launchpad Bug 2004212 <https://bugs.launchpad.net/manila/+bug/2004212>`_.