def test_resource_by_refid(self):
    tmpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'resource_by_refid_stack', template.Template(tmpl))
    self.stack.store()
    self.stack.create()
    self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE), self.stack.state)
    self.assertIn('AResource', self.stack)
    rsrc = self.stack['AResource']
    rsrc.resource_id_set('aaaa')
    for (action, status) in ((rsrc.INIT, rsrc.COMPLETE), (rsrc.CREATE, rsrc.IN_PROGRESS), (rsrc.CREATE, rsrc.COMPLETE), (rsrc.RESUME, rsrc.IN_PROGRESS), (rsrc.RESUME, rsrc.COMPLETE), (rsrc.UPDATE, rsrc.IN_PROGRESS), (rsrc.UPDATE, rsrc.COMPLETE), (rsrc.CHECK, rsrc.COMPLETE)):
        rsrc.state_set(action, status)
        stk_defn.update_resource_data(self.stack.defn, rsrc.name, rsrc.node_data())
        self.assertEqual(rsrc, self.stack.resource_by_refid('aaaa'))
    rsrc.state_set(rsrc.DELETE, rsrc.IN_PROGRESS)
    stk_defn.update_resource_data(self.stack.defn, rsrc.name, rsrc.node_data())
    try:
        self.assertIsNone(self.stack.resource_by_refid('aaaa'))
        self.assertIsNone(self.stack.resource_by_refid('bbbb'))
    finally:
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE)
def test_resource_by_refid(self):
    tmpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'resource_by_refid_stack', template.Template(tmpl))
    self.stack.store()
    self.stack.create()
    self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE), self.stack.state)
    self.assertIn('AResource', self.stack)
    rsrc = self.stack['AResource']
    rsrc.resource_id_set('aaaa')
    for (action, status) in ((rsrc.INIT, rsrc.COMPLETE), (rsrc.CREATE, rsrc.IN_PROGRESS), (rsrc.CREATE, rsrc.COMPLETE), (rsrc.RESUME, rsrc.IN_PROGRESS), (rsrc.RESUME, rsrc.COMPLETE), (rsrc.UPDATE, rsrc.IN_PROGRESS), (rsrc.UPDATE, rsrc.COMPLETE), (rsrc.CHECK, rsrc.COMPLETE)):
        rsrc.state_set(action, status)
        stk_defn.update_resource_data(self.stack.defn, rsrc.name, rsrc.node_data())
        self.assertEqual(rsrc, self.stack.resource_by_refid('aaaa'))
    rsrc.state_set(rsrc.DELETE, rsrc.IN_PROGRESS)
    stk_defn.update_resource_data(self.stack.defn, rsrc.name, rsrc.node_data())
    try:
        self.assertIsNone(self.stack.resource_by_refid('aaaa'))
        self.assertIsNone(self.stack.resource_by_refid('bbbb'))
    finally:
        rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE)