Merge "ResourceGroup update refactor"
This commit is contained in:
commit
5683185f2a
@ -150,9 +150,8 @@ class ResourceGroup(stack_resource.StackResource):
|
||||
self.stack)
|
||||
res_inst.validate()
|
||||
|
||||
def _resource_names(self, properties=None):
|
||||
p = properties or self.properties
|
||||
return [str(n) for n in range(p.get(self.COUNT, 0))]
|
||||
def _resource_names(self):
|
||||
return [str(n) for n in range(self.properties.get(self.COUNT))]
|
||||
|
||||
def handle_create(self):
|
||||
names = self._resource_names()
|
||||
@ -162,14 +161,18 @@ class ResourceGroup(stack_resource.StackResource):
|
||||
{},
|
||||
self.stack.timeout_mins)
|
||||
|
||||
def handle_update(self, new_snippet, tmpl_diff, prop_diff):
|
||||
old_names = self._resource_names()
|
||||
new_names = self._resource_names(prop_diff)
|
||||
if old_names != new_names:
|
||||
return self.update_with_template(
|
||||
self._assemble_nested(new_names),
|
||||
{},
|
||||
self.stack.timeout_mins)
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
if prop_diff:
|
||||
old_names = self._resource_names()
|
||||
self.properties = json_snippet.properties(self.properties_schema,
|
||||
self.context)
|
||||
|
||||
new_names = self._resource_names()
|
||||
if old_names != new_names:
|
||||
return self.update_with_template(
|
||||
self._assemble_nested(new_names),
|
||||
{},
|
||||
self.stack.timeout_mins)
|
||||
|
||||
def handle_delete(self):
|
||||
return self.delete_nested()
|
||||
|
@ -565,9 +565,8 @@ class SoftwareDeployments(resource_group.ResourceGroup):
|
||||
),
|
||||
}
|
||||
|
||||
def _resource_names(self, properties=None):
|
||||
p = properties or self.properties
|
||||
return p.get(self.SERVERS, {}).keys()
|
||||
def _resource_names(self):
|
||||
return self.properties.get(self.SERVERS, {}).keys()
|
||||
|
||||
def _do_prop_replace(self, res_name, res_def_template):
|
||||
res_def = copy.deepcopy(res_def_template)
|
||||
|
@ -359,6 +359,10 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
def test_update(self):
|
||||
"""Test basic update."""
|
||||
resg = self._create_dummy_stack()
|
||||
self.assertEqual(2, len(resg.nested()))
|
||||
resource_names = [r.name for r in resg.nested().iter_resources()]
|
||||
self.assertEqual(['0', '1'], sorted(resource_names))
|
||||
old_snip = copy.deepcopy(resg.t)
|
||||
new_snip = copy.deepcopy(resg.t)
|
||||
new_snip['Properties']['count'] = 3
|
||||
scheduler.TaskRunner(resg.update, new_snip)()
|
||||
@ -366,6 +370,14 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state)
|
||||
self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state)
|
||||
self.assertEqual(3, len(resg.nested()))
|
||||
resource_names = [r.name for r in resg.nested().iter_resources()]
|
||||
self.assertEqual(['0', '1', '2'], sorted(resource_names))
|
||||
scheduler.TaskRunner(resg.update, old_snip)()
|
||||
self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.state)
|
||||
self.assertEqual((resg.UPDATE, resg.COMPLETE), resg.nested().state)
|
||||
self.assertEqual(2, len(resg.nested()))
|
||||
resource_names = [r.name for r in resg.nested().iter_resources()]
|
||||
self.assertEqual(['0', '1'], sorted(resource_names))
|
||||
|
||||
def test_aggregate_attribs(self):
|
||||
"""
|
||||
|
@ -835,11 +835,10 @@ class SoftwareDeploymentsTest(HeatTestCase):
|
||||
set(resg._resource_names())
|
||||
)
|
||||
|
||||
resg.properties = {'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}}
|
||||
self.assertEqual(
|
||||
set(('s1', 's2', 's3')),
|
||||
set(resg._resource_names({
|
||||
'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}}))
|
||||
)
|
||||
set(resg._resource_names()))
|
||||
|
||||
def test_assemble_nested(self):
|
||||
"""
|
||||
|
@ -246,11 +246,10 @@ class StructuredDeploymentsTest(HeatTestCase):
|
||||
set(resg._resource_names())
|
||||
)
|
||||
|
||||
resg.properties = {'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}}
|
||||
self.assertEqual(
|
||||
set(('s1', 's2', 's3')),
|
||||
set(resg._resource_names({
|
||||
'servers': {'s1': 'u1', 's2': 'u2', 's3': 'u3'}}))
|
||||
)
|
||||
set(resg._resource_names()))
|
||||
|
||||
def test_assemble_nested(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user