Make the current alarms use the signal action

blueprint watch-ceilometer
Change-Id: I7560650f207411ffaf14242bb74cdaf8acd0cf4b
This commit is contained in:
Angus Salkeld 2013-07-05 10:35:36 +10:00
parent c8dae557b3
commit 390757280c
7 changed files with 26 additions and 21 deletions

View File

@ -461,7 +461,7 @@ class ScalingPolicy(resource.Resource, CooldownMixin):
self.stack.resolve_runtime_data,
self.name)
def alarm(self):
def handle_signal(self, details=None):
if self._cooldown_inprogress():
logger.info("%s NOT performing scaling action, cooldown %s" %
(self.name, self.properties['Cooldown']))

View File

@ -51,7 +51,7 @@ class Restarter(resource.Resource):
return resource
return None
def alarm(self):
def handle_signal(self, details=None):
victim = self._find_resource(self.properties['InstanceId'])
if victim is None:

View File

@ -619,9 +619,9 @@ class EngineService(service.Service):
('watch rule removed?', str(ex)))
return
def run_alarm_action(actions):
def run_alarm_action(actions, details):
for action in actions:
action()
action(details=details)
stk = parser.Stack.load(stack_context, stack=stack)
for res in stk:
@ -631,7 +631,8 @@ class EngineService(service.Service):
rule = watchrule.WatchRule.load(stack_context, watch=wr)
actions = rule.evaluate()
if actions:
self._start_in_thread(sid, run_alarm_action, actions)
self._start_in_thread(sid, run_alarm_action, actions,
rule.get_details())
@request_context
def create_watch_data(self, cnxt, watch_name, stats_data):

View File

@ -225,6 +225,10 @@ class WatchRule(object):
return []
return self.run_rule()
def get_details(self):
return {'alarm': self.name,
'state': self.state}
def run_rule(self):
new_state = self.get_alarm_state()
actions = self.rule_actions(new_state)
@ -247,7 +251,7 @@ class WatchRule(object):
if (stack.action != stack.DELETE
and stack.status == stack.COMPLETE):
for a in self.rule[self.ACTION_MAP[new_state]]:
actions.append(stack[a].alarm)
actions.append(stack[a].signal)
else:
logger.warning("Could not process watch state %s for stack" %
new_state)

View File

@ -942,7 +942,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -972,7 +972,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
down_policy = self.create_scaling_policy(t, stack,
'WebServerScaleDownPolicy')
down_policy.alarm()
down_policy.signal()
self.assertEqual('WebServerGroup-0', rsrc.resource_id)
rsrc.delete()
@ -999,7 +999,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1022,7 +1022,7 @@ class AutoScalingTest(HeatTestCase):
).AndReturn(previous_meta)
self.m.ReplayAll()
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1050,7 +1050,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1072,7 +1072,7 @@ class AutoScalingTest(HeatTestCase):
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
rsrc.resource_id)
@ -1102,7 +1102,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1122,7 +1122,7 @@ class AutoScalingTest(HeatTestCase):
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
rsrc.resource_id)
@ -1154,7 +1154,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1174,7 +1174,7 @@ class AutoScalingTest(HeatTestCase):
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
rsrc.resource_id)
@ -1206,7 +1206,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
# Trigger alarm
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
@ -1237,7 +1237,7 @@ class AutoScalingTest(HeatTestCase):
self.m.ReplayAll()
# Trigger alarm
up_policy.alarm()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,'
'WebServerGroup-2,WebServerGroup-3',
rsrc.resource_id)

View File

@ -1341,7 +1341,7 @@ class StackServiceTest(HeatTestCase):
self.wr.store()
class DummyAction(object):
alarm = "dummyfoo"
signal = "dummyfoo"
dummy_action = DummyAction()
self.m.StubOutWithMock(parser.Stack, '__getitem__')
@ -1373,7 +1373,7 @@ class StackServiceTest(HeatTestCase):
watch_name="OverrideAlarm",
state=state)
self.assertEqual(state, result[engine_api.WATCH_STATE_VALUE])
self.assertEqual([DummyAction.alarm],
self.assertEqual([DummyAction.signal],
self.eng.stg[self.stack.id].threads)
self.m.VerifyAll()

View File

@ -34,7 +34,7 @@ class WatchData(object):
class DummyAction(object):
alarm = "DummyAction"
signal = "DummyAction"
class WatchRuleTest(HeatTestCase):