Add the mongo implementation of alarms collection
blueprint alarm-api Change-Id: I2c0691a788a0ca81d231802cc44a40641672b23e
This commit is contained in:
parent
1667ded277
commit
896015ccae
@ -28,6 +28,7 @@ import re
|
|||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
import bson.code
|
import bson.code
|
||||||
|
import bson.objectid
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
from ceilometer.openstack.common import log
|
from ceilometer.openstack.common import log
|
||||||
@ -510,17 +511,45 @@ class Connection(base.Connection):
|
|||||||
project=None, enabled=True, alarm_id=None):
|
project=None, enabled=True, alarm_id=None):
|
||||||
"""Yields a lists of alarms that match filters
|
"""Yields a lists of alarms that match filters
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError('Alarms not implemented')
|
q = {}
|
||||||
|
if user is not None:
|
||||||
|
q['user_id'] = user
|
||||||
|
if project is not None:
|
||||||
|
q['project_id'] = project
|
||||||
|
if name is not None:
|
||||||
|
q['name'] = name
|
||||||
|
if enabled is not None:
|
||||||
|
q['enabled'] = enabled
|
||||||
|
if alarm_id is not None:
|
||||||
|
q['_id'] = alarm_id
|
||||||
|
|
||||||
|
for alarm in self.db.alarm.find(q):
|
||||||
|
a = {}
|
||||||
|
a.update(alarm)
|
||||||
|
a['alarm_id'] = str(a['_id'])
|
||||||
|
del a['_id']
|
||||||
|
yield models.Alarm(**a)
|
||||||
|
|
||||||
def update_alarm(self, alarm):
|
def update_alarm(self, alarm):
|
||||||
"""update alarm
|
"""update alarm
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError('Alarms not implemented')
|
aid = bson.objectid.ObjectId(oid=alarm.alarm_id)
|
||||||
|
data = alarm.as_dict()
|
||||||
|
self.db.alarm.update(
|
||||||
|
{'_id': aid},
|
||||||
|
{'$set': data},
|
||||||
|
upsert=True)
|
||||||
|
|
||||||
|
stored_alarm = self.db.alarm.find({'_id': aid})[0]
|
||||||
|
stored_alarm['alarm_id'] = str(stored_alarm['_id'])
|
||||||
|
del stored_alarm['_id']
|
||||||
|
return models.Alarm(**stored_alarm)
|
||||||
|
|
||||||
def delete_alarm(self, alarm_id):
|
def delete_alarm(self, alarm_id):
|
||||||
"""Delete a alarm
|
"""Delete a alarm
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError('Alarms not implemented')
|
aid = bson.objectid.ObjectId(oid=alarm_id)
|
||||||
|
self.db.alarm.remove({'_id': aid})
|
||||||
|
|
||||||
|
|
||||||
def require_map_reduce(conn):
|
def require_map_reduce(conn):
|
||||||
|
@ -638,6 +638,18 @@ class AlarmTest(DBTestBase):
|
|||||||
self.assertEquals(updated.enabled, False)
|
self.assertEquals(updated.enabled, False)
|
||||||
self.assertEquals(updated.state, models.Alarm.ALARM_INSUFFICIENT_DATA)
|
self.assertEquals(updated.state, models.Alarm.ALARM_INSUFFICIENT_DATA)
|
||||||
|
|
||||||
|
def test_update_llu(self):
|
||||||
|
llu = models.Alarm('llu',
|
||||||
|
'counter_name', 'lt', 34, 'max',
|
||||||
|
'bla', 'ffo')
|
||||||
|
updated = self.conn.update_alarm(llu)
|
||||||
|
updated.state = models.Alarm.ALARM_OK
|
||||||
|
updated.description = ':)'
|
||||||
|
self.conn.update_alarm(updated)
|
||||||
|
|
||||||
|
all = list(self.conn.get_alarms())
|
||||||
|
self.assertEquals(len(all), 1)
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.add_some_alarms()
|
self.add_some_alarms()
|
||||||
victim = list(self.conn.get_alarms(name='orange-alert'))[0]
|
victim = list(self.conn.get_alarms(name='orange-alert'))[0]
|
||||||
|
@ -97,6 +97,10 @@ class StatisticsTest(base.StatisticsTest, MongoDBEngineTestBase):
|
|||||||
require_map_reduce(self.conn)
|
require_map_reduce(self.conn)
|
||||||
|
|
||||||
|
|
||||||
|
class AlarmTest(base.AlarmTest, MongoDBEngineTestBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CompatibilityTest(MongoDBEngineTestBase):
|
class CompatibilityTest(MongoDBEngineTestBase):
|
||||||
|
|
||||||
def prepare_data(self):
|
def prepare_data(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user