diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-09-27 17:43:44 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-09-27 17:43:45 +0000 |
commit | a0b89b9a1c1069cbdc1311a8a2d24ef46365463e (patch) | |
tree | d49b852e2f97ac4a5c0e1ff73374642467fe8583 | |
parent | 755cfb885cea36e8463f2dcdb59ff42f5127bae8 (diff) | |
parent | fc8dd31ff79ba2c0c610e7a6fad450eb10acae93 (diff) | |
download | heat-a0b89b9a1c1069cbdc1311a8a2d24ef46365463e.tar.gz |
Merge "Fixed adopt failure for stack with resource group"
-rw-r--r-- | heat/engine/resources/resource_group.py | 18 | ||||
-rw-r--r-- | heat/tests/test_resource_group.py | 54 |
2 files changed, 72 insertions, 0 deletions
diff --git a/heat/engine/resources/resource_group.py b/heat/engine/resources/resource_group.py index e24a49b24..c548018ab 100644 --- a/heat/engine/resources/resource_group.py +++ b/heat/engine/resources/resource_group.py @@ -253,6 +253,24 @@ class ResourceGroup(stack_resource.StackResource): def child_params(self): return {} + def handle_adopt(self, resource_data): + names = self._resource_names() + if names: + return self.create_with_template(self._assemble_nested(names), + {}, + adopt_data=resource_data) + + def check_adopt_complete(self, adopter): + if adopter is None: + return True + done = adopter.step() + if done: + if self._nested.state != (self._nested.ADOPT, + self._nested.COMPLETE): + raise exception.Error(self._nested.status_reason) + + return done + def resource_mapping(): return { diff --git a/heat/tests/test_resource_group.py b/heat/tests/test_resource_group.py index 448c36202..10454cfa5 100644 --- a/heat/tests/test_resource_group.py +++ b/heat/tests/test_resource_group.py @@ -14,12 +14,15 @@ import copy import mock import six +import uuid from heat.common import exception from heat.engine import properties from heat.engine import resource from heat.engine.resources import resource_group from heat.engine import scheduler +from heat.engine import stack as stackm +from heat.engine import template as templatem from heat.tests import common from heat.tests import generic_resource from heat.tests import utils @@ -480,3 +483,54 @@ class ResourceGroupTest(common.HeatTestCase): snip = stack.t.resource_definitions(stack)['group1'] resgrp = resource_group.ResourceGroup('test', snip, stack) self.assertEqual({}, resgrp.child_params()) + + def test_adopt(self): + tmpl = templatem.Template(template) + stack = stackm.Stack(utils.dummy_context(), + 'test_stack', + tmpl, + stack_id=str(uuid.uuid4())) + + resg = stack['group1'] + + adopt_data = { + "status": "COMPLETE", + "name": "group1", + "resource_data": {}, + "metadata": {}, + "resource_id": "test-group1-id", + "action": "CREATE", + "type": "OS::Heat::ResourceGroup", + "resources": { + "0": { + "status": "COMPLETE", + "name": "0", + "resource_data": {}, + "resource_id": "ID-0", + "action": "CREATE", + "type": "dummy.resource", + "metadata": {} + }, + "1": { + "status": "COMPLETE", + "name": "1", + "resource_data": {}, + "resource_id": "ID-1", + "action": "CREATE", + "type": "dummy.resource", + "metadata": {} + } + } + } + scheduler.TaskRunner(resg.adopt, adopt_data)() + self.assertEqual((resg.ADOPT, resg.COMPLETE), resg.state) + self.assertEqual(adopt_data['name'], resg.name) + # a new nested stack should be created + self.assertIsNotNone(resg.resource_id) + # verify all the resources in resource group are adopted. + self.assertEqual(adopt_data['resources']['0']['resource_id'], + resg.FnGetAtt('resource.0')) + self.assertEqual(adopt_data['resources']['1']['resource_id'], + resg.FnGetAtt('resource.1')) + self.assertRaises(exception.InvalidTemplateAttribute, resg.FnGetAtt, + 'resource.2') |