Make HARestarter do a proper lookup of the RefID
HARestarter is a primitive prototype that is barely maintained. Its implementation still dates to the era when the resource name, physical resource ID and RefId were regularly used interchangably. This change substitutes Stack.resource_by_refid() for the previous (incorrect) home-grown hack, so that at least the giant red flags will be easy to grep for. Change-Id: I9d81dfcd5d34282c8bd83bbd98350e75c1ec0eb2 Closes-Bug: #1381136
This commit is contained in:
parent
78c9e0f67a
commit
c4dd7d70b5
|
@ -60,16 +60,6 @@ class Restarter(signal_responder.SignalResponder):
|
|||
),
|
||||
}
|
||||
|
||||
def _find_resource(self, resource_id):
|
||||
'''
|
||||
Return the resource with the specified instance ID, or None if it
|
||||
cannot be found.
|
||||
'''
|
||||
for resource in self.stack.itervalues():
|
||||
if resource.resource_id == resource_id:
|
||||
return resource
|
||||
return None
|
||||
|
||||
def handle_create(self):
|
||||
super(Restarter, self).handle_create()
|
||||
self.resource_id_set(self._get_user_id())
|
||||
|
@ -90,12 +80,13 @@ class Restarter(signal_responder.SignalResponder):
|
|||
if alarm_state != 'alarm':
|
||||
return
|
||||
|
||||
victim = self._find_resource(self.properties[self.INSTANCE_ID])
|
||||
target_id = self.properties[self.INSTANCE_ID]
|
||||
victim = self.stack.resource_by_refid(target_id)
|
||||
if victim is None:
|
||||
LOG.info(_LI('%(name)s Alarm, can not find instance '
|
||||
'%(instance)s'),
|
||||
{'name': self.name,
|
||||
'instance': self.properties[self.INSTANCE_ID]})
|
||||
'instance': target_id})
|
||||
return
|
||||
|
||||
LOG.info(_LI('%(name)s Alarm, restarting resource: %(victim)s'),
|
||||
|
|
|
@ -54,6 +54,10 @@ class RestarterTest(common.HeatTestCase):
|
|||
inst = mock.Mock(spec=instance.Instance)
|
||||
inst.resource_id = '1234'
|
||||
inst.name = 'instance'
|
||||
inst.action = inst.CREATE
|
||||
inst.status = inst.COMPLETE
|
||||
inst.state = (inst.action, inst.status)
|
||||
inst.FnGetRefId = lambda: inst.resource_id
|
||||
stack.resources['instance'] = inst
|
||||
|
||||
def test_create(self):
|
||||
|
|
Loading…
Reference in New Issue