summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2015-06-16 11:00:32 -0700
committerDan Smith <dansmith@redhat.com>2015-06-16 11:31:08 -0700
commit74d16c112b17c19a964c4c114156e87026c9a199 (patch)
treeaccd1e30c6672b18ebda3b55f6518a1234e82dbd
parentf60eb56f0ac1ab007cfbda65008b7222d382831f (diff)
downloadnova-74d16c112b17c19a964c4c114156e87026c9a199.tar.gz
Avoid always saving flavor info in instance
Right now, _save_flavor() will always end up updating the instance_extra record, even if nothing has changed. This is because this helper is always called during save() and it doesn't avoid doing work if there is nothing to do. Closes-Bug: #1465799 Change-Id: I464f0a75c08df881457298bd9ccdb35220721b74
-rw-r--r--nova/objects/instance.py3
-rw-r--r--nova/tests/unit/objects/test_instance.py8
2 files changed, 11 insertions, 0 deletions
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index 3b914cf029..4ade3f4d1b 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -711,6 +711,9 @@ class Instance(base.NovaPersistentObject, base.NovaObject,
pass
def _save_flavor(self, context):
+ if not any([x in self.obj_what_changed() for x in
+ ('flavor', 'old_flavor', 'new_flavor')]):
+ return
# FIXME(danms): We can do this smarterly by updating this
# with all the other extra things at the same time
flavor_info = {
diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py
index e0d15368d1..d270ac425a 100644
--- a/nova/tests/unit/objects/test_instance.py
+++ b/nova/tests/unit/objects/test_instance.py
@@ -498,6 +498,14 @@ class _TestInstanceObject(object):
instance.save)
_test()
+ def test_save_flavor_skips_unchanged_flavors(self):
+ inst = objects.Instance(context=self.context,
+ flavor=objects.Flavor())
+ inst.obj_reset_changes()
+ with mock.patch('nova.db.instance_extra_update_by_uuid') as mock_upd:
+ inst.save()
+ self.assertFalse(mock_upd.called)
+
@mock.patch.object(cells_rpcapi.CellsAPI, 'instance_update_from_api')
@mock.patch.object(cells_rpcapi.CellsAPI, 'instance_update_at_top')
@mock.patch.object(db, 'instance_update_and_get_original')