diff --git a/nova/objects/instance.py b/nova/objects/instance.py index e0d79e26eed5..bba3f6d423fc 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -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')]): diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index e9ac32f5adb8..d7f7c863c67e 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -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