Remove the mistral from the check_deprecated_parameters workflow
This change removes all of mistral from the check_deprecated_parameters function by calling the required functions directly. Story: 2007212 Task: 38424 Change-Id: Ib76dac4e0d11c66fe90c30db19788af1cb4694f6 Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
parent
72bb7fbaa9
commit
8416553903
@ -108,6 +108,43 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
||||
client.object_store.put_object = mock.Mock()
|
||||
get_container = client.object_store.get_container = mock.MagicMock()
|
||||
get_container.return_value = ('container', [{'name': 'f1'}])
|
||||
roles = mock.patch(
|
||||
'tripleoclient.workflows.roles.list_available_roles',
|
||||
autospec=True,
|
||||
return_value=[
|
||||
{
|
||||
'TestRole1': {
|
||||
'TestParameter1': {}
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
roles.start()
|
||||
self.addCleanup(roles.stop)
|
||||
flatten = mock.patch(
|
||||
'tripleo_common.actions.parameters.GetFlattenedParametersAction'
|
||||
'.run',
|
||||
autospec=True,
|
||||
return_value={
|
||||
'environment_parameters': {
|
||||
'TestParameter1': {},
|
||||
'TestRole1': 'TestParameter2'
|
||||
},
|
||||
'heat_resource_tree': {
|
||||
'parameters': {
|
||||
'TestParameter2': {
|
||||
'name': 'TestParameter2',
|
||||
'tags': [
|
||||
'role_specific'
|
||||
]
|
||||
}
|
||||
},
|
||||
'resources': {}
|
||||
}
|
||||
}
|
||||
)
|
||||
flatten.start()
|
||||
self.addCleanup(flatten.stop)
|
||||
|
||||
# Mock playbook runner
|
||||
playbook_runner = mock.patch(
|
||||
|
@ -45,6 +45,46 @@ class TestParameterWorkflows(utils.TestCommand):
|
||||
execution = mock.Mock()
|
||||
execution.id = "IDID"
|
||||
self.workflow.executions.create.return_value = execution
|
||||
get_container = self.tripleoclient.object_store.get_container \
|
||||
= mock.MagicMock()
|
||||
get_container.return_value = ('container', [{'name': 'f1'}])
|
||||
roles = mock.patch(
|
||||
'tripleoclient.workflows.roles.list_available_roles',
|
||||
autospec=True,
|
||||
return_value=[
|
||||
{
|
||||
'TestRole1': {
|
||||
'TestParameter1': {}
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
roles.start()
|
||||
self.addCleanup(roles.stop)
|
||||
flatten = mock.patch(
|
||||
'tripleo_common.actions.parameters.GetFlattenedParametersAction'
|
||||
'.run',
|
||||
autospec=True,
|
||||
return_value={
|
||||
'environment_parameters': {
|
||||
'TestParameter1': {},
|
||||
'TestRole1': 'TestParameter2'
|
||||
},
|
||||
'heat_resource_tree': {
|
||||
'parameters': {
|
||||
'TestParameter2': {
|
||||
'name': 'TestParameter2',
|
||||
'tags': [
|
||||
'role_specific'
|
||||
]
|
||||
}
|
||||
},
|
||||
'resources': {}
|
||||
}
|
||||
}
|
||||
)
|
||||
flatten.start()
|
||||
self.addCleanup(flatten.stop)
|
||||
|
||||
@mock.patch('yaml.safe_load')
|
||||
@mock.patch("six.moves.builtins.open")
|
||||
@ -141,144 +181,44 @@ class TestParameterWorkflows(utils.TestCommand):
|
||||
self.workflow.executions.create.assert_not_called()
|
||||
|
||||
def test_check_deprecated_params_no_output(self):
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
}])
|
||||
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
|
||||
def test_check_deprecated_params_user_defined(self):
|
||||
msg = ("WARNING: Following parameter(s) are deprecated and still "
|
||||
"defined. Deprecated parameters will be removed soon!"
|
||||
" TestParameter1")
|
||||
deprecated_params = [{'parameter': 'TestParameter1',
|
||||
'deprecated': True,
|
||||
'user_defined': True}]
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"deprecated": deprecated_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
mock_log.warning.assert_called_once_with(msg)
|
||||
self.assertTrue(mock_log.warning.called)
|
||||
|
||||
def test_check_deprecated_params_user_not_defined(self):
|
||||
deprecated_params = [{'parameter': 'TestParameter1',
|
||||
'deprecated': True}]
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"deprecated": deprecated_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
self.assertFalse(mock_log.log.warning.called)
|
||||
|
||||
def test_check_deprecated_multiple_parameters(self):
|
||||
msg = ("WARNING: Following parameter(s) are deprecated and still "
|
||||
"defined. Deprecated parameters will be removed soon!"
|
||||
" TestParameter1, TestParameter2")
|
||||
deprecated_params = [{'parameter': 'TestParameter1',
|
||||
'deprecated': True,
|
||||
'user_defined': True},
|
||||
{'parameter': 'TestParameter2',
|
||||
'deprecated': True,
|
||||
'user_defined': True}]
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"deprecated": deprecated_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
mock_log.warning.assert_called_once_with(msg)
|
||||
|
||||
def test_check_unused_parameters(self):
|
||||
msg = ("WARNING: Following parameter(s) are defined but not currently"
|
||||
" used in the deployment plan. These parameters may be valid"
|
||||
" but not in use due to the service or deployment"
|
||||
" configuration. TestParameter1")
|
||||
unused_params = ['TestParameter1']
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"unused": unused_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
mock_log.warning.assert_called_once_with(msg)
|
||||
self.assertTrue(mock_log.warning.called)
|
||||
|
||||
def test_check_unused_multiple_parameters(self):
|
||||
msg = ("WARNING: Following parameter(s) are defined but not currently"
|
||||
" used in the deployment plan. These parameters may be valid"
|
||||
" but not in use due to the service or deployment"
|
||||
" configuration. TestParameter1, TestParameter2")
|
||||
unused_params = ['TestParameter1', 'TestParameter2']
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"unused": unused_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
mock_log.warning.assert_called_once_with(msg)
|
||||
self.assertTrue(mock_log.warning.called)
|
||||
|
||||
def test_check_invalid_role_specific_parameters(self):
|
||||
msg = ("WARNING: Following parameter(s) are not supported as"
|
||||
" role-specific inputs. TestParameter1")
|
||||
invalid_role_specific_params = ['TestParameter1']
|
||||
self.websocket.wait_for_messages.return_value = iter([{
|
||||
"execution_id": "IDID",
|
||||
"status": "SUCCESS",
|
||||
"invalid_role_specific": invalid_role_specific_params
|
||||
}])
|
||||
|
||||
with mock.patch('tripleoclient.workflows.parameters.LOG') as mock_log:
|
||||
parameters.check_deprecated_parameters(
|
||||
self.app.client_manager,
|
||||
container='container-name')
|
||||
self.workflow.executions.create.assert_called_once_with(
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input={'container': 'container-name'})
|
||||
mock_log.warning.assert_called_once_with(msg)
|
||||
self.assertTrue(mock_log.warning.called)
|
||||
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.parameters.GenerateFencingParametersAction'
|
||||
|
@ -75,6 +75,7 @@ class Authorize(command.Command):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
self.log.debug("take_action({})".format(parsed_args))
|
||||
clients = self.app.client_manager
|
||||
stack = oooutils.get_stack(clients.orchestration, parsed_args.stack)
|
||||
|
@ -9,6 +9,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import re
|
||||
import yaml
|
||||
@ -18,6 +19,7 @@ from tripleo_common.actions import parameters
|
||||
from tripleoclient.constants import UNUSED_PARAMETER_EXCLUDES_RE
|
||||
from tripleoclient import exceptions
|
||||
from tripleoclient.workflows import base
|
||||
from tripleoclient.workflows import roles
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -72,67 +74,110 @@ def invoke_plan_env_workflows(clients, stack_name, plan_env_file):
|
||||
|
||||
|
||||
def check_deprecated_parameters(clients, container):
|
||||
"""Checks for deprecated parameters in plan and adds warning if present"""
|
||||
"""Checks for deprecated parameters in plan and adds warning if present.
|
||||
|
||||
workflow_client = clients.workflow_engine
|
||||
tripleoclients = clients.tripleoclient
|
||||
workflow_input = {
|
||||
'container': container
|
||||
}
|
||||
:param clients: application client object.
|
||||
:type clients: Object
|
||||
|
||||
with tripleoclients.messaging_websocket() as ws:
|
||||
execution = base.start_workflow(
|
||||
workflow_client,
|
||||
'tripleo.plan_management.v1.get_deprecated_parameters',
|
||||
workflow_input=workflow_input
|
||||
:param container: Name of the stack container.
|
||||
:type container: String
|
||||
"""
|
||||
|
||||
context = clients.tripleoclient.create_mistral_context()
|
||||
role_name_list = roles.list_available_roles(
|
||||
clients=clients,
|
||||
container=container
|
||||
)
|
||||
flattened_parms = parameters.GetFlattenedParametersAction(
|
||||
container=container
|
||||
).run(context=context)
|
||||
user_params = flattened_parms['environment_parameters']
|
||||
heat_resource_tree = flattened_parms['heat_resource_tree']
|
||||
heat_resource_tree_params = heat_resource_tree['parameters']
|
||||
heat_resource_tree_resources = heat_resource_tree['resources']
|
||||
plan_params = heat_resource_tree_params.keys()
|
||||
parameter_groups = [
|
||||
i.get('parameter_groups')
|
||||
for i in heat_resource_tree_resources.values()
|
||||
if i.get('parameter_groups')
|
||||
]
|
||||
params_role_specific_tag = [
|
||||
i.get('name')
|
||||
for i in heat_resource_tree_params.values()
|
||||
if 'tags' in i and 'role_specific' in i['tags']
|
||||
]
|
||||
|
||||
r = re.compile(".*Count")
|
||||
filtered_names = list(filter(r.match, plan_params))
|
||||
valid_role_name_list = list()
|
||||
for name in filtered_names:
|
||||
default = heat_resource_tree_params[name].get('default', 0)
|
||||
if default and int(default) > 0:
|
||||
role_name = name.rstrip('Count')
|
||||
if [i for i in role_name_list if i.get('name') == role_name]:
|
||||
valid_role_name_list.append(role_name)
|
||||
|
||||
deprecated_params = [
|
||||
i[0] for i in parameter_groups
|
||||
if i[0].get('label') == 'deprecated'
|
||||
]
|
||||
deprecated_result = [
|
||||
{
|
||||
'parameter': i,
|
||||
'deprecated': True,
|
||||
'user_defined': i in user_params.keys()
|
||||
}
|
||||
for i in deprecated_params
|
||||
]
|
||||
unused_params = [i for i in user_params.keys() if i not in plan_params]
|
||||
user_provided_role_specific = [
|
||||
v for i in role_name_list
|
||||
for k, v in user_params.items()
|
||||
if k in i
|
||||
]
|
||||
invalid_role_specific_params = [
|
||||
i for i in user_provided_role_specific
|
||||
if i in params_role_specific_tag
|
||||
]
|
||||
deprecated_parameters = [
|
||||
param['parameter'] for param in deprecated_result
|
||||
if param.get('user_defined')
|
||||
]
|
||||
|
||||
if deprecated_parameters:
|
||||
deprecated_join = ', '.join(deprecated_parameters)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are deprecated and still '
|
||||
'defined. Deprecated parameters will be removed soon!'
|
||||
' {deprecated_join}'.format(
|
||||
deprecated_join=deprecated_join
|
||||
)
|
||||
)
|
||||
|
||||
messages = base.wait_for_messages(workflow_client, ws, execution, 120)
|
||||
has_messages = False
|
||||
# exclude our known params that may not be used
|
||||
ignore_re = re.compile('|'.join(UNUSED_PARAMETER_EXCLUDES_RE))
|
||||
unused_params = [p for p in unused_params if not ignore_re.search(p)]
|
||||
|
||||
for message in messages:
|
||||
if message['status'] != 'SUCCESS':
|
||||
return
|
||||
if unused_params:
|
||||
unused_join = ', '.join(unused_params)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are defined but not '
|
||||
'currently used in the deployment plan. These parameters '
|
||||
'may be valid but not in use due to the service or '
|
||||
'deployment configuration.'
|
||||
' {unused_join}'.format(
|
||||
unused_join=unused_join
|
||||
)
|
||||
)
|
||||
|
||||
has_messages = True
|
||||
deprecated_params = [
|
||||
param['parameter'] for param in message.get('deprecated', [])
|
||||
if param.get('user_defined')
|
||||
]
|
||||
unused_params = message.get('unused', [])
|
||||
invalid_role_specific_params = message.get(
|
||||
'invalid_role_specific', [])
|
||||
|
||||
if not has_messages:
|
||||
return
|
||||
|
||||
if deprecated_params:
|
||||
deprecated_join = ', '.join(deprecated_params)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are deprecated and still '
|
||||
'defined. Deprecated parameters will be removed soon!'
|
||||
' {deprecated_join}'.format(
|
||||
deprecated_join=deprecated_join))
|
||||
|
||||
# exclude our known params that may not be used
|
||||
ignore_re = re.compile('|'.join(UNUSED_PARAMETER_EXCLUDES_RE))
|
||||
unused_params = [p for p in unused_params if not ignore_re.search(p)]
|
||||
|
||||
if unused_params:
|
||||
unused_join = ', '.join(unused_params)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are defined but not '
|
||||
'currently used in the deployment plan. These parameters '
|
||||
'may be valid but not in use due to the service or '
|
||||
'deployment configuration.'
|
||||
' {unused_join}'.format(unused_join=unused_join))
|
||||
|
||||
if invalid_role_specific_params:
|
||||
invalid_join = ', '.join(invalid_role_specific_params)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are not supported as '
|
||||
'role-specific inputs. {invalid_join}'.format(
|
||||
invalid_join=invalid_join))
|
||||
if invalid_role_specific_params:
|
||||
invalid_join = ', '.join(invalid_role_specific_params)
|
||||
LOG.warning(
|
||||
'WARNING: Following parameter(s) are not supported as '
|
||||
'role-specific inputs. {invalid_join}'.format(
|
||||
invalid_join=invalid_join
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def generate_fencing_parameters(clients, nodes_json, delay, ipmi_level,
|
||||
|
Loading…
x
Reference in New Issue
Block a user