Merge "Fix quota rollback on retype failure"

This commit is contained in:
Jenkins 2016-09-07 10:13:26 +00:00 committed by Gerrit Code Review
commit 7ff588cd95
2 changed files with 7 additions and 3 deletions

View File

@ -282,7 +282,7 @@ class SchedulerManager(manager.Manager):
reraise = not isinstance(ex, exception.NoValidHost) reraise = not isinstance(ex, exception.NoValidHost)
with excutils.save_and_reraise_exception(reraise=reraise): with excutils.save_and_reraise_exception(reraise=reraise):
_retype_volume_set_error(self, context, ex, request_spec, _retype_volume_set_error(self, context, ex, request_spec,
volume, None, reservations) volume, reservations)
else: else:
volume_rpcapi.VolumeAPI().retype(context, volume, volume_rpcapi.VolumeAPI().retype(context, volume,
new_type['id'], tgt_host, new_type['id'], tgt_host,

View File

@ -266,8 +266,9 @@ class SchedulerManagerTestCase(test.TestCase):
@mock.patch('cinder.db.volume_update') @mock.patch('cinder.db.volume_update')
@mock.patch('cinder.db.volume_attachment_get_all_by_volume_id') @mock.patch('cinder.db.volume_attachment_get_all_by_volume_id')
@mock.patch('cinder.quota.QUOTAS.rollback')
def test_retype_volume_exception_returns_volume_state( def test_retype_volume_exception_returns_volume_state(
self, _mock_vol_attachment_get, _mock_vol_update): self, quota_rollback, _mock_vol_attachment_get, _mock_vol_update):
# Test NoValidHost exception behavior for retype. # Test NoValidHost exception behavior for retype.
# Puts the volume in original state and eats the exception. # Puts the volume in original state and eats the exception.
volume = tests_utils.create_volume(self.context, volume = tests_utils.create_volume(self.context,
@ -279,8 +280,10 @@ class SchedulerManagerTestCase(test.TestCase):
'/dev/fake') '/dev/fake')
_mock_vol_attachment_get.return_value = [volume_attach] _mock_vol_attachment_get.return_value = [volume_attach]
topic = 'fake_topic' topic = 'fake_topic'
reservations = mock.sentinel.reservations
request_spec = {'volume_id': volume.id, 'volume_type': {'id': 3}, request_spec = {'volume_id': volume.id, 'volume_type': {'id': 3},
'migration_policy': 'on-demand'} 'migration_policy': 'on-demand',
'quota_reservations': reservations}
_mock_vol_update.return_value = {'status': 'in-use'} _mock_vol_update.return_value = {'status': 'in-use'}
_mock_find_retype_host = mock.Mock( _mock_find_retype_host = mock.Mock(
side_effect=exception.NoValidHost(reason="")) side_effect=exception.NoValidHost(reason=""))
@ -295,6 +298,7 @@ class SchedulerManagerTestCase(test.TestCase):
_mock_find_retype_host.assert_called_once_with(self.context, _mock_find_retype_host.assert_called_once_with(self.context,
request_spec, {}, request_spec, {},
'on-demand') 'on-demand')
quota_rollback.assert_called_once_with(self.context, reservations)
_mock_vol_update.assert_called_once_with(self.context, volume.id, _mock_vol_update.assert_called_once_with(self.context, volume.id,
{'status': 'in-use'}) {'status': 'in-use'})
self.manager.driver.find_retype_host = orig_retype self.manager.driver.find_retype_host = orig_retype