Browse Source

Merge "Rollback the volume_types table when failed to update quota_usages" into stable/stein

changes/12/701212/1
Zuul 1 month ago
parent
commit
a59c01e820
2 changed files with 38 additions and 3 deletions
  1. +25
    -0
      cinder/tests/unit/test_volume_types.py
  2. +13
    -3
      cinder/volume/volume_types.py

+ 25
- 0
cinder/tests/unit/test_volume_types.py View File

@@ -19,6 +19,7 @@ import mock
import time

from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_utils import uuidutils

from cinder import context
@@ -143,6 +144,30 @@ class VolumeTypeTestCase(test.TestCase):
new_type_name)
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):
"""Ensure volume types can be created and deleted by non-admin user.


+ 13
- 3
cinder/volume/volume_types.py View File

@@ -79,9 +79,19 @@ def update(context, id, name, description, is_public=None):
if name:
old_type_name = old_volume_type.get('name')
if old_type_name != name:
QUOTAS.update_quota_resource(elevated,
old_type_name,
name)
old_description = old_volume_type.get('description')
old_public = old_volume_type.get('is_public')
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:
LOG.exception('DB error:')
raise exception.VolumeTypeUpdateFailed(id=id)

Loading…
Cancel
Save