Skip to content

Commit

Permalink
Rollback quota when share network create API fails.
Browse files Browse the repository at this point in the history
During share network create API, if failure occurs quota is not rolled
back and its usable only after quota reservations timed out (waiting
conf.reservation_expire seconds).

Closes-bug: #1975483
Change-Id: I3de8f5bfa6ac4580da9b1012caa25657a6df71ec
(cherry picked from commit 8c854a1)
  • Loading branch information
kpawar89 authored and chuan137 committed Aug 22, 2022
1 parent 0215f0f commit bddb4dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion manila/api/v2/share_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def _consumed(name):
share_network = db_api.share_network_create(
context, share_network_values)
except db_exception.DBError as e:
QUOTAS.rollback(context, reservations)
LOG.exception(e)
msg = "Could not create share network."
raise exc.HTTPInternalServerError(explanation=msg)
Expand All @@ -397,7 +398,8 @@ def _consumed(name):
context, share_network_subnet_values)
except db_exception.DBError:
db_api.share_network_delete(context, share_network['id'])
msg = _('Could not create share network.')
QUOTAS.rollback(context, reservations)
msg = _('Could not create share network subnet.')
raise exc.HTTPInternalServerError(explanation=msg)

QUOTAS.commit(context, reservations)
Expand Down
17 changes: 17 additions & 0 deletions manila/tests/api/v2/test_share_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,29 @@ def test_create_az_not_found(self, data):
req,
body)

def test_create_error_on_network_creation(self):
self.mock_object(share_networks.QUOTAS, 'reserve',
mock.Mock(return_value='fake_reservation'))
self.mock_object(share_networks.QUOTAS, 'rollback')
self.mock_object(db_api, 'share_network_create',
mock.Mock(side_effect=db_exception.DBError()))

self.assertRaises(webob_exc.HTTPInternalServerError,
self.controller.create,
self.req,
self.body)
self.assertTrue(share_networks.QUOTAS.rollback.called)

def test_create_error_on_subnet_creation(self):
data = {
'neutron_net_id': 'fake',
'neutron_subnet_id': 'fake',
'id': fake_share_network['id']
}
subnet_data = copy.deepcopy(data)
self.mock_object(share_networks.QUOTAS, 'reserve',
mock.Mock(return_value='fake_reservation'))
self.mock_object(share_networks.QUOTAS, 'rollback')
self.mock_object(db_api, 'share_network_create',
mock.Mock(return_value=fake_share_network))
self.mock_object(db_api, 'share_network_subnet_create',
Expand All @@ -302,6 +318,7 @@ def test_create_error_on_subnet_creation(self):
self.context, subnet_data)
db_api.share_network_delete.assert_called_once_with(
self.context, fake_share_network['id'])
self.assertTrue(share_networks.QUOTAS.rollback.called)

def test_delete_nominal(self):
share_nw = fake_share_network.copy()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
During share network create API, if either share network or share network
subnet db creation fails, manila raises an exception. However quota is not
rolled back and its usable only after quota reservations timed out (waiting
conf.reservation_expire seconds). Fixed by introducing immediate quota
rollback in case any db create api fails.

0 comments on commit bddb4dc

Please sign in to comment.