Merge "Raise descriptive error for over volume quota" into stable/icehouse

This commit is contained in:
Jenkins 2014-10-06 23:39:38 +00:00 committed by Gerrit Code Review
commit 499584b378
4 changed files with 64 additions and 0 deletions

View File

@ -1716,6 +1716,12 @@ class ComputeManager(manager.Manager):
block_device_info['swap'])
return block_device_info
except exception.OverQuota:
msg = ('Failed to create block device for instance due to being '
'over volume resource quota')
LOG.debug(msg, instance=instance)
raise exception.InvalidBDM()
except Exception:
LOG.exception(_('Instance failed block device setup'),
instance=instance)

View File

@ -1031,6 +1031,27 @@ class ComputeVolumeTestCase(BaseTestCase):
self.compute.volume_snapshot_delete, self.context,
self.instance_object, 'fake_id', 'fake_id2', {})
@mock.patch.object(cinder.API, 'create',
side_effect=exception.OverQuota(overs='volumes'))
def test_prep_block_device_over_quota_failure(self, mock_create):
instance = self._create_fake_instance()
bdms = [
block_device.BlockDeviceDict({
'boot_index': 0,
'guest_format': None,
'connection_info': None,
'device_type': u'disk',
'source_type': 'image',
'destination_type': 'volume',
'volume_size': 1,
'image_id': 1,
'device_name': '/dev/vdb',
})]
self.assertRaises(exception.InvalidBDM,
compute_manager.ComputeManager()._prep_block_device,
self.context, instance, bdms)
mock_create.assert_called_once()
class ComputeTestCase(BaseTestCase):
def test_wrap_instance_fault(self):
@ -1509,6 +1530,30 @@ class ComputeTestCase(BaseTestCase):
self._assert_state({'vm_state': vm_states.ERROR,
'task_state': None})
@mock.patch('nova.compute.manager.ComputeManager._prep_block_device',
side_effect=exception.OverQuota(overs='volumes'))
def test_setup_block_device_over_quota_fail(self, mock_prep_block_dev):
"""block device mapping over quota failure test.
Make sure when we're over volume quota according to Cinder client, the
appropriate exception is raised and the instances to ERROR state, keep
the task state.
"""
instance = self._create_fake_instance()
self.assertRaises(exception.OverQuota, self.compute.run_instance,
self.context, instance=instance, request_spec={},
filter_properties={}, requested_networks=[],
injected_files=None, admin_password=None,
is_first_time=True, node=None,
legacy_bdm_in_spec=False)
#check state is failed even after the periodic poll
self._assert_state({'vm_state': vm_states.ERROR,
'task_state': None})
self.compute.periodic_tasks(context.get_admin_context())
self._assert_state({'vm_state': vm_states.ERROR,
'task_state': None})
mock_prep_block_dev.assert_called_once()
def test_run_instance_spawn_fail(self):
"""spawn failure test.

View File

@ -86,6 +86,17 @@ class CinderApiTestCase(test.NoDBTestCase):
self.assertRaises(exception.InvalidInput,
self.api.create, self.ctx, 1, '', '')
@mock.patch('nova.volume.cinder.cinderclient')
def test_create_over_quota_failed(self, mock_cinderclient):
mock_cinderclient.return_value.volumes.create.side_effect = (
cinder_exception.OverLimit(413))
self.assertRaises(exception.OverQuota, self.api.create, self.ctx,
1, '', '')
mock_cinderclient.return_value.volumes.create.assert_called_once_with(
1, user_id=None, imageRef=None, availability_zone=None,
volume_type=None, display_description='', snapshot_id=None,
display_name='', project_id=None, metadata=None)
def test_get_all(self):
cinder.cinderclient(self.ctx).AndReturn(self.cinderclient)
cinder._untranslate_volume_summary_view(self.ctx,

View File

@ -302,6 +302,8 @@ class API(object):
try:
item = cinderclient(context).volumes.create(size, **kwargs)
return _untranslate_volume_summary_view(context, item)
except cinder_exception.OverLimit:
raise exception.OverQuota(overs='volumes')
except cinder_exception.BadRequest as e:
raise exception.InvalidInput(reason=unicode(e))