summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorBrian Elliott <bdelliott@gmail.com>2013-05-17 17:46:30 +0000
committerBrian Elliott <bdelliott@gmail.com>2013-05-17 19:53:25 +0000
commite788bc24809693b19969c7f7fb44f414bb3b890a (patch)
treeb57a1669a1211b41c2edbba83300871572766aa3 /nova/tests
parent0e760b3e94c53e8f794609a60343b392e7ff595c (diff)
Don't update DB records for unchanged stats.
Change-Id: I6eb0adba12676cf057c92fb0b54431cfe6a76210
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_db_api.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 8dbfa7010..7a642e451 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']: