|
|
|
@ -45,6 +45,26 @@ class WatchData:
|
|
|
|
|
@attr(speed='fast')
|
|
|
|
|
class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
|
|
|
|
# Create a dummy stack in the DB as WatchRule instances
|
|
|
|
|
# must be associated with a stack
|
|
|
|
|
ctx = context.get_admin_context()
|
|
|
|
|
tmpl = db_api.raw_template_create(ctx, {'foo': 'bar'})
|
|
|
|
|
dummy_stack = {'id': '6754d843-bed2-40dc-a325-84882bb90a98',
|
|
|
|
|
'name': 'dummystack',
|
|
|
|
|
'raw_template_id': tmpl.id,
|
|
|
|
|
'user_creds_id': 1,
|
|
|
|
|
'username': 'dummyuser',
|
|
|
|
|
'owner_id': None,
|
|
|
|
|
'status': 'CREATE_COMPLETE',
|
|
|
|
|
'status_reason': 'foo status',
|
|
|
|
|
'parameters': {'foo': 'bar'},
|
|
|
|
|
'timeout': 60,
|
|
|
|
|
'tenant': 123456}
|
|
|
|
|
db_ret = db_api.stack_create(ctx, dummy_stack)
|
|
|
|
|
cls.stack_id = db_ret.id
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.username = 'watchrule_test_user'
|
|
|
|
|
|
|
|
|
@ -77,8 +97,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
|
logger.info(new_state)
|
|
|
|
@ -88,8 +108,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
|
logger.info(new_state)
|
|
|
|
@ -113,8 +133,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -125,8 +145,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -152,8 +172,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -165,8 +185,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -179,8 +199,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -205,8 +225,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -218,8 +238,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -243,8 +263,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -255,8 +275,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
watcher = watchrule.WatchRule(context=self.ctx,
|
|
|
|
|
watch_name="testwatch",
|
|
|
|
|
rule=rule,
|
|
|
|
|
stack_name="teststack",
|
|
|
|
|
watch_data=data,
|
|
|
|
|
stack_id=self.stack_id,
|
|
|
|
|
last_evaluated=last)
|
|
|
|
|
watcher.now = now
|
|
|
|
|
new_state = watcher.get_alarm_state()
|
|
|
|
@ -265,7 +285,8 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_load(self):
|
|
|
|
|
# Insert two dummy watch rules into the DB
|
|
|
|
|
values = {'stack_name': u'wordpress_ha', 'state': 'NORMAL',
|
|
|
|
|
values = {'stack_id': self.stack_id,
|
|
|
|
|
'state': 'NORMAL',
|
|
|
|
|
'name': u'HttpFailureAlarm',
|
|
|
|
|
'rule': {
|
|
|
|
|
u'EvaluationPeriods': u'1',
|
|
|
|
@ -291,7 +312,6 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(wr.name, wn)
|
|
|
|
|
self.assertEqual(wr.state, values['state'])
|
|
|
|
|
self.assertEqual(wr.rule, values['rule'])
|
|
|
|
|
self.assertEqual(wr.stack_name, values['stack_name'])
|
|
|
|
|
self.assertEqual(wr.timeperiod, datetime.timedelta(
|
|
|
|
|
seconds=int(values['rule']['Period'])))
|
|
|
|
|
|
|
|
|
@ -301,23 +321,22 @@ class WatchRuleTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_store(self):
|
|
|
|
|
rule = {u'EvaluationPeriods': u'1',
|
|
|
|
|
u'AlarmActions': [u'WebServerRestartPolicy'],
|
|
|
|
|
u'AlarmDescription': u'Restart the WikiDatabase',
|
|
|
|
|
u'Namespace': u'system/linux',
|
|
|
|
|
u'Period': u'300',
|
|
|
|
|
u'ComparisonOperator': u'GreaterThanThreshold',
|
|
|
|
|
u'Statistic': u'SampleCount',
|
|
|
|
|
u'Threshold': u'2',
|
|
|
|
|
u'MetricName': u'ServiceFailure'}
|
|
|
|
|
u'AlarmActions': [u'WebServerRestartPolicy'],
|
|
|
|
|
u'AlarmDescription': u'Restart the WikiDatabase',
|
|
|
|
|
u'Namespace': u'system/linux',
|
|
|
|
|
u'Period': u'300',
|
|
|
|
|
u'ComparisonOperator': u'GreaterThanThreshold',
|
|
|
|
|
u'Statistic': u'SampleCount',
|
|
|
|
|
u'Threshold': u'2',
|
|
|
|
|
u'MetricName': u'ServiceFailure'}
|
|
|
|
|
wr = watchrule.WatchRule(context=self.ctx, watch_name='storetest',
|
|
|
|
|
rule=rule, stack_name='teststack')
|
|
|
|
|
stack_id=self.stack_id, rule=rule)
|
|
|
|
|
wr.store()
|
|
|
|
|
|
|
|
|
|
dbwr = db_api.watch_rule_get_by_name(self.ctx, 'storetest')
|
|
|
|
|
self.assertNotEqual(dbwr, None)
|
|
|
|
|
self.assertEqual(dbwr.name, 'storetest')
|
|
|
|
|
self.assertEqual(dbwr.state, watchrule.WatchRule.NORMAL)
|
|
|
|
|
self.assertEqual(dbwr.stack_name, 'teststack')
|
|
|
|
|
self.assertEqual(dbwr.rule, rule)
|
|
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
|