From fedd45446992efc848178f4851b0405cfa7d2fdd Mon Sep 17 00:00:00 2001 From: Szymon Borkowski Date: Tue, 12 Jan 2016 11:32:22 +0100 Subject: [PATCH] Fixed logging for oslo versioned objects Earlier, when we wanted to log a message with an object as a parameter, obj_attr_is_set method used to check name parameter, which was a wrong approach. The reason was, that the oslo logger, when received a versioned object as a resource parameter, is trying to get the 'name' parameter, which is a property, so the obj_attr_is_set method will return False and the logger will try to get the 'type' parameter, which does not exist in some versioned objects (please take a look at oslo.logging code [1]). Now, when the parameter's name is present in obj_extra_fields dict, we avoid calling obj_attr_is_set and simply get() it. The other cause was a difference between fields names: size (in volume object) and volume_size (in snapshot object), and inproper condition statement in lvm driver. [1] goo.gl/YffLcK Change-Id: Id92d58b4ccced907cc6e3e59d9e71650a459b4a8 Closes-Bug: 1501521 --- cinder/objects/base.py | 1 + cinder/tests/unit/objects/test_base.py | 1 + cinder/volume/drivers/lvm.py | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cinder/objects/base.py b/cinder/objects/base.py index 24f775a1d..1451e8951 100644 --- a/cinder/objects/base.py +++ b/cinder/objects/base.py @@ -326,6 +326,7 @@ class CinderObjectDictCompat(base.VersionedObjectDictCompat): 'attribute_name': key}) return None if (value != base._NotSpecifiedSentinel and + key not in self.obj_extra_fields and not self.obj_attr_is_set(key)): return value else: diff --git a/cinder/tests/unit/objects/test_base.py b/cinder/tests/unit/objects/test_base.py index 70e2da302..b67da6c2a 100644 --- a/cinder/tests/unit/objects/test_base.py +++ b/cinder/tests/unit/objects/test_base.py @@ -601,6 +601,7 @@ class TestCinderDictObject(test_objects.BaseObjectsTestCase): obj.abc = 'val2' self.assertEqual('val2', obj.get('abc', 'val')) self.assertEqual(42, obj.get('foo')) + self.assertEqual(42, obj.get('foo', None)) self.assertTrue('foo' in obj) self.assertTrue('abc' in obj) diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 34a9172e1..81d959e21 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -152,7 +152,8 @@ class LVMVolumeDriver(driver.VolumeDriver): LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - size_in_g = volume.get('volume_size') or volume.get('size') + size_in_g = (volume.get('volume_size') if is_snapshot + else volume.get('size')) if size_in_g is None: msg = (_("Size for volume: %s not found, cannot secure delete.") % volume['id']) -- 2.45.2