From b7f38639a21857aead860195d12eccf6eb9f437e Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 26 Jul 2019 14:10:04 +0300 Subject: [PATCH] Fix writing of keys without values Sometimes there might be a key in configfile, that should be empty but defined correctly. This patch fixes such behaviour and adds testing. Change-Id: I693bc3a2aade7015d0465583001962df4ba53443 --- action/config_template.py | 5 ++++- tests/files/test_comment_configs.ini.expected | 8 -------- tests/files/test_default_section.ini.expected | 6 ++++-- tests/files/test_remote_src_multistropts.ini.expected | 2 -- tests/templates/test_default_section.ini | 5 ++++- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/action/config_template.py b/action/config_template.py index e5ab7b8..3370cac 100644 --- a/action/config_template.py +++ b/action/config_template.py @@ -220,8 +220,11 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser): def _write_check(self, fp, key, value, section=False): def _return_entry(option, item): - if item: + # If we have item, we consider it as a config parameter with value + if item is not None: return "%s = %s\n" % (option, str(item).replace('\n', '\n\t')) + elif not option: + return option else: return "%s\n" % option diff --git a/tests/files/test_comment_configs.ini.expected b/tests/files/test_comment_configs.ini.expected index 95ef5d0..652b879 100644 --- a/tests/files/test_comment_configs.ini.expected +++ b/tests/files/test_comment_configs.ini.expected @@ -1,44 +1,36 @@ [DEFAULT] - # # From nova.conf # - # # Availability zone for internal services. For more information, refer to the # documentation. (string value) #internal_service_availability_zone = internal - # # Default availability zone for compute services. For more information, refer to # the documentation. (string value) #default_availability_zone = nova default_availability_zone = zone1 - # # Default availability zone for instances. For more information, refer to the # documentation. (string value) #default_schedule_zone = - # Length of generated instance admin passwords (integer value) # Minimum value = 0 #password_length = 12 password_length = 100 - # # Time period to generate instance usages for. It is possible to define optional # offset to given period by appending @ character followed by a number defining # offset. For more information, refer to the documentation. (string value) #instance_usage_audit_period = month instance_usage_audit_period = blah blah blah - test = test1,test2 [SubSection] #Comments and overrides in a subsection #testopt1 = 9000 testopt1 = 9000 - # This is another test opt #testop2 = over 9000 diff --git a/tests/files/test_default_section.ini.expected b/tests/files/test_default_section.ini.expected index 94540b9..1e0d5eb 100644 --- a/tests/files/test_default_section.ini.expected +++ b/tests/files/test_default_section.ini.expected @@ -1,9 +1,11 @@ [global] test1 = 1 # This is a post option comment - test2 = 2 [section1] setting1 = 1 -setting2 = 2 \ No newline at end of file +setting2 = 2 + +[section2] +setting3 = diff --git a/tests/files/test_remote_src_multistropts.ini.expected b/tests/files/test_remote_src_multistropts.ini.expected index 5887042..8a8c384 100644 --- a/tests/files/test_remote_src_multistropts.ini.expected +++ b/tests/files/test_remote_src_multistropts.ini.expected @@ -3,10 +3,8 @@ test = test1 test = test2 test = test3 - [testsection] test = output - [remote_src_section] test = output diff --git a/tests/templates/test_default_section.ini b/tests/templates/test_default_section.ini index d759463..f241b84 100644 --- a/tests/templates/test_default_section.ini +++ b/tests/templates/test_default_section.ini @@ -3,4 +3,7 @@ test1 = 1 # This is a post option comment [section1] -setting1 = 1 \ No newline at end of file +setting1 = 1 + +[section2] +setting3 = \ No newline at end of file