From 35579d812500890518215f4a766412ceb880d078 Mon Sep 17 00:00:00 2001 From: Dmitry Guryanov Date: Tue, 13 Oct 2015 14:53:13 +0300 Subject: [PATCH] Fix method VolumeTypeList.get_all 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 | 2 +- cinder/tests/unit/objects/test_volume_type.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cinder/objects/volume_type.py b/cinder/objects/volume_type.py index 78196d2ee..0784947c1 100644 --- a/cinder/objects/volume_type.py +++ b/cinder/objects/volume_type.py @@ -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) diff --git a/cinder/tests/unit/objects/test_volume_type.py b/cinder/tests/unit/objects/test_volume_type.py index 356a523d1..d0453513c 100644 --- a/cinder/tests/unit/objects/test_volume_type.py +++ b/cinder/tests/unit/objects/test_volume_type.py @@ -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)) -- 2.45.2