Merge "Throw warning if --limit used with a skip list in Heat" into stable/train

This commit is contained in:
Zuul 2020-07-23 12:36:01 +00:00 committed by Gerrit Code Review
commit 037dd3342f
4 changed files with 103 additions and 0 deletions

View File

@ -1693,6 +1693,45 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
expected = ('fd12::1 uc.ctlplane.localdomain uc.ctlplane')
self.assertEqual(expected, self.cmd._get_undercloud_host_entry())
def test_check_limit_warning(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_limit_skiplist_warning(env)
self.cmd.log = old_logger
mock_warning.assert_not_called()
def test_check_limit_warning_empty(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {'DeploymentServerBlacklist': []}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_limit_skiplist_warning(env)
self.cmd.log = old_logger
mock_warning.assert_not_called()
def test_check_limit_warning_warns(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {'DeploymentServerBlacklist': ['a']}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_limit_skiplist_warning(env)
self.cmd.log = old_logger
expected_message = ('[WARNING] DeploymentServerBlacklist is defined '
'and will be ignored because --limit has been '
'specified.')
mock_warning.assert_called_once_with(expected_message)
class TestArgumentValidation(fakes.TestDeployOvercloud):

View File

@ -409,6 +409,47 @@ class TestDeleteNode(fakes.TestDeleteNode):
parsed_args, bm_yaml)
self.assertEqual(['aaaa', 'dddd'], result)
def test_check_skiplist_exists(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_skiplist_exists(env)
self.cmd.log = old_logger
mock_warning.assert_not_called()
def test_check_skiplist_exists_empty(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {'DeploymentServerBlacklist': []}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_skiplist_exists(env)
self.cmd.log = old_logger
mock_warning.assert_not_called()
def test_check_skiplist_exists_warns(self):
mock_warning = mock.MagicMock()
mock_log = mock.MagicMock()
mock_log.warning = mock_warning
env = {'parameter_defaults': {'DeploymentServerBlacklist': ['a']}}
old_logger = self.cmd.log
self.cmd.log = mock_log
self.cmd._check_skiplist_exists(env)
self.cmd.log = old_logger
expected_message = ('[WARNING] DeploymentServerBlacklist is ignored '
'when executing scale down actions. If the '
'node(s) being removed should *NOT* have any '
'actions executed on them, please shut them off '
'prior to their removal.')
mock_warning.assert_called_once_with(expected_message)
class TestProvideNode(fakes.TestOvercloudNode):

View File

@ -150,6 +150,12 @@ class DeployOvercloud(command.Command):
container_name)
return parameter_defaults
def _check_limit_skiplist_warning(self, env):
if env.get('parameter_defaults').get('DeploymentServerBlacklist'):
msg = _('[WARNING] DeploymentServerBlacklist is defined and will '
'be ignored because --limit has been specified.')
self.log.warning(msg)
def _write_user_environment(self, env_map, abs_env_path, tht_root,
container_name):
# We write the env_map to the local /tmp tht_root and also
@ -441,6 +447,11 @@ class DeployOvercloud(command.Command):
cleanup=(not parsed_args.no_cleanup))
template_utils.deep_update(env, localenv)
if parsed_args.limit:
# check if skip list is defined while using --limit and throw a
# warning if necessary
self._check_limit_skiplist_warning(env)
if stack:
if not parsed_args.disable_validations:
# note(aschultz): network validation goes here before we deploy

View File

@ -160,6 +160,16 @@ class DeleteNode(command.Command):
nodes.append(node)
return nodes
def _check_skiplist_exists(self, env):
skiplist = env.get('parameter_defaults',
{}).get('DeploymentServerBlacklist')
if skiplist:
self.log.warning(_('[WARNING] DeploymentServerBlacklist is '
'ignored when executing scale down actions. If '
'the node(s) being removed should *NOT* have '
'any actions executed on them, please shut '
'them off prior to their removal.'))
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
clients = self.app.client_manager
@ -197,6 +207,8 @@ class DeleteNode(command.Command):
print("Deleting the following nodes from stack {stack}:\n{nodes}"
.format(stack=stack.stack_name, nodes=nodes_text))
self._check_skiplist_exists(stack.environment())
scale.scale_down(
clients,
stack.stack_name,