do not log error for missing _save_tags

The instance.save always logs the below error message if instance.tags
are lazy loaded before the save.

AttributeError: 'Instance' object has no attribute '_save_tags'

The tags should never be saved through the instance object so adding an
empty _save_tags function is better than logging an error every time.

Change-Id: Id41b06e7a294d803bd580d38ef04cc0ffb32a3bf
This commit is contained in:
Balazs Gibizer 2017-03-27 16:17:51 +02:00
parent 27441a2312
commit c4f24bb105
2 changed files with 23 additions and 0 deletions

View File

@ -616,6 +616,10 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
# be dropped.
pass
def _save_tags(self, context):
# NOTE(gibi): tags are not saved through the instance
pass
def _save_flavor(self, context):
if not any([x in self.obj_what_changed() for x in
('flavor', 'old_flavor', 'new_flavor')]):

View File

@ -234,6 +234,25 @@ class _TestInstanceObject(object):
self.assertEqual(1, len(instance.tags))
self.assertEqual('foo', instance.tags[0].tag)
@mock.patch('nova.objects.instance.LOG.exception')
def test_save_does_not_log_exception_after_tags_loaded(self, mock_log):
instance = objects.Instance(self.context, uuid=uuids.instance,
user_id=self.context.user_id,
project_id=self.context.project_id)
instance.create()
tag = objects.Tag(self.context, resource_id=instance.uuid, tag='foo')
tag.create()
# this will lazy load tags so instance.tags will be set
self.assertEqual(1, len(instance.tags))
# instance.save will try to find a way to save tags but is should not
# spam the log with errors
instance.display_name = 'foobar'
instance.save()
self.assertFalse(mock_log.called)
@mock.patch.object(db, 'instance_get')
def test_get_by_id(self, mock_get):
mock_get.return_value = self.fake_instance