Merge "Automatically set tag's based on role names"

This commit is contained in:
Zuul 2020-10-16 00:39:32 +00:00 committed by Gerrit Code Review
commit 93ffdf9ef8
2 changed files with 114 additions and 0 deletions

View File

@ -526,6 +526,75 @@ class ProcessTemplatesTest(base.TestCase):
resource_registry, 'overcloud')
mock_put.assert_not_called()
@mock.patch.object(template_utils, 'LOG', autospec=True)
def test__set_tags_based_on_role_name(self, mock_log):
role_data = [
{'name': 'CephStorageFoo'},
{'name': 'CephStorageBar', 'tags': ['ceph', 'storage']},
{'name': 'ObjectStorageFoo'},
{'name': 'ObjectStorageBar', 'tags': ['storage']},
{'name': 'BlockStorageFoo'},
{'name': 'BlockStorageFoo', 'tags': ['storage']},
{'name': 'ComputeOvsDpdkFoo'},
{'name': 'ComputeOvsDpdkBar', 'tags': ['ovsdpdk']},
]
template_utils._set_tags_based_on_role_name(role_data)
expected = [
{'name': 'CephStorageFoo', 'tags': ['ceph', 'storage']},
{'name': 'CephStorageBar', 'tags': ['ceph', 'storage']},
{'name': 'ObjectStorageFoo', 'tags': ['storage']},
{'name': 'ObjectStorageBar', 'tags': ['storage']},
{'name': 'BlockStorageFoo', 'tags': ['storage']},
{'name': 'BlockStorageFoo', 'tags': ['storage']},
{'name': 'ComputeOvsDpdkFoo', 'tags': ['compute', 'ovsdpdk']},
{'name': 'ComputeOvsDpdkBar', 'tags': ['ovsdpdk', 'compute']},
]
self.assertEqual(expected, role_data)
mock_log.assert_has_calls([
mock.call.warning(
"DEPRECATED: Role 'CephStorageFoo' without the 'ceph' tag "
"detected, the tag was added automatically. Please add the "
"'ceph' tag in roles data. The function to automatically "
"add tags based on role name will be removed in the next "
"release."),
mock.call.warning(
"DEPRECATED: Role 'CephStorageFoo' without the 'storage' "
"tag detected, the tag was added automatically. Please add "
"the 'storage' tag in roles data. The function to "
"automatically add tags based on role name will be removed in "
"the next release."),
mock.call.warning(
"DEPRECATED: Role 'ObjectStorageFoo' without the 'storage' "
"tag detected, the tag was added automatically. Please add "
"the 'storage' tag in roles data. The function to "
"automatically add tags based on role name will be "
"removed in the next release."),
mock.call.warning(
"DEPRECATED: Role 'BlockStorageFoo' without the 'storage' tag "
"detected, the tag was added automatically. Please add "
"the 'storage' tag in roles data. The function to "
"automatically add tags based on role name will be removed "
"in the next release."),
mock.call.warning(
"DEPRECATED: Role 'ComputeOvsDpdkFoo' without the 'compute' "
"tag detected, the tag was added automatically. Please add "
"the 'compute' tag in roles data. The function to "
"automatically add tags based on role name will be removed in "
"the next release."),
mock.call.warning(
"DEPRECATED: Role 'ComputeOvsDpdkFoo' without the 'ovsdpdk' "
"tag detected, the tag was added automatically. Please add "
"the 'ovsdpdk' tag in roles data. The function to "
"automatically add tags based on role name will be removed in "
"the next release."),
mock.call.warning(
"DEPRECATED: Role 'ComputeOvsDpdkBar' without the 'compute' "
"tag detected, the tag was added automatically. Please add "
"the 'compute' tag in roles data. The function to "
"automatically add tags based on role name will be removed in "
"the next release."),
])
class UploadTemplatesTest(base.TestCase):

View File

@ -136,6 +136,47 @@ def heat_resource_exists(heat, stack, nested_stack_name, resource_name):
return True
def _set_tags_based_on_role_name(role_data):
for role in role_data:
role['tags'] = role.get('tags', [])
role_name = role.get('name', str())
if ((role_name.startswith('Compute') or role_name.startswith('HciCeph')
or role_name.startswith('DistributedCompute'))
and 'compute' not in role['tags']):
role['tags'].append('compute')
LOG.warning("DEPRECATED: Role '%s' without the 'compute' tag "
"detected, the tag was added automatically. Please "
"add the 'compute' tag in roles data. The function to "
"automatically add tags based on role name will be "
"removed in the next release." % role_name)
if role_name.startswith('Ceph') and 'ceph' not in role['tags']:
role['tags'].append('ceph')
LOG.warning("DEPRECATED: Role '%s' without the 'ceph' tag "
"detected, the tag was added automatically. Please "
"add the 'ceph' tag in roles data. The function to "
"automatically add tags based on role name will be "
"removed in the next release." % role_name)
if (role_name.startswith('ComputeOvsDpdk')
and 'ovsdpdk' not in role['tags']):
role['tags'].append('ovsdpdk')
LOG.warning("DEPRECATED: Role '%s' without the 'ovsdpdk' tag "
"detected, the tag was added automatically. Please "
"add the 'ovsdpdk' tag in roles data. The function to "
"automatically add tags based on role name will be "
"removed in the next release." % role_name)
if ((role_name.startswith('ObjectStorage')
or role_name.startswith('BlockStorage')
or role_name.startswith('Ceph'))
and 'storage' not in role['tags']):
role['tags'].append('storage')
LOG.warning("DEPRECATED: Role '%s' without the 'storage' tag "
"detected, the tag was added automatically. Please "
"add the 'storage' tag in roles data. The function to "
"automatically add tags based on role name will be "
"removed in the next release." % role_name)
def process_custom_roles(swift, heat,
container=constants.DEFAULT_CONTAINER_NAME):
try:
@ -172,6 +213,10 @@ def process_custom_roles(swift, heat,
LOG.error(error_msg)
raise RuntimeError(error_msg)
# TODO(hjensas): In next release remove the function to automatically add
# tags based on role name.
_set_tags_based_on_role_name(role_data)
role_names = [r.get('name') for r in role_data]
r_map = {}
for r in role_data: