diff --git a/ceilometer/alarm/storage/impl_mongodb.py b/ceilometer/alarm/storage/impl_mongodb.py index 07a78edc2..f4549af3a 100644 --- a/ceilometer/alarm/storage/impl_mongodb.py +++ b/ceilometer/alarm/storage/impl_mongodb.py @@ -58,6 +58,13 @@ class Connection(pymongo_base.Connection): # needed. self.upgrade() + def upgrade(self): + # create collection if not present + if 'alarm' not in self.db.conn.collection_names(): + self.db.conn.create_collection('alarm') + if 'alarm_history' not in self.db.conn.collection_names(): + self.db.conn.create_collection('alarm_history') + def clear(self): self.conn.drop_database(self.db.name) # Connection will be reopened automatically if needed diff --git a/ceilometer/event/storage/impl_mongodb.py b/ceilometer/event/storage/impl_mongodb.py index 728c1258e..822831cf2 100644 --- a/ceilometer/event/storage/impl_mongodb.py +++ b/ceilometer/event/storage/impl_mongodb.py @@ -53,6 +53,9 @@ class Connection(pymongo_base.Connection): self.upgrade() def upgrade(self): + # create collection if not present + if 'event' not in self.db.conn.collection_names(): + self.db.conn.create_collection('event') # Establish indexes ttl = cfg.CONF.database.event_time_to_live impl_mongodb.Connection.update_ttl(ttl, 'event_ttl', 'timestamp', diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index d7b114420..557f8e226 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -442,6 +442,13 @@ class Connection(pymongo_base.Connection): # project_id values are usually mutually exclusive in the # queries, so the database won't take advantage of an index # including both. + + # create collection if not present + if 'resource' not in self.db.conn.collection_names(): + self.db.conn.create_collection('resource') + if 'meter' not in self.db.conn.collection_names(): + self.db.conn.create_collection('meter') + name_qualifier = dict(user_id='', project_id='project_') background = dict(user_id=False, project_id=True) for primary in ['user_id', 'project_id']: