From ceeefe64adc14134548aabe4b677f4a0160ca4b4 Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Fri, 3 Feb 2017 07:02:38 -0500 Subject: [PATCH] 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 --- packstack/installer/core/parameters.py | 3 ++- packstack/installer/run_setup.py | 18 ++++++++++++++ ...d-parameter-messages-47d9cf6996f58230.yaml | 24 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-parameter-messages-47d9cf6996f58230.yaml diff --git a/packstack/installer/core/parameters.py b/packstack/installer/core/parameters.py index 7450f9d4a..0f7fa4934 100644 --- a/packstack/installer/core/parameters.py +++ b/packstack/installer/core/parameters.py @@ -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 {} diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index b0dae805e..864dc9a06 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -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() diff --git a/releasenotes/notes/add-parameter-messages-47d9cf6996f58230.yaml b/releasenotes/notes/add-parameter-messages-47d9cf6996f58230.yaml new file mode 100644 index 000000000..577c37e7c --- /dev/null +++ b/releasenotes/notes/add-parameter-messages-47d9cf6996f58230.yaml @@ -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"