Merge "Utilise sorted to ensure no random changes"

This commit is contained in:
Zuul 2018-03-30 06:56:19 +00:00 committed by Gerrit Code Review
commit 6036837b44
2 changed files with 47 additions and 3 deletions

View File

@ -170,16 +170,16 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
if self._defaults: if self._defaults:
_write_comments('DEFAULT') _write_comments('DEFAULT')
fp.write("[%s]\n" % 'DEFAULT') fp.write("[%s]\n" % 'DEFAULT')
for key, value in self._defaults.items(): for key, value in sorted(self._defaults.items()):
_write_comments('DEFAULT', optname=key) _write_comments('DEFAULT', optname=key)
self._write_check(fp, key=key, value=value) self._write_check(fp, key=key, value=value)
else: else:
fp.write("\n") fp.write("\n")
for section in self._sections: for section in sorted(self._sections):
_write_comments(section) _write_comments(section)
fp.write("[%s]\n" % section) fp.write("[%s]\n" % section)
for key, value in self._sections[section].items(): for key, value in sorted(self._sections[section].items()):
_write_comments(section, optname=key) _write_comments(section, optname=key)
self._write_check(fp, key=key, value=value, section=True) self._write_check(fp, key=key, value=value, section=True)
else: else:

View File

@ -203,12 +203,56 @@
- "{{ ini_file.content | b64decode | search('#This is a comment')}}" - "{{ ini_file.content | b64decode | search('#This is a comment')}}"
- "{{ ini_file.content | b64decode | search('# A default section comment\n# broken into multiple lines\n\\[DEFAULT\\]')}}" - "{{ ini_file.content | b64decode | search('# A default section comment\n# broken into multiple lines\n\\[DEFAULT\\]')}}"
- name: Template multiple times to assert no changes
config_template:
src: "{{ playbook_dir }}/templates/test_with_comments.ini"
dest: "/tmp/test_with_comments.ini"
config_type: "ini"
config_overrides: "{{ item[1] }}"
register: template_changed
failed_when: template_changed | changed
with_nested:
- [ 0, 1, 2 ]
- [ "{{ test_config_ini_overrides }}" ]
vars: vars:
test_config_ini_overrides: test_config_ini_overrides:
DEFAULT: DEFAULT:
new_key: "new_value" new_key: "new_value"
foo: foo:
baz: "bar" baz: "bar"
section1:
key1: "value1"
key2: "value2"
key3: "value3"
key4: "value4"
key5: "value5"
key6: "value6"
key7: "value7"
key8: "value8"
key9: "value9"
key10: "value10"
key11: "value11"
section2:
key1: "value1"
section3:
key1: "value1"
section4:
key1: "value1"
section5:
key1: "value1"
section6:
key1: "value1"
section7:
key1: "value1"
section8:
key1: "value1"
section9:
key1: "value1"
section10:
key1: "value1"
section11:
key1: "value1"
test_config_yml_overrides: test_config_yml_overrides:
list_one: list_one:
- four - four