Move function for member_definitions to grouputil
Change-Id: If07573ad833fd45860247aca8d350bf7104f3f52
This commit is contained in:
parent
8df756e150
commit
33093f42df
@ -98,3 +98,12 @@ def get_nested_attrs(stack, key, use_indices, *path):
|
|||||||
return get_rsrc_attr(stack, key, use_indices, *path)
|
return get_rsrc_attr(stack, key, use_indices, *path)
|
||||||
else:
|
else:
|
||||||
return get_rsrc_id(stack, key, use_indices, *path)
|
return get_rsrc_id(stack, key, use_indices, *path)
|
||||||
|
|
||||||
|
|
||||||
|
def get_member_definitions(group):
|
||||||
|
"""Get member definitions in (name, ResourceDefinition) pair for group.
|
||||||
|
|
||||||
|
The List is sorted first by created_time then by name.
|
||||||
|
"""
|
||||||
|
return [(resource.name, resource.t)
|
||||||
|
for resource in get_members(group)]
|
||||||
|
@ -246,11 +246,6 @@ class InstanceGroup(stack_resource.StackResource):
|
|||||||
props,
|
props,
|
||||||
conf.t.metadata())
|
conf.t.metadata())
|
||||||
|
|
||||||
def _get_instance_templates(self):
|
|
||||||
"""Get templates for resource instances."""
|
|
||||||
return [(instance.name, instance.t)
|
|
||||||
for instance in grouputils.get_members(self)]
|
|
||||||
|
|
||||||
def _create_template(self, num_instances, num_replace=0,
|
def _create_template(self, num_instances, num_replace=0,
|
||||||
template_version=('HeatTemplateFormatVersion',
|
template_version=('HeatTemplateFormatVersion',
|
||||||
'2012-12-12')):
|
'2012-12-12')):
|
||||||
@ -259,7 +254,7 @@ class InstanceGroup(stack_resource.StackResource):
|
|||||||
Also see heat.scaling.template.member_definitions.
|
Also see heat.scaling.template.member_definitions.
|
||||||
"""
|
"""
|
||||||
instance_definition = self._get_resource_definition()
|
instance_definition = self._get_resource_definition()
|
||||||
old_resources = self._get_instance_templates()
|
old_resources = grouputils.get_member_definitions(self)
|
||||||
definitions = template.member_definitions(
|
definitions = template.member_definitions(
|
||||||
old_resources, instance_definition, num_instances, num_replace,
|
old_resources, instance_definition, num_instances, num_replace,
|
||||||
short_id.generate_id)
|
short_id.generate_id)
|
||||||
|
@ -341,11 +341,6 @@ class ResourceGroup(stack_resource.StackResource):
|
|||||||
candidates),
|
candidates),
|
||||||
size)
|
size)
|
||||||
|
|
||||||
def _get_resources(self):
|
|
||||||
"""Get definitions for resources."""
|
|
||||||
return [(resource.name, resource.t)
|
|
||||||
for resource in grouputils.get_members(self)]
|
|
||||||
|
|
||||||
def _count_black_listed(self):
|
def _count_black_listed(self):
|
||||||
"""Return the number of current resource names that are blacklisted"""
|
"""Return the number of current resource names that are blacklisted"""
|
||||||
existing_members = grouputils.get_member_names(self)
|
existing_members = grouputils.get_member_names(self)
|
||||||
@ -497,7 +492,8 @@ class ResourceGroup(stack_resource.StackResource):
|
|||||||
names = list(self._resource_names(total_capacity))
|
names = list(self._resource_names(total_capacity))
|
||||||
name_blacklist = self._name_blacklist()
|
name_blacklist = self._name_blacklist()
|
||||||
|
|
||||||
valid_resources = [(n, d) for n, d in self._get_resources()
|
valid_resources = [(n, d) for n, d in
|
||||||
|
grouputils.get_member_definitions(self)
|
||||||
if n not in name_blacklist]
|
if n not in name_blacklist]
|
||||||
|
|
||||||
targ_cap = self.get_size()
|
targ_cap = self.get_size()
|
||||||
|
@ -16,6 +16,7 @@ import six
|
|||||||
|
|
||||||
from heat.common import grouputils
|
from heat.common import grouputils
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine import rsrc_defn
|
||||||
from heat.tests import common
|
from heat.tests import common
|
||||||
from heat.tests import utils
|
from heat.tests import utils
|
||||||
|
|
||||||
@ -44,7 +45,6 @@ class GroupUtilsTest(common.HeatTestCase):
|
|||||||
group = mock.Mock()
|
group = mock.Mock()
|
||||||
t = template_format.parse(nested_stack)
|
t = template_format.parse(nested_stack)
|
||||||
stack = utils.parse_stack(t)
|
stack = utils.parse_stack(t)
|
||||||
|
|
||||||
# group size
|
# group size
|
||||||
self.patchobject(group, 'nested', return_value=stack)
|
self.patchobject(group, 'nested', return_value=stack)
|
||||||
self.assertEqual(2, grouputils.get_size(group))
|
self.assertEqual(2, grouputils.get_size(group))
|
||||||
@ -62,7 +62,16 @@ class GroupUtilsTest(common.HeatTestCase):
|
|||||||
self.assertEqual(['ID-r0'], partial_ids)
|
self.assertEqual(['ID-r0'], partial_ids)
|
||||||
|
|
||||||
# names
|
# names
|
||||||
self.assertEqual(['r0', 'r1'], grouputils.get_member_names(group))
|
names = grouputils.get_member_names(group)
|
||||||
|
self.assertEqual(['r0', 'r1'], names)
|
||||||
|
|
||||||
|
# defn snippets as list
|
||||||
|
expected = rsrc_defn.ResourceDefinition(
|
||||||
|
None,
|
||||||
|
"OverwrittenFnGetRefIdType")
|
||||||
|
|
||||||
|
member_defs = grouputils.get_member_definitions(group)
|
||||||
|
self.assertEqual([(x, expected) for x in names], member_defs)
|
||||||
|
|
||||||
def test_group_with_failed_members(self):
|
def test_group_with_failed_members(self):
|
||||||
group = mock.Mock()
|
group = mock.Mock()
|
||||||
|
@ -17,6 +17,7 @@ import mock
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.common import grouputils
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import function
|
from heat.engine import function
|
||||||
from heat.engine.resources.openstack.heat import resource_group
|
from heat.engine.resources.openstack.heat import resource_group
|
||||||
@ -1383,9 +1384,9 @@ class TestGetBatches(common.HeatTestCase):
|
|||||||
|
|
||||||
resources = [(str(i), old_def) for i in range(self.init_cap + 1)]
|
resources = [(str(i), old_def) for i in range(self.init_cap + 1)]
|
||||||
self.grp.get_size = mock.Mock(return_value=self.targ_cap)
|
self.grp.get_size = mock.Mock(return_value=self.targ_cap)
|
||||||
|
self.patchobject(grouputils, 'get_member_definitions',
|
||||||
|
return_value=resources)
|
||||||
self.grp.build_resource_definition = mock.Mock(return_value=new_def)
|
self.grp.build_resource_definition = mock.Mock(return_value=new_def)
|
||||||
self.grp._get_resources = mock.Mock(return_value=resources)
|
|
||||||
|
|
||||||
all_updated_names = set()
|
all_updated_names = set()
|
||||||
|
|
||||||
for size, max_upd, names in self.batches:
|
for size, max_upd, names in self.batches:
|
||||||
|
Loading…
Reference in New Issue
Block a user