From 53ba7df3e4b6d55578b125121c38c5fbf2cca4fb Mon Sep 17 00:00:00 2001 From: Maciej Kucia Date: Fri, 30 Jun 2017 19:41:11 +0200 Subject: [PATCH] Add switch to check unexpected answerfile options Added new --validate-answer-file switch to check if answerfile contains any unexpected options. Often such options are a result of human error or answerfile reuse in different Packstack/OpenStack versions. Change-Id: Ie537a27e7a21086f6b41c582d846584bf1545d52 Signed-off-by: Maciej Kucia --- README.md | 7 ++++ packstack/installer/run_setup.py | 36 +++++++++++++++++-- ...k-unexpected-options-2f2d26ebe54da6c9.yaml | 5 +++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/check-unexpected-options-2f2d26ebe54da6c9.yaml diff --git a/README.md b/README.md index 4df87c881..dc497834f 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,13 @@ To make **Packstack** write more detailed information into the log file you can $ packstack -d --allinone +When upgrading to a new OpenStack release and reusing old answerfile +it is useful to know if any **Packstack** option was removed. If answerfile is +written by hand it is possible to make a mistake. The `--validate-answer-file` +switch allows checking if any provided option is not recognized by **Packstack**. + + $ packstack --validate-answer-file=ans.txt + ## Developing **Warning:** diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index 9ee737c0f..556a70687 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -761,6 +761,35 @@ def generateAnswerFile(outputFile, overrides={}): ans_file.write(fmt % args) +def validate_answer_file_options(answerfile_path): + if not os.path.exists(answerfile_path): + raise Exception( + output_messages.ERR_NO_ANSWER_FILE % answerfile_path) + + answerfile = ConfigParser.ConfigParser() + answerfile.read(answerfile_path) + sections = answerfile._sections + general_sections = sections.get('general', None) + + if len(sections) != 1: + raise Exception('Expected single section') + if not general_sections: + raise Exception('Expected section [general]') + + general_sections.pop('__name__') + answerfile_options = set([key.upper() for key in general_sections]) + + possible_options = set() + for group in controller.getAllGroups(): + possible_options.update([key.upper() for key in group.parameters]) + + difference = answerfile_options - possible_options + if difference: + raise Exception( + 'Found unexpected answerfile options {}'.format(list(difference))) + print('Provided answerfile does not contain any unexpected options.') + + def single_step_aio_install(options, logFile): """Installs an All in One host on this host.""" @@ -810,6 +839,7 @@ def initCmdLineParser(): usage = "usage: %prog [options] [--help]" parser = OptionParser(usage=usage, version="%prog {0}".format(version_info.version_string())) parser.add_option("--gen-answer-file", help="Generate a template of an answer file.") + parser.add_option("--validate-answer-file", help="Check if answerfile contains unexpected options.") parser.add_option("--answer-file", help="Runs the configuration in non-interactive mode, extracting all information from the" "configuration file. using this option excludes all other options") parser.add_option("--install-hosts", help="Install on a set of hosts in a single step. The format should be a comma separated list " @@ -979,8 +1009,10 @@ def main(): controller.CONF['DRY_RUN'] = options.dry_run controller.CONF['DIR_LOG'] = basedefs.DIR_LOG - # If --gen-answer-file was supplied, do not run main - if options.gen_answer_file: + if options.validate_answer_file: + answerfilepath = options.validate_answer_file + validate_answer_file_options(answerfilepath) + elif options.gen_answer_file: answerfilepath = _gettmpanswerfilepath() if not answerfilepath: _printAdditionalMessages() diff --git a/releasenotes/notes/check-unexpected-options-2f2d26ebe54da6c9.yaml b/releasenotes/notes/check-unexpected-options-2f2d26ebe54da6c9.yaml new file mode 100644 index 000000000..5bc2887e3 --- /dev/null +++ b/releasenotes/notes/check-unexpected-options-2f2d26ebe54da6c9.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added new --validate-answer-file switch to check if answerfile contains + any unexpected options.