Addresses comments in #38971 (#44324)

* Controlled params within no section

* Added tests to control params within no section

* Cleaning output_file before creating no-section params and check the content

* addresses comment in PR "s/hate/beverage/g"
This commit is contained in:
codylane 2018-10-29 05:33:14 -06:00 committed by John R Barker
commit d3fe6c01f2
2 changed files with 115 additions and 6 deletions

View file

@ -171,9 +171,22 @@ def do_ini(module, filename, section=None, option=None, value=None,
ini_lines[-1] += '\n'
changed = True
# append a fake section line to simplify the logic
# append fake section lines to simplify the logic
# At top:
# Fake random section to do not match any other in the file
# Using commit hash as fake section name
fake_section_name = "ad01e11446efb704fcdbdb21f2c43757423d91c5"
# Insert it at the beginning
ini_lines.insert(0, '[%s]' % fake_section_name)
# At botton:
ini_lines.append('[')
# If no section is defined, fake section is used
if not section:
section = fake_section_name
within_section = not section
section_start = 0
msg = 'OK'
@ -241,6 +254,7 @@ def do_ini(module, filename, section=None, option=None, value=None,
break
# remove the fake section line
del ini_lines[0]
del ini_lines[-1:]
if not within_section and option and state == 'present':