Fixed adopt failure for stack with resource group

Added support to adopt a resource group and corresponding
unit test.

Change-Id: Icfeff0e30a9c4bd7fa0279e156709e078b81fcab
Closes-bug: #1353942
This commit is contained in:
Unmesh Gurjar 2014-08-21 14:28:49 +05:30
parent 9cfe20b3da
commit fc8dd31ff7
2 changed files with 72 additions and 0 deletions

View File

@ -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 {

View File

@ -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')