From 2f8ff3ec6bc2e7658ed681d5e8e36cc997f79494 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 21 Jan 2017 00:12:44 -0500 Subject: [PATCH] Corrected carryover indention. --- keepalived/templates/config.jinja | 5 +++-- test/test_keepalived_config.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja index 5a37e77..528d267 100644 --- a/keepalived/templates/config.jinja +++ b/keepalived/templates/config.jinja @@ -20,14 +20,15 @@ {{- keepalived_config(item[value], carryover=item[key], indent=indent) -}} {%- else -%} {%- set carryIndent = indentHolder -%} + {%- set forwardIndent = indentHolder -%} {%- if carryover -%} {{- carryover|indent(indentHolder, True) }}{{ ' ' -}} {%- set carryIndent = 0 -%} {%- endif -%} {%- if item[value] is string or item[value] is not iterable -%} - {%- set indent = 0 -%} + {%- set forwardIndent = 0 -%} {%- endif -%} - {{- item[key]|indent(carryIndent, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=indent) -}} + {{- item[key]|indent(carryIndent, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=forwardIndent) -}} {%- endif -%} {%- endfor -%} {%- else -%} diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py index bfcbc85..c275160 100755 --- a/test/test_keepalived_config.py +++ b/test/test_keepalived_config.py @@ -104,5 +104,15 @@ class TestKeepalivedConfiguration(unittest.TestCase): result = 'virtual_server gizmo {\n real_server dumdums {\n barney rubble\n fred flintstone\n }\n}\n' self.renderTest(testdata, result) + def test_indent_nested_hashes(self): + testdata = {'flintstone': {'fred': {'role': {'family': 'father'}}}} + result = 'flintstone {\n fred {\n role {\n family father\n }\n }\n}\n' + self.renderTest(testdata, result) + + def test_indent_carryover_with_nested_hashes(self): + testdata = {'real_server': {'gizmo': {'another': 'day', 'dumdums': {'fred': 'flintstone', 'barney': 'rubble'}}}} + result = 'real_server gizmo {\n another day\n dumdums {\n barney rubble\n fred flintstone\n }\n}\n' + self.renderTest(testdata, result) + if __name__ == '__main__': unittest.main()