Don't load nested stack in batched ResourceGroup

Previously whenever we did a batched operation on a ResourceGroup, we
loaded the nested stack into memory in the local engine in order to
determine the current capacity. Change to using the GroupInspector class to
calculate the capacity using only RPC.

Change-Id: Ie4c6791bf70df01a66e49cb8ef104e8155c90443
Partial-Bug: #1731349
This commit is contained in:
Zane Bitter 2018-01-08 17:23:12 -05:00
parent ce120bfda8
commit b023fa88d1
2 changed files with 10 additions and 7 deletions

View File

@ -377,9 +377,8 @@ class ResourceGroup(stack_resource.StackResource):
candidates),
size)
def _count_black_listed(self):
def _count_black_listed(self, existing_members):
"""Return the number of current resource names that are blacklisted."""
existing_members = grouputils.get_member_names(self)
return len(self._name_blacklist() & set(existing_members))
def handle_create(self):
@ -679,11 +678,12 @@ class ResourceGroup(stack_resource.StackResource):
while not duration.expired():
yield
# blacklist count existing
num_blacklist = self._count_black_listed()
# current capacity not including existing blacklisted
curr_cap = len(self.nested()) - num_blacklist if self.nested() else 0
inspector = grouputils.GroupInspector.from_parent_resource(self)
num_blacklist = self._count_black_listed(
inspector.member_names(include_failed=False))
num_resources = inspector.size(include_failed=True)
curr_cap = num_resources - num_blacklist
batches = list(self._get_batches(self.get_size(), curr_cap, batch_size,
min_in_service))

View File

@ -573,6 +573,7 @@ class ResourceGroupTest(common.HeatTestCase):
def test_handle_create_with_batching(self):
self.inspector.member_names.return_value = []
self.inspector.size.return_value = 0
stack = utils.parse_stack(tmpl_with_default_updt_policy())
defn = stack.t.resource_definitions(stack)['group1']
props = stack.t.t['resources']['group1']['properties'].copy()
@ -586,6 +587,7 @@ class ResourceGroupTest(common.HeatTestCase):
def test_handle_create_with_batching_zero_count(self):
self.inspector.member_names.return_value = []
self.inspector.size.return_value = 0
stack = utils.parse_stack(tmpl_with_default_updt_policy())
defn = stack.t.resource_definitions(stack)['group1']
props = stack.t.t['resources']['group1']['properties'].copy()
@ -997,6 +999,7 @@ class ReplaceTest(common.HeatTestCase):
self.patchobject(grouputils.GroupInspector, 'from_parent_resource',
return_value=inspector)
inspector.member_names.return_value = self.existing
inspector.size.return_value = len(self.existing)
def test_rolling_updates(self):
self.group._nested = get_fake_nested_stack(self.existing)
@ -1224,7 +1227,7 @@ class TestUtils(common.HeatTestCase):
snip = stack.t.resource_definitions(stack)['group1']
resgrp = resource_group.ResourceGroup('test', snip, stack)
resgrp._name_blacklist = mock.Mock(return_value=set(self.black_listed))
rcount = resgrp._count_black_listed()
rcount = resgrp._count_black_listed(self.existing)
self.assertEqual(self.count, rcount)