From 3fa634908969d3f7b24c6cbd284610075952a6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Sun, 20 Jan 2019 03:57:03 +0100 Subject: [PATCH] UX - Useful error msg if role is not in roles data If the user specify a role name that does not exist in the provided roles data the scipt exits with a StopIteration error. Catch it and raise RuntimeError with user friendly error message. Closes-Bug: #1812530 Change-Id: I704316f66c197668a7d8e373efe00889776d2a85 --- tools/merge-new-params-nic-config-script.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/merge-new-params-nic-config-script.py b/tools/merge-new-params-nic-config-script.py index 8e8c1343ec..470e7479dd 100755 --- a/tools/merge-new-params-nic-config-script.py +++ b/tools/merge-new-params-nic-config-script.py @@ -209,9 +209,15 @@ def process_templates_and_get_reference_parameters(): # be used when loading the reference file. with open(OPTS.roles_data) as roles_data_file: roles_data = yaml.safe_load(roles_data_file) - nic_config_name = next((x.get('deprecated_nic_config_name', - OPTS.role_name.lower() + '.yaml') for x in - roles_data if x['name'] == OPTS.role_name)) + try: + nic_config_name = next((x.get('deprecated_nic_config_name', + OPTS.role_name.lower() + '.yaml') + for x in roles_data + if x['name'] == OPTS.role_name)) + except StopIteration: + raise RuntimeError('The role: {role_name} is not defined in roles ' + 'data file: {roles_data_file}'.format( + role_name=OPTS.role_name, roles_data_file=OPTS.roles_data)) refernce_file = '/'.join([temp_dir, 'network/config', NIC_CONFIG_REFERENCE, nic_config_name])