From cd927f7018463972500b311ed26fd39037b21456 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 20 Aug 2013 09:46:59 +1000 Subject: [PATCH] To support both CW and CM, return alarmurl from policy ref This is so we can still have the following: AlarmActions: - {Ref: ServerScaleUpPolicy} and use Ceilometer underneath. The watchrule now tries to look up the resource by both name and resource_by_refid. Change-Id: I4759806919ab4f3ccef66698235b23f7f310cb03 --- heat/engine/resources/autoscaling.py | 5 ++++- heat/engine/watchrule.py | 4 ++-- heat/tests/test_autoscaling.py | 5 +++++ heat/tests/test_engine_service.py | 4 ++-- heat/tests/test_watch.py | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 04987b8892..dbcf2e3a63 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -509,7 +509,10 @@ class ScalingPolicy(signal_responder.SignalResponder, CooldownMixin): return unicode(self._get_signed_url()) def FnGetRefId(self): - return unicode(self.name) + if self.resource_id is not None: + return unicode(self._get_signed_url()) + else: + return unicode(self.name) def resource_mapping(): diff --git a/heat/engine/watchrule.py b/heat/engine/watchrule.py index e791088e22..b9316b8c3e 100644 --- a/heat/engine/watchrule.py +++ b/heat/engine/watchrule.py @@ -257,8 +257,8 @@ class WatchRule(object): stack = parser.Stack.load(self.context, stack=s) if (stack.action != stack.DELETE and stack.status == stack.COMPLETE): - for a in self.rule[self.ACTION_MAP[new_state]]: - actions.append(stack[a].signal) + for refid in self.rule[self.ACTION_MAP[new_state]]: + actions.append(stack.resource_by_refid(refid).signal) else: logger.warning("Could not process watch state %s for stack" % new_state) diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index 7ea0b1c71f..5bffbe5c35 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -1299,6 +1299,11 @@ class AutoScalingTest(HeatTestCase): self._stub_lb_reload(2) self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2) self._stub_create(1) + + self.m.StubOutWithMock(asc.ScalingPolicy, 'keystone') + asc.ScalingPolicy.keystone().MultipleTimes().AndReturn( + self.fc) + self.m.ReplayAll() # Trigger alarm diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 403c5b85bf..8fd5d3d125 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -1423,8 +1423,8 @@ class StackServiceTest(HeatTestCase): signal = "dummyfoo" dummy_action = DummyAction() - self.m.StubOutWithMock(parser.Stack, '__getitem__') - parser.Stack.__getitem__( + self.m.StubOutWithMock(parser.Stack, 'resource_by_refid') + parser.Stack.resource_by_refid( 'WebServerRestartPolicy').AndReturn(dummy_action) # Replace the real stack threadgroup with a dummy one, so we can diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index 6d5fb4b384..15c07964db 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -75,9 +75,9 @@ class WatchRuleTest(HeatTestCase): if action_expected: dummy_action = DummyAction() - self.m.StubOutWithMock(parser.Stack, '__getitem__') - parser.Stack.__getitem__(mox.IgnoreArg() - ).MultipleTimes().AndReturn(dummy_action) + self.m.StubOutWithMock(parser.Stack, 'resource_by_refid') + parser.Stack.resource_by_refid(mox.IgnoreArg()).\ + MultipleTimes().AndReturn(dummy_action) self.m.ReplayAll()