Use 'skiplist' to describe skipped indices in ResourceGroup code

Don't use needlessly divisive terminology.

Change-Id: I86a06cd2c5cebcc3d2cd07b675f626a917bb9db4
This commit is contained in:
Zane Bitter 2020-07-14 09:44:13 -04:00
parent 9f931119ba
commit 24bae944dc
3 changed files with 86 additions and 86 deletions

View File

@ -322,24 +322,24 @@ class ResourceGroup(stack_resource.StackResource):
raise exception.StackValidationFailed( raise exception.StackValidationFailed(
ex, path=[self.stack.t.RESOURCES, path]) ex, path=[self.stack.t.RESOURCES, path])
def _current_blacklist(self): def _current_skiplist(self):
db_rsrc_names = self.data().get('name_blacklist') db_rsrc_names = self.data().get('name_blacklist')
if db_rsrc_names: if db_rsrc_names:
return db_rsrc_names.split(',') return db_rsrc_names.split(',')
else: else:
return [] return []
def _get_new_blacklist_entries(self, properties, current_blacklist): def _get_new_skiplist_entries(self, properties, current_skiplist):
insp = grouputils.GroupInspector.from_parent_resource(self) insp = grouputils.GroupInspector.from_parent_resource(self)
# Now we iterate over the removal policies, and update the blacklist # Now we iterate over the removal policies, and update the skiplist
# with any additional names # with any additional names
for r in properties.get(self.REMOVAL_POLICIES, []): for r in properties.get(self.REMOVAL_POLICIES, []):
if self.REMOVAL_RSRC_LIST in r: if self.REMOVAL_RSRC_LIST in r:
# Tolerate string or int list values # Tolerate string or int list values
for n in r[self.REMOVAL_RSRC_LIST]: for n in r[self.REMOVAL_RSRC_LIST]:
str_n = str(n) str_n = str(n)
if (str_n in current_blacklist or if (str_n in current_skiplist or
self.resource_id is None or self.resource_id is None or
str_n in insp.member_names(include_failed=True)): str_n in insp.member_names(include_failed=True)):
yield str_n yield str_n
@ -364,52 +364,52 @@ class ResourceGroup(stack_resource.StackResource):
# outdated values after stack update. # outdated values after stack update.
self._outputs = None self._outputs = None
def _update_name_blacklist(self, properties): def _update_name_skiplist(self, properties):
"""Resolve the remove_policies to names for removal.""" """Resolve the remove_policies to names for removal."""
# To avoid reusing names after removal, we store a comma-separated # To avoid reusing names after removal, we store a comma-separated
# blacklist in the resource data - in cases where you want to # skiplist in the resource data - in cases where you want to
# overwrite the stored data, removal_policies_mode: update can be used # overwrite the stored data, removal_policies_mode: update can be used
curr_bl = set(self._current_blacklist()) curr_sl = set(self._current_skiplist())
p_mode = properties.get(self.REMOVAL_POLICIES_MODE, p_mode = properties.get(self.REMOVAL_POLICIES_MODE,
self.REMOVAL_POLICY_APPEND) self.REMOVAL_POLICY_APPEND)
if p_mode == self.REMOVAL_POLICY_UPDATE: if p_mode == self.REMOVAL_POLICY_UPDATE:
init_bl = set() init_sl = set()
else: else:
init_bl = curr_bl init_sl = curr_sl
updated_bl = init_bl | set(self._get_new_blacklist_entries(properties, updated_sl = init_sl | set(self._get_new_skiplist_entries(properties,
curr_bl)) curr_sl))
# If the blacklist has changed, update the resource data # If the skiplist has changed, update the resource data
if updated_bl != curr_bl: if updated_sl != curr_sl:
self.data_set('name_blacklist', ','.join(sorted(updated_bl))) self.data_set('name_blacklist', ','.join(sorted(updated_sl)))
def _name_blacklist(self): def _name_skiplist(self):
"""Get the list of resource names to blacklist.""" """Get the list of resource names to skiplist."""
bl = set(self._current_blacklist()) sl = set(self._current_skiplist())
if self.resource_id is None: if self.resource_id is None:
bl |= set(self._get_new_blacklist_entries(self.properties, bl)) sl |= set(self._get_new_skiplist_entries(self.properties, sl))
return bl return sl
def _resource_names(self, size=None): def _resource_names(self, size=None):
name_blacklist = self._name_blacklist() name_skiplist = self._name_skiplist()
if size is None: if size is None:
size = self.get_size() size = self.get_size()
def is_blacklisted(name): def is_skipped(name):
return name in name_blacklist return name in name_skiplist
candidates = map(str, itertools.count()) candidates = map(str, itertools.count())
return itertools.islice(itertools.filterfalse(is_blacklisted, return itertools.islice(itertools.filterfalse(is_skipped,
candidates), candidates),
size) size)
def _count_black_listed(self, existing_members): def _count_skipped(self, existing_members):
"""Return the number of current resource names that are blacklisted.""" """Return the number of current resource names that are skipped."""
return len(self._name_blacklist() & set(existing_members)) return len(self._name_skiplist() & set(existing_members))
def handle_create(self): def handle_create(self):
self._update_name_blacklist(self.properties) self._update_name_skiplist(self.properties)
if self.update_policy.get(self.BATCH_CREATE) and self.get_size(): if self.update_policy.get(self.BATCH_CREATE) and self.get_size():
batch_create = self.update_policy[self.BATCH_CREATE] batch_create = self.update_policy[self.BATCH_CREATE]
max_batch_size = batch_create[self.MAX_BATCH_SIZE] max_batch_size = batch_create[self.MAX_BATCH_SIZE]
@ -468,7 +468,7 @@ class ResourceGroup(stack_resource.StackResource):
checkers = [] checkers = []
self.properties = json_snippet.properties(self.properties_schema, self.properties = json_snippet.properties(self.properties_schema,
self.context) self.context)
self._update_name_blacklist(self.properties) self._update_name_skiplist(self.properties)
if prop_diff and self.res_def_changed(prop_diff): if prop_diff and self.res_def_changed(prop_diff):
updaters = self._try_rolling_update() updaters = self._try_rolling_update()
if updaters: if updaters:
@ -491,7 +491,7 @@ class ResourceGroup(stack_resource.StackResource):
def get_attribute(self, key, *path): def get_attribute(self, key, *path):
if key == self.REMOVED_RSRC_LIST: if key == self.REMOVED_RSRC_LIST:
return self._current_blacklist() return self._current_skiplist()
if key == self.ATTR_ATTRIBUTES and not path: if key == self.ATTR_ATTRIBUTES and not path:
raise exception.InvalidTemplateAttribute(resource=self.name, raise exception.InvalidTemplateAttribute(resource=self.name,
key=key) key=key)
@ -680,11 +680,11 @@ class ResourceGroup(stack_resource.StackResource):
template_version=('heat_template_version', template_version=('heat_template_version',
'2015-04-30')): '2015-04-30')):
names = list(self._resource_names(total_capacity)) names = list(self._resource_names(total_capacity))
name_blacklist = self._name_blacklist() name_skiplist = self._name_skiplist()
valid_resources = [(n, d) for n, d in valid_resources = [(n, d) for n, d in
grouputils.get_member_definitions(self) grouputils.get_member_definitions(self)
if n not in name_blacklist] if n not in name_skiplist]
targ_cap = self.get_size() targ_cap = self.get_size()
@ -728,7 +728,7 @@ class ResourceGroup(stack_resource.StackResource):
def _resolve_attribute(self, name): def _resolve_attribute(self, name):
if name == self.REMOVED_RSRC_LIST: if name == self.REMOVED_RSRC_LIST:
return self._current_blacklist() return self._current_skiplist()
def _update_timeout(self, batch_cnt, pause_sec): def _update_timeout(self, batch_cnt, pause_sec):
total_pause_time = pause_sec * max(batch_cnt - 1, 0) total_pause_time = pause_sec * max(batch_cnt - 1, 0)
@ -761,12 +761,12 @@ class ResourceGroup(stack_resource.StackResource):
while not duration.expired(): while not duration.expired():
yield yield
# current capacity not including existing blacklisted # current capacity not including existing skiplisted
inspector = grouputils.GroupInspector.from_parent_resource(self) inspector = grouputils.GroupInspector.from_parent_resource(self)
num_blacklist = self._count_black_listed( num_skiplist = self._count_skipped(
inspector.member_names(include_failed=False)) inspector.member_names(include_failed=False))
num_resources = inspector.size(include_failed=True) num_resources = inspector.size(include_failed=True)
curr_cap = num_resources - num_blacklist curr_cap = num_resources - num_skiplist
batches = list(self._get_batches(self.get_size(), curr_cap, batch_size, batches = list(self._get_batches(self.get_size(), curr_cap, batch_size,
min_in_service)) min_in_service))

View File

@ -709,10 +709,10 @@ class SoftwareDeploymentGroup(resource_group.ResourceGroup):
def res_def_changed(self, prop_diff): def res_def_changed(self, prop_diff):
return True return True
def _update_name_blacklist(self, properties): def _update_name_skiplist(self, properties):
pass pass
def _name_blacklist(self): def _name_skiplist(self):
return set() return set()
def get_resource_def(self, include_all=False): def get_resource_def(self, include_all=False):

View File

@ -648,7 +648,7 @@ class ResourceGroupTest(common.HeatTestCase):
resg = stack.resources['group1'] resg = stack.resources['group1']
self.assertIsNone(resg.validate()) self.assertIsNone(resg.validate())
def test_validate_with_blacklist(self): def test_validate_with_skiplist(self):
templ = copy.deepcopy(template_server) templ = copy.deepcopy(template_server)
self.mock_flavor = mock.Mock(ram=4, disk=4) self.mock_flavor = mock.Mock(ram=4, disk=4)
self.mock_active_image = mock.Mock(min_ram=1, min_disk=1, self.mock_active_image = mock.Mock(min_ram=1, min_disk=1,
@ -822,11 +822,11 @@ class ResourceGroupTest(common.HeatTestCase):
self.assertTrue(resgrp._assemble_nested.called) self.assertTrue(resgrp._assemble_nested.called)
class ResourceGroupBlackList(common.HeatTestCase): class ResourceGroupSkiplistTest(common.HeatTestCase):
"""This class tests ResourceGroup._name_blacklist().""" """This class tests ResourceGroup._name_skiplist()."""
# 1) no resource_list, empty blacklist # 1) no resource_list, empty skiplist
# 2) no resource_list, existing blacklist # 2) no resource_list, existing skiplist
# 3) resource_list not in nested() # 3) resource_list not in nested()
# 4) resource_list (refid) not in nested() # 4) resource_list (refid) not in nested()
# 5) resource_list in nested() -> saved # 5) resource_list in nested() -> saved
@ -876,7 +876,7 @@ class ResourceGroupBlackList(common.HeatTestCase):
saved=True, fallback=True, rm_mode='update')), saved=True, fallback=True, rm_mode='update')),
] ]
def test_blacklist(self): def test_skiplist(self):
stack = utils.parse_stack(template) stack = utils.parse_stack(template)
resg = stack['group1'] resg = stack['group1']
@ -923,13 +923,13 @@ class ResourceGroupBlackList(common.HeatTestCase):
nested.resource_by_refid.side_effect = by_refid nested.resource_by_refid.side_effect = by_refid
resg.nested = mock.Mock(return_value=nested) resg.nested = mock.Mock(return_value=nested)
resg._update_name_blacklist(properties) resg._update_name_skiplist(properties)
if self.saved: if self.saved:
resg.data_set.assert_called_once_with('name_blacklist', resg.data_set.assert_called_once_with('name_blacklist',
','.join(self.expected)) ','.join(self.expected))
else: else:
resg.data_set.assert_not_called() resg.data_set.assert_not_called()
self.assertEqual(set(self.expected), resg._name_blacklist()) self.assertEqual(set(self.expected), resg._name_skiplist())
class ResourceGroupEmptyParams(common.HeatTestCase): class ResourceGroupEmptyParams(common.HeatTestCase):
@ -979,18 +979,18 @@ class ResourceGroupEmptyParams(common.HeatTestCase):
class ResourceGroupNameListTest(common.HeatTestCase): class ResourceGroupNameListTest(common.HeatTestCase):
"""This class tests ResourceGroup._resource_names().""" """This class tests ResourceGroup._resource_names()."""
# 1) no blacklist, 0 count # 1) no skiplist, 0 count
# 2) no blacklist, x count # 2) no skiplist, x count
# 3) blacklist (not effecting) # 3) skiplist (not effecting)
# 4) blacklist with pruning # 4) skiplist with pruning
scenarios = [ scenarios = [
('1', dict(blacklist=[], count=0, ('1', dict(skiplist=[], count=0,
expected=[])), expected=[])),
('2', dict(blacklist=[], count=4, ('2', dict(skiplist=[], count=4,
expected=['0', '1', '2', '3'])), expected=['0', '1', '2', '3'])),
('3', dict(blacklist=['5', '6'], count=3, ('3', dict(skiplist=['5', '6'], count=3,
expected=['0', '1', '2'])), expected=['0', '1', '2'])),
('4', dict(blacklist=['2', '4'], count=4, ('4', dict(skiplist=['2', '4'], count=4,
expected=['0', '1', '3', '5'])), expected=['0', '1', '3', '5'])),
] ]
@ -1000,7 +1000,7 @@ class ResourceGroupNameListTest(common.HeatTestCase):
resg.properties = mock.MagicMock() resg.properties = mock.MagicMock()
resg.properties.get.return_value = self.count resg.properties.get.return_value = self.count
resg._name_blacklist = mock.MagicMock(return_value=self.blacklist) resg._name_skiplist = mock.MagicMock(return_value=self.skiplist)
self.assertEqual(self.expected, list(resg._resource_names())) self.assertEqual(self.expected, list(resg._resource_names()))
@ -1115,7 +1115,7 @@ class ResourceGroupAttrTest(common.HeatTestCase):
rsrc = stack.defn['group1'] rsrc = stack.defn['group1']
self.assertEqual(['rsrc1', 'rsrc2'], rsrc.FnGetAtt('refs')) self.assertEqual(['rsrc1', 'rsrc2'], rsrc.FnGetAtt('refs'))
def test_get_attribute_blacklist(self): def test_get_attribute_skiplist(self):
resg = self._create_dummy_stack() resg = self._create_dummy_stack()
resg.data = mock.Mock(return_value={'name_blacklist': '3,5'}) resg.data = mock.Mock(return_value={'name_blacklist': '3,5'})
@ -1201,48 +1201,48 @@ class ResourceGroupAttrFallbackTest(ResourceGroupAttrTest):
class ReplaceTest(common.HeatTestCase): class ReplaceTest(common.HeatTestCase):
# 1. no min_in_service # 1. no min_in_service
# 2. min_in_service > count and existing with no blacklist # 2. min_in_service > count and existing with no skiplist
# 3. min_in_service > count and existing with blacklist # 3. min_in_service > count and existing with skiplist
# 4. existing > count and min_in_service with blacklist # 4. existing > count and min_in_service with skiplist
# 5. existing > count and min_in_service with no blacklist # 5. existing > count and min_in_service with no skiplist
# 6. all existing blacklisted # 6. all existing skipped
# 7. count > existing and min_in_service with no blacklist # 7. count > existing and min_in_service with no skiplist
# 8. count > existing and min_in_service with blacklist # 8. count > existing and min_in_service with skiplist
# 9. count < existing - blacklisted # 9. count < existing - skiplisted
# 10. pause_sec > 0 # 10. pause_sec > 0
scenarios = [ scenarios = [
('1', dict(min_in_service=0, count=2, ('1', dict(min_in_service=0, count=2,
existing=['0', '1'], black_listed=['0'], existing=['0', '1'], skipped=['0'],
batch_size=1, pause_sec=0, tasks=2)), batch_size=1, pause_sec=0, tasks=2)),
('2', dict(min_in_service=3, count=2, ('2', dict(min_in_service=3, count=2,
existing=['0', '1'], black_listed=[], existing=['0', '1'], skipped=[],
batch_size=2, pause_sec=0, tasks=3)), batch_size=2, pause_sec=0, tasks=3)),
('3', dict(min_in_service=3, count=2, ('3', dict(min_in_service=3, count=2,
existing=['0', '1'], black_listed=['0'], existing=['0', '1'], skipped=['0'],
batch_size=2, pause_sec=0, tasks=3)), batch_size=2, pause_sec=0, tasks=3)),
('4', dict(min_in_service=3, count=2, ('4', dict(min_in_service=3, count=2,
existing=['0', '1', '2', '3'], black_listed=['2', '3'], existing=['0', '1', '2', '3'], skipped=['2', '3'],
batch_size=1, pause_sec=0, tasks=4)), batch_size=1, pause_sec=0, tasks=4)),
('5', dict(min_in_service=2, count=2, ('5', dict(min_in_service=2, count=2,
existing=['0', '1', '2', '3'], black_listed=[], existing=['0', '1', '2', '3'], skipped=[],
batch_size=2, pause_sec=0, tasks=2)), batch_size=2, pause_sec=0, tasks=2)),
('6', dict(min_in_service=2, count=3, ('6', dict(min_in_service=2, count=3,
existing=['0', '1'], black_listed=['0', '1'], existing=['0', '1'], skipped=['0', '1'],
batch_size=2, pause_sec=0, tasks=2)), batch_size=2, pause_sec=0, tasks=2)),
('7', dict(min_in_service=0, count=5, ('7', dict(min_in_service=0, count=5,
existing=['0', '1'], black_listed=[], existing=['0', '1'], skipped=[],
batch_size=1, pause_sec=0, tasks=5)), batch_size=1, pause_sec=0, tasks=5)),
('8', dict(min_in_service=0, count=5, ('8', dict(min_in_service=0, count=5,
existing=['0', '1'], black_listed=['0'], existing=['0', '1'], skipped=['0'],
batch_size=1, pause_sec=0, tasks=5)), batch_size=1, pause_sec=0, tasks=5)),
('9', dict(min_in_service=0, count=3, ('9', dict(min_in_service=0, count=3,
existing=['0', '1', '2', '3', '4', '5'], existing=['0', '1', '2', '3', '4', '5'],
black_listed=['0'], skipped=['0'],
batch_size=2, pause_sec=0, tasks=2)), batch_size=2, pause_sec=0, tasks=2)),
('10', dict(min_in_service=0, count=3, ('10', dict(min_in_service=0, count=3,
existing=['0', '1', '2', '3', '4', '5'], existing=['0', '1', '2', '3', '4', '5'],
black_listed=['0'], skipped=['0'],
batch_size=2, pause_sec=10, tasks=3))] batch_size=2, pause_sec=10, tasks=3))]
def setUp(self): def setUp(self):
@ -1263,8 +1263,8 @@ class ReplaceTest(common.HeatTestCase):
def test_rolling_updates(self): def test_rolling_updates(self):
self.group._nested = get_fake_nested_stack(self.existing) self.group._nested = get_fake_nested_stack(self.existing)
self.group.get_size = mock.Mock(return_value=self.count) self.group.get_size = mock.Mock(return_value=self.count)
self.group._name_blacklist = mock.Mock( self.group._name_skiplist = mock.Mock(
return_value=set(self.black_listed)) return_value=set(self.skipped))
tasks = self.group._replace(self.min_in_service, self.batch_size, tasks = self.group._replace(self.min_in_service, self.batch_size,
self.pause_sec) self.pause_sec)
self.assertEqual(self.tasks, len(tasks)) self.assertEqual(self.tasks, len(tasks))
@ -1468,18 +1468,18 @@ class RollingUpdateTest(common.HeatTestCase):
class TestUtils(common.HeatTestCase): class TestUtils(common.HeatTestCase):
# 1. No existing no blacklist # 1. No existing no skiplist
# 2. Existing with no blacklist # 2. Existing with no skiplist
# 3. Existing with blacklist # 3. Existing with skiplist
scenarios = [ scenarios = [
('1', dict(existing=[], black_listed=[], count=0)), ('1', dict(existing=[], skipped=[], count=0)),
('2', dict(existing=['0', '1'], black_listed=[], count=0)), ('2', dict(existing=['0', '1'], skipped=[], count=0)),
('3', dict(existing=['0', '1'], black_listed=['0'], count=1)), ('3', dict(existing=['0', '1'], skipped=['0'], count=1)),
('4', dict(existing=['0', '1'], black_listed=['1', '2'], count=1)) ('4', dict(existing=['0', '1'], skipped=['1', '2'], count=1))
] ]
def test_count_black_listed(self): def test_count_skipped(self):
inspector = mock.Mock(spec=grouputils.GroupInspector) inspector = mock.Mock(spec=grouputils.GroupInspector)
self.patchobject(grouputils.GroupInspector, 'from_parent_resource', self.patchobject(grouputils.GroupInspector, 'from_parent_resource',
return_value=inspector) return_value=inspector)
@ -1488,8 +1488,8 @@ class TestUtils(common.HeatTestCase):
stack = utils.parse_stack(template2) stack = utils.parse_stack(template2)
snip = stack.t.resource_definitions(stack)['group1'] snip = stack.t.resource_definitions(stack)['group1']
resgrp = resource_group.ResourceGroup('test', snip, stack) resgrp = resource_group.ResourceGroup('test', snip, stack)
resgrp._name_blacklist = mock.Mock(return_value=set(self.black_listed)) resgrp._name_skiplist = mock.Mock(return_value=set(self.skipped))
rcount = resgrp._count_black_listed(self.existing) rcount = resgrp._count_skipped(self.existing)
self.assertEqual(self.count, rcount) self.assertEqual(self.count, rcount)
@ -1761,7 +1761,7 @@ class TestGetBatches(common.HeatTestCase):
self.stack = utils.parse_stack(template) self.stack = utils.parse_stack(template)
self.grp = self.stack['group1'] self.grp = self.stack['group1']
self.grp._name_blacklist = mock.Mock(return_value={'0'}) self.grp._name_skiplist = mock.Mock(return_value={'0'})
def test_get_batches(self): def test_get_batches(self):
batches = list(self.grp._get_batches(self.targ_cap, batches = list(self.grp._get_batches(self.targ_cap,