From 053de0aa4013dfcc9fca3b29d21e31cbf44ba7bf Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Fri, 17 May 2013 17:46:30 +0000 Subject: [PATCH] Don't update DB records for unchanged stats. Change-Id: I6eb0adba12676cf057c92fb0b54431cfe6a76210 --- nova/tests/test_db_api.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 8dbfa701..7a642e45 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -1750,6 +1750,38 @@ class CapacityTestCase(test.TestCase): item['id'], {}) self.assertNotEqual(item['updated_at'], item_updated['updated_at']) + def test_compute_node_stat_unchanged(self): + # don't update unchanged stat values: + item = self._create_helper('host1') + + compute_node_id = item['id'] + stats = self._stats_as_dict(item['stats']) + self.assertEqual(4, len(stats.keys())) + + orig_update_stats = sqlalchemy_api._update_stats + + def update(context, new_stats, compute_id, session, prune_stats=False): + # wrap the session object to see which stats get updated + orig_add = session.add + added = [] + + def add(instance): + added.append(instance) + orig_add(instance) + + self.stubs.Set(session, 'add', add) + orig_update_stats(context, new_stats, compute_id, session, + prune_stats=False) + + # no stats should have been added to the session: + self.assertEqual(0, len(added)) + + self.stubs.Set(sqlalchemy_api, '_update_stats', update) + + # save with same (unchanged) stats again: + values = {'stats': stats} + db.compute_node_update(self.ctxt, compute_node_id, values) + def test_compute_node_stat_prune(self): item = self._create_helper('host1') for stat in item['stats']: