]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Return updated volume type after updating
authorLisaLi <xiaoyan.li@intel.com>
Thu, 28 Jan 2016 02:47:36 +0000 (10:47 +0800)
committerLisaLi <xiaoyan.li@intel.com>
Mon, 1 Feb 2016 07:52:36 +0000 (07:52 +0000)
When updating volume type in db, it queries the object and
would like to return the updated object.

The problem is that the update session hasn't committed and
the update has not been implemented in db. And then the query is
executed in another session. As a result, the update function returns
an non-updated object.

The fix is to return updated object.

Closes-Bug: #1540190

Change-Id: I4b57ea69b1eebd62de707ca15aad32c53fca9f1d

cinder/db/sqlalchemy/api.py
cinder/tests/unit/db/test_volume_type.py [new file with mode: 0644]

index 32b8bb97aa9b75ea14862c88c77ba96b92847bd1..d6262972639e60e0e38af5c085d8aeef8c1a7726 100644 (file)
@@ -2447,9 +2447,8 @@ def volume_type_update(context, volume_type_id, values):
 
         volume_type_ref.update(values)
         volume_type_ref.save(session=session)
-        volume_type = volume_type_get(context, volume_type_id)
 
-        return volume_type
+        return volume_type_ref
 
 
 @require_context
diff --git a/cinder/tests/unit/db/test_volume_type.py b/cinder/tests/unit/db/test_volume_type.py
new file mode 100644 (file)
index 0000000..f87db1e
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright 2016 Intel Corp.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+"""Tests for volume type."""
+
+from oslo_config import cfg
+
+from cinder import context
+from cinder import db
+from cinder import test
+from cinder.volume import volume_types
+
+CONF = cfg.CONF
+
+
+class VolumeTypeTestCase(test.TestCase):
+    """Test cases for volume type."""
+
+    def setUp(self):
+        super(VolumeTypeTestCase, self).setUp()
+        self.ctxt = context.RequestContext(user_id='user_id',
+                                           project_id='project_id',
+                                           is_admin = True)
+
+    def test_volume_type_update(self):
+        vol_type_ref = volume_types.create(self.ctxt, 'fake volume type')
+        updates = dict(name = 'test_volume_type_update',
+                       description = None,
+                       is_public = None)
+        updated_vol_type = db.volume_type_update(
+            self.ctxt, vol_type_ref.id, updates)
+        self.assertEqual('test_volume_type_update', updated_vol_type.name)
+        volume_types.destroy(self.ctxt, vol_type_ref.id)