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
This commit is contained in:
Szymon Borkowski 2016-01-12 11:32:22 +01:00 committed by Michal Dulko
parent 3f2fe6266e
commit fedd454469
3 changed files with 4 additions and 1 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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'])