def _populate_config(self) -> ConfigParser: config = ConfigParser() config_path = './resources/config.ini' if 'resources' not in listdir('.'): config_path = '.' + config_path with open(config_path) as file_pointer: config.read_file(file_pointer) return config
def get_value_from_ini_config(overcloud_node, config_path, check_section, check_value, multi_key_values=False): """Get value from INI configuration file :param overcloud_node: The node that config should be pulled from :param config_path: The path of the configuration file :param check_section: Section within the config :param check_value: Value that should be checked within the config The variable could hold multiple values separated by comma. :param multi_key_values: Flag on request to hold multiple values for single key from ini file :return return_value """ class M(OrderedDict): def __setitem__(self, key, value): v_val = self.get(key) if v_val is not None and type(value) == list: v_val.append(value[0]) else: v_val = value # still using python2.7 super, for backport portability super(M, self).__setitem__(key, v_val) ini_config = get_overcloud_config(overcloud_node, config_path) config_parser_args = {'allow_no_value': True} if multi_key_values: config_parser_args['dict_type'] = M config_parser_args['strict'] = False get_value = ConfigParser(**config_parser_args) get_value.read_file(StringIO(ini_config)) value_data = [] for value in check_value.split(','): value_data.append(get_value.get(check_section, value)) return ','.join(value_data)