From cd767dd468fd7c99dc24e7e54262be4e3ba9aaa9 Mon Sep 17 00:00:00 2001 From: Kiran Pawar Date: Tue, 26 Sep 2023 13:17:44 +0000 Subject: [PATCH] Delete share network subnet during network deletion Share network subnet is deleted during share network deletion which was missing earlier causing lots of stale db entries. Change-Id: Idb58b4ca389cfb1aaf8f9f1f8aa2fd15979c4872 Closes-bug: #2037422 --- manila/db/sqlalchemy/api.py | 2 ++ manila/tests/db/sqlalchemy/test_api.py | 18 ++++++++++++++++++ ...t-on-network-deletion-b28b42ce4a42b554.yaml | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 releasenotes/notes/bug-2037422-delete-share-network-subnet-on-network-deletion-b28b42ce4a42b554.yaml diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index cbd46cedfd..a2de8a21a6 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -4679,6 +4679,8 @@ def share_network_create(context, values): @context_manager.writer def share_network_delete(context, id): network_ref = _share_network_get(context, id) + for subnet in network_ref['share_network_subnets']: + share_network_subnet_delete(context, subnet['id']) network_ref.soft_delete(session=context.session) diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index 7c2685761c..5f0539afdd 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -2738,6 +2738,24 @@ class ShareNetworkDatabaseAPITestCase(BaseDatabaseAPITestCase): self.fake_context, self.share_nw_dict['id']) + @ddt.data([{'id': 'fake_id_1', 'availability_zone_id': 'None'}], + [{'id': 'fake_id_2', 'availability_zone_id': 'None'}, + {'id': 'fake_id_3', 'availability_zone_id': 'fake_az_id'}]) + def test_delete_with_subnets(self, subnets): + db_api.share_network_create(self.fake_context, self.share_nw_dict) + + for subnet in subnets: + subnet['share_network_id'] = self.share_nw_dict['id'] + db_api.share_network_subnet_create(self.fake_context, subnet) + + db_api.share_network_delete(self.fake_context, + self.share_nw_dict['id']) + + self.assertRaises(exception.ShareNetworkSubnetNotFound, + db_api.share_network_subnet_get, + self.fake_context, + subnets[0]['id']) + def test_delete_not_found(self): self.assertRaises(exception.ShareNetworkNotFound, db_api.share_network_delete, diff --git a/releasenotes/notes/bug-2037422-delete-share-network-subnet-on-network-deletion-b28b42ce4a42b554.yaml b/releasenotes/notes/bug-2037422-delete-share-network-subnet-on-network-deletion-b28b42ce4a42b554.yaml new file mode 100644 index 0000000000..e27a9d5f35 --- /dev/null +++ b/releasenotes/notes/bug-2037422-delete-share-network-subnet-on-network-deletion-b28b42ce4a42b554.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Now, default share network subnet is deleted when share network is deleted, + in case it is the only subnet present in share network. Please refer to the + `Launchpad bug #2037422 `_ + for more details.