Add options to display parameter specific messages

This patch introduces MESSAGE and MESSSAGE_VALUES to
parameters. When a user selects a value included in
MESSAGE_VALUES for a parameter with MESSAGE option,
this message will be shown to users at the end
of packstack execution.

Example use case is showing a note alerting that a service
will be removed in next release if user enables it.

Change-Id: I1331de921e1f5f1aecf991cb83fa1509f29b3ee7
This commit is contained in:
Alfredo Moralejo 2017-02-03 07:02:38 -05:00
parent 8168496c9e
commit ceeefe64ad
3 changed files with 44 additions and 1 deletions

View File

@ -23,7 +23,8 @@ class Parameter(object):
allowed_keys = ('CONF_NAME', 'CMD_OPTION', 'USAGE', 'PROMPT',
'PROCESSORS', 'VALIDATORS', 'LOOSE_VALIDATION',
'DEFAULT_VALUE', 'USE_DEFAULT', 'OPTION_LIST',
'MASK_INPUT', 'NEED_CONFIRM', 'CONDITION', 'DEPRECATES')
'MASK_INPUT', 'NEED_CONFIRM', 'CONDITION', 'DEPRECATES',
'MESSAGE', 'MESSAGE_VALUES')
def __init__(self, attributes=None):
attributes = attributes or {}

View File

@ -389,6 +389,9 @@ def _loadParamFromFile(config, section, param_name):
# Keep param value in our never ending global conf
controller.CONF[param.CONF_NAME] = value
# Add message to controller.MESSAGES if defined in parameter
if param.MESSAGE:
_handleParamMessage(param, value)
return value
@ -623,6 +626,21 @@ def _summaryParamsToLog():
logging.debug("%s: %s" % (param.CMD_OPTION, maskedValue))
def _handleParamMessage(param, value):
"""
add message to the information displayed at the end of the execution
for parameters with MESSAGE option. if parameter has MESSAGE_VALUES
option, message will be only displayed if the provided value is in
MESSAGE_VALUES.
"""
message_values = param.MESSAGE_VALUES if param.MESSAGE_VALUES is not None else None
if not message_values or value in message_values:
message = utils.color_text('Parameter %s: %s'
% (param.CONF_NAME, param.MESSAGE), 'red')
if message not in controller.MESSAGES:
controller.MESSAGES.append(message)
def runSequences():
controller.runAllSequences()

View File

@ -0,0 +1,24 @@
---
features:
- |
Packstack can display parameter specific messages when a MESSAGE option
is added to the parameter. If MESSAGE_VALUES exist for the parameter, the
message will only be shown if the value provided by the user is included
in MESSAGE_VALUES. Example:
{"CMD_OPTION": "example-service-install",
"OPTION_LIST": ["y", "n"],
"VALIDATORS": [validators.validate_options],
"DEFAULT_VALUE": 'n',
"MASK_INPUT": False,
"LOOSE_VALIDATION": False,
"CONF_NAME": "CONFIG_EXAMPLE_SERVICE_INSTALL",
"USE_DEFAULT": False,
"NEED_CONFIRM": False,
"CONDITION": False,
"MESSAGE_VALUES": ["y"],
"MESSAGE": "Example service installation will be removed from packstack in Pike"}
In this case, if the user enable installation of example service, a message
will be displayed at the end of packstack execution with content "Example
service installation will be removed from packstack in Pike"