I am trying to update a particular option in my config.ini
file using ConfigParser
.
This is my config.ini
file:
[remote-server-details]
MACHINE_NAME =
MACHINE_USERNAME =
MACHINE_PASSWORD = Welcome!23
And this is my step file in Python:
@step('I change the following config options in section "{section_name}" in the {config_file_type} config file')
def set_dag_config_section_values(context, section_name, config_file_type):
parameters = ast.literal_eval(context.text)
context.conf[config_file_type].read(context.dag_config_file[config_file_type])
context.conf[config_file_type].remove_section(section_name)
context.conf[config_file_type].add_section(section_name)
for option, value in parameters.iteritems():
context.conf[config_file_type].set(section_name, option, value)
with open(context.dag_config_file[config_file_type], 'w+') as configfile:
context.conf[config_file_type].write(configfile)
context.conf[config_file_type].read(context.dag_config_file[config_file_type])
readin_parameters = dict(context.conf[config_file_type].items(section_name))
sort_dict(parameters)
sort_dict(readin_parameters)
assert readin_parameters == parameters, 'Value could not be set. %s does not match config contents %s' % (parameters, readin_parameters)
I need to update only MACHINE_NAME
and MACHINE_USERNAME
, as MACHINE_PASSWORD
is already contained in the config file, but I'm getting this error:
INFO - Subtask: remote_server_details['MACHINE_PASSWORD'],
[2018-08-17 17:40:04,723] {{base_task_runner.py:98}} INFO - Subtask: KeyError: 'MACHINE_PASSWORD'