]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix method VolumeTypeList.get_all
authorDmitry Guryanov <dguryanov@parallels.com>
Tue, 13 Oct 2015 11:53:13 +0000 (14:53 +0300)
committerJohn Griffith <john.griffith8@gmail.com>
Tue, 13 Oct 2015 18:25:47 +0000 (18:25 +0000)
Function volume_types.get_all_types returns dict, then
VolumeTypeList.get_all passes it to base.obj_make_list, which, in turn,
passes it to oslo_versionedobjects.base.obj_make_list.

And this function iterates over 4th argument and calls
item_cls._from_db_object for each item. So if it will iterate over dict
from volume_types.get_all_types, it'll get strings instead of orm
objects.

By the way, VolumeTypeList.get_all is not used anywhere in cinder code.
I tried to use it in unit test for my new patch and found this problem.

Closes-Bug: #1505653

Change-Id: If789bc5bf224974de5c4e4b9a57c83ef51d1779b

cinder/objects/volume_type.py
cinder/tests/unit/objects/test_volume_type.py

index 78196d2eead460396a560a948f7cd983d2b440ae..0784947c18ee7532ccabd589747b8ca9548fe7e6 100644 (file)
@@ -121,5 +121,5 @@ class VolumeTypeList(base.ObjectListBase, base.CinderObject):
         types = volume_types.get_all_types(context, inactive, search_opts)
         expected_attrs = ['extra_specs', 'projects']
         return base.obj_make_list(context, cls(context),
-                                  objects.VolumeType, types,
+                                  objects.VolumeType, types.values(),
                                   expected_attrs=expected_attrs)
index 356a523d1b4408d566d316f571690d8896e98735..d0453513c5ba8e299ff9f4a862303934cc9c2967 100644 (file)
@@ -88,7 +88,7 @@ class TestVolumeTypeList(test_objects.BaseObjectsTestCase):
     @mock.patch('cinder.volume.volume_types.get_all_types')
     def test_get_all(self, get_all_types):
         db_volume_type = fake_volume.fake_db_volume_type()
-        get_all_types.return_value = [db_volume_type]
+        get_all_types.return_value = {db_volume_type['name']: db_volume_type}
 
         volume_types = objects.VolumeTypeList.get_all(self.context)
         self.assertEqual(1, len(volume_types))