From da070c862b3da5887c41beb499a3b167bbb6b121 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 18 Jan 2017 21:38:51 -0500 Subject: [PATCH] Added ordered hashes. --- keepalived/templates/config.jinja | 8 ++++++-- test/test_keepalived_config.py | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja index fa46d41..e02881f 100644 --- a/keepalived/templates/config.jinja +++ b/keepalived/templates/config.jinja @@ -17,10 +17,14 @@ {{- '}\n' -}} {%- endif -%} {%- else -%} - {{- '{\n' -}} + {%- if recurse > 0 -%} + {{- '{\n' -}} + {%- endif -%} {%- for item in data -%} {{- keepalived_config(item) -}} {%- endfor -%} - {{- '}\n' -}} + {%- if recurse > 0 -%} + {{- '}\n' -}} + {%- endif -%} {%- endif -%} {%- endmacro -%} diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py index 1aed30a..30abe51 100755 --- a/test/test_keepalived_config.py +++ b/test/test_keepalived_config.py @@ -54,5 +54,10 @@ class TestKeepalivedConfiguration(unittest.TestCase): result = 'friends {\nbarney rubble\nbetty rubble\nfred flintstone\nwilma flintstone\n}\n' self.renderTest(testdata, result) + def test_ordered_hashes(self): + testdata = [{'fred': 'flintstone'}, {'wilma': 'flintstone'}, {'barney': 'rubble'}, {'betty': 'rubble'}] + result = 'fred flintstone\nwilma flintstone\nbarney rubble\nbetty rubble\n' + self.renderTest(testdata, result) + if __name__ == '__main__': unittest.main()