From e71000be85b9321ed7b88345671a6648bff89e91 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 31 Oct 2012 17:38:34 +0000 Subject: [PATCH] add mongo index names fixes bug #1028485 Change-Id: Iccdda933ebe574db2927a62516cf7e1189dac6eb --- ceilometer/storage/impl_mongodb.py | 4 ++-- tests/storage/test_impl_mongodb.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index b6b81e866..84a0eea6e 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -191,14 +191,14 @@ class Connection(base.Connection): self.db.resource.ensure_index([ (primary, pymongo.ASCENDING), ('source', pymongo.ASCENDING), - ]) + ], name='resource_idx') self.db.meter.ensure_index([ ('resource_id', pymongo.ASCENDING), (primary, pymongo.ASCENDING), ('counter_name', pymongo.ASCENDING), ('timestamp', pymongo.ASCENDING), ('source', pymongo.ASCENDING), - ]) + ], name='meter_idx') return def _get_connection(self, opts): diff --git a/tests/storage/test_impl_mongodb.py b/tests/storage/test_impl_mongodb.py index 513899bcf..454278eb3 100644 --- a/tests/storage/test_impl_mongodb.py +++ b/tests/storage/test_impl_mongodb.py @@ -141,6 +141,14 @@ class MongoDBEngineTestBase(unittest.TestCase): self.conn.drop_database(self.DBNAME) +class IndexTest(MongoDBEngineTestBase): + + def test_indexes_exist(self): + # ensure_index returns none if index already exists + assert not self.db.resource.ensure_index('foo', name='resource_idx') + assert not self.db.meter.ensure_index('foo', name='meter_idx') + + class UserTest(MongoDBEngineTestBase): def test_new_user(self):