Merge "Update quota usages correctly in manage share operation"
This commit is contained in:
commit
2a9879479f
@ -1575,10 +1575,12 @@ class ShareManager(manager.SchedulerDependentManager):
|
|||||||
msg = _("Driver cannot calculate share size.")
|
msg = _("Driver cannot calculate share size.")
|
||||||
raise exception.InvalidShare(reason=msg)
|
raise exception.InvalidShare(reason=msg)
|
||||||
|
|
||||||
self._update_quota_usages(context, project_id, {
|
reservations = QUOTAS.reserve(context,
|
||||||
"shares": 1,
|
project_id=project_id,
|
||||||
"gigabytes": share_update['size'],
|
user_id=context.user_id,
|
||||||
})
|
shares=1,
|
||||||
|
gigabytes=share_update['size'])
|
||||||
|
QUOTAS.commit(context, reservations, project_id=project_id)
|
||||||
|
|
||||||
share_update.update({
|
share_update.update({
|
||||||
'status': constants.STATUS_AVAILABLE,
|
'status': constants.STATUS_AVAILABLE,
|
||||||
|
@ -2075,7 +2075,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
self.mock_object(self.share_manager.driver,
|
self.mock_object(self.share_manager.driver,
|
||||||
"manage_existing",
|
"manage_existing",
|
||||||
mock.Mock(return_value={'size': 3}))
|
mock.Mock(return_value={'size': 3}))
|
||||||
self.mock_object(self.share_manager, '_update_quota_usages',
|
self.mock_object(quota.QUOTAS, 'reserve',
|
||||||
mock.Mock(side_effect=exception.QuotaError))
|
mock.Mock(side_effect=exception.QuotaError))
|
||||||
self.mock_object(self.share_manager.db, 'share_update', mock.Mock())
|
self.mock_object(self.share_manager.db, 'share_update', mock.Mock())
|
||||||
share = db_utils.create_share()
|
share = db_utils.create_share()
|
||||||
@ -2092,9 +2092,6 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
self.share_manager.db.share_update.assert_called_once_with(
|
self.share_manager.db.share_update.assert_called_once_with(
|
||||||
mock.ANY, share_id,
|
mock.ANY, share_id,
|
||||||
{'status': constants.STATUS_MANAGE_ERROR, 'size': 1})
|
{'status': constants.STATUS_MANAGE_ERROR, 'size': 1})
|
||||||
self.share_manager._update_quota_usages.assert_called_once_with(
|
|
||||||
utils.IsAMatcher(context.RequestContext),
|
|
||||||
share['project_id'], {'shares': 1, 'gigabytes': 3})
|
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
{'size': 1, 'replication_type': None},
|
{'size': 1, 'replication_type': None},
|
||||||
@ -2107,8 +2104,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
export_locations = driver_data.get('export_locations')
|
export_locations = driver_data.get('export_locations')
|
||||||
self.mock_object(self.share_manager.db, 'share_update', mock.Mock())
|
self.mock_object(self.share_manager.db, 'share_update', mock.Mock())
|
||||||
self.mock_object(self.share_manager, 'driver', mock.Mock())
|
self.mock_object(self.share_manager, 'driver', mock.Mock())
|
||||||
self.mock_object(self.share_manager, '_update_quota_usages',
|
self.mock_object(quota.QUOTAS, 'reserve', mock.Mock())
|
||||||
mock.Mock())
|
|
||||||
self.mock_object(
|
self.mock_object(
|
||||||
self.share_manager.db,
|
self.share_manager.db,
|
||||||
'share_export_locations_update',
|
'share_export_locations_update',
|
||||||
@ -4252,7 +4248,7 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
mock.Mock(return_value=None))
|
mock.Mock(return_value=None))
|
||||||
self.mock_object(self.share_manager.db, 'share_snapshot_update')
|
self.mock_object(self.share_manager.db, 'share_snapshot_update')
|
||||||
self.mock_object(self.share_manager, 'driver')
|
self.mock_object(self.share_manager, 'driver')
|
||||||
self.mock_object(self.share_manager, '_update_quota_usages')
|
self.mock_object(quota.QUOTAS, 'reserve', mock.Mock())
|
||||||
self.share_manager.driver.driver_handles_share_servers = False
|
self.share_manager.driver.driver_handles_share_servers = False
|
||||||
mock_manage = self.mock_object(
|
mock_manage = self.mock_object(
|
||||||
self.share_manager.driver,
|
self.share_manager.driver,
|
||||||
@ -4277,10 +4273,6 @@ class ShareManagerTestCase(test.TestCase):
|
|||||||
self.share_manager.db.share_snapshot_update.assert_called_once_with(
|
self.share_manager.db.share_snapshot_update.assert_called_once_with(
|
||||||
utils.IsAMatcher(context.RequestContext),
|
utils.IsAMatcher(context.RequestContext),
|
||||||
snapshot_id, valid_snapshot_data)
|
snapshot_id, valid_snapshot_data)
|
||||||
self.share_manager._update_quota_usages.assert_called_once_with(
|
|
||||||
utils.IsAMatcher(context.RequestContext),
|
|
||||||
snapshot['project_id'],
|
|
||||||
{'snapshots': 1, 'snapshot_gigabytes': size})
|
|
||||||
mock_get_share_server.assert_called_once_with(
|
mock_get_share_server.assert_called_once_with(
|
||||||
utils.IsAMatcher(context.RequestContext), snapshot['share'])
|
utils.IsAMatcher(context.RequestContext), snapshot['share'])
|
||||||
mock_get.assert_called_once_with(
|
mock_get.assert_called_once_with(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user