def test_adopt_stack(self):
    adopt_data = '{\n        "action": "CREATE",\n        "status": "COMPLETE",\n        "name": "my-test-stack-name",\n        "resources": {\n        "AResource": {\n        "status": "COMPLETE",\n        "name": "AResource",\n        "resource_data": {},\n        "metadata": {},\n        "resource_id": "test-res-id",\n        "action": "CREATE",\n        "type": "GenericResourceType"\n          }\n         }\n        }'
    tmpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}, 'Outputs': {'TestOutput': {'Value': {'Fn::GetAtt': ['AResource', 'Foo']}}}}
    self.stack = stack.Stack(utils.dummy_context(), 'test_stack', template.Template(tmpl), adopt_stack_data=json.loads(adopt_data))
    self.stack.store()
    self.stack.adopt()
    res = self.stack['AResource']
    self.assertEqual(u'test-res-id', res.resource_id)
    self.assertEqual('AResource', res.name)
    self.assertEqual('COMPLETE', res.status)
    self.assertEqual('ADOPT', res.action)
    self.assertEqual((self.stack.ADOPT, self.stack.COMPLETE), self.stack.state)
    loaded_stack = stack.Stack.load(self.ctx, self.stack.id)
    loaded_stack._update_all_resource_data(False, True)
    self.assertEqual('AResource', loaded_stack.outputs['TestOutput'].get_value())
    self.assertIsNone(loaded_stack['AResource']._stored_properties_data)
def test_adopt_stack(self):
    adopt_data = '{\n        "action": "CREATE",\n        "status": "COMPLETE",\n        "name": "my-test-stack-name",\n        "resources": {\n        "AResource": {\n        "status": "COMPLETE",\n        "name": "AResource",\n        "resource_data": {},\n        "metadata": {},\n        "resource_id": "test-res-id",\n        "action": "CREATE",\n        "type": "GenericResourceType"\n          }\n         }\n        }'
    tmpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}, 'Outputs': {'TestOutput': {'Value': {'Fn::GetAtt': ['AResource', 'Foo']}}}}
    self.stack = stack.Stack(utils.dummy_context(), 'test_stack', template.Template(tmpl), adopt_stack_data=json.loads(adopt_data))
    self.stack.store()
    self.stack.adopt()
    res = self.stack['AResource']
    self.assertEqual(u'test-res-id', res.resource_id)
    self.assertEqual('AResource', res.name)
    self.assertEqual('COMPLETE', res.status)
    self.assertEqual('ADOPT', res.action)
    self.assertEqual((self.stack.ADOPT, self.stack.COMPLETE), self.stack.state)
    loaded_stack = stack.Stack.load(self.ctx, self.stack.id)
    loaded_stack._update_all_resource_data(False, True)
    self.assertEqual('AResource', loaded_stack.outputs['TestOutput'].get_value())
    self.assertIsNone(loaded_stack['AResource']._stored_properties_data)