Merge "Rollback the volume_types table when failed to update quota_usages"
This commit is contained in:
commit
b5c53fc450
@ -19,6 +19,7 @@ import mock
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
from oslo_db import exception as db_exc
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from cinder import context
|
from cinder import context
|
||||||
@ -143,6 +144,30 @@ class VolumeTypeTestCase(test.TestCase):
|
|||||||
new_type_name)
|
new_type_name)
|
||||||
volume_types.destroy(self.ctxt, type_ref.id)
|
volume_types.destroy(self.ctxt, type_ref.id)
|
||||||
|
|
||||||
|
@mock.patch('cinder.quota.VolumeTypeQuotaEngine.'
|
||||||
|
'update_quota_resource')
|
||||||
|
def test_update_volume_type_name_with_db_error(self, mock_update_quota):
|
||||||
|
type_ref = volume_types.create(self.ctxt,
|
||||||
|
self.vol_type1_name,
|
||||||
|
self.vol_type1_specs,
|
||||||
|
description=self.vol_type1_description)
|
||||||
|
mock_update_quota.side_effect = db_exc.DBError
|
||||||
|
new_type_name = self.vol_type1_name + '_updated'
|
||||||
|
description = 'new_test'
|
||||||
|
is_public = False
|
||||||
|
self.assertRaises(exception.VolumeTypeUpdateFailed,
|
||||||
|
volume_types.update, self.ctxt, type_ref.id,
|
||||||
|
new_type_name, description, is_public)
|
||||||
|
mock_update_quota.assert_called_once_with(self.ctxt,
|
||||||
|
self.vol_type1_name,
|
||||||
|
new_type_name)
|
||||||
|
new = volume_types.get_volume_type_by_name(self.ctxt,
|
||||||
|
self.vol_type1_name)
|
||||||
|
self.assertEqual(self.vol_type1_name, new.get('name'))
|
||||||
|
self.assertEqual(self.vol_type1_description, new.get('description'))
|
||||||
|
self.assertTrue(new.get('is_public'))
|
||||||
|
volume_types.destroy(self.ctxt, type_ref.id)
|
||||||
|
|
||||||
def test_volume_type_create_then_destroy_with_non_admin(self):
|
def test_volume_type_create_then_destroy_with_non_admin(self):
|
||||||
"""Ensure volume types can be created and deleted by non-admin user.
|
"""Ensure volume types can be created and deleted by non-admin user.
|
||||||
|
|
||||||
|
@ -79,9 +79,19 @@ def update(context, id, name, description, is_public=None):
|
|||||||
if name:
|
if name:
|
||||||
old_type_name = old_volume_type.get('name')
|
old_type_name = old_volume_type.get('name')
|
||||||
if old_type_name != name:
|
if old_type_name != name:
|
||||||
QUOTAS.update_quota_resource(elevated,
|
old_description = old_volume_type.get('description')
|
||||||
old_type_name,
|
old_public = old_volume_type.get('is_public')
|
||||||
name)
|
try:
|
||||||
|
QUOTAS.update_quota_resource(elevated,
|
||||||
|
old_type_name,
|
||||||
|
name)
|
||||||
|
# Rollback the updated information to the original
|
||||||
|
except db_exc.DBError:
|
||||||
|
db.volume_type_update(elevated, id,
|
||||||
|
dict(name=old_type_name,
|
||||||
|
description=old_description,
|
||||||
|
is_public=old_public))
|
||||||
|
raise
|
||||||
except db_exc.DBError:
|
except db_exc.DBError:
|
||||||
LOG.exception('DB error:')
|
LOG.exception('DB error:')
|
||||||
raise exception.VolumeTypeUpdateFailed(id=id)
|
raise exception.VolumeTypeUpdateFailed(id=id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user