From 726f34379dfce5d638bb644de38b479eb42f86c0 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Fri, 20 Jan 2017 23:27:03 -0500 Subject: [PATCH] Got carryover indention correct. --- keepalived/templates/config.jinja | 10 ++++++---- test/test_keepalived_config.py | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja index d68ec45..5a37e77 100644 --- a/keepalived/templates/config.jinja +++ b/keepalived/templates/config.jinja @@ -17,15 +17,17 @@ {%- set indentHolder = indent -%} {%- for item in data|dictsort -%} {%- if item[key] in carryovers -%} - {{- keepalived_config(item[value], carryover=item[key]) -}} + {{- keepalived_config(item[value], carryover=item[key], indent=indent) -}} {%- else -%} + {%- set carryIndent = indentHolder -%} {%- if carryover -%} - {{- carryover }}{{ ' ' -}} + {{- carryover|indent(indentHolder, True) }}{{ ' ' -}} + {%- set carryIndent = 0 -%} {%- endif -%} {%- if item[value] is string or item[value] is not iterable -%} {%- set indent = 0 -%} {%- endif -%} - {{- item[key]|indent(indentHolder, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=indent) -}} + {{- item[key]|indent(carryIndent, True) }} {{ keepalived_config(item[value], recurse=recurse, indent=indent) -}} {%- endif -%} {%- endfor -%} {%- else -%} @@ -34,7 +36,7 @@ {%- endfor -%} {%- endif -%} {%- if recurse > 0 -%} - {{- '}\n' -}} + {{- '}'|indent(indent - 2, True) -}}{{ '\n' }} {%- endif -%} {%- endif -%} {%- endmacro -%} diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py index 27c88e7..bfcbc85 100755 --- a/test/test_keepalived_config.py +++ b/test/test_keepalived_config.py @@ -69,7 +69,7 @@ class TestKeepalivedConfiguration(unittest.TestCase): result = 'vrrp_script gizmo {\n fred flintstone\n barney rubble\n}\n' self.renderTest(testdata, result) - def test_carrover_vrrp_instance(self): + def test_carryover_vrrp_instance(self): testdata = {'vrrp_instance': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}} result = 'vrrp_instance gizmo {\n barney rubble\n fred flintstone\n}\n' self.renderTest(testdata, result) @@ -79,25 +79,30 @@ class TestKeepalivedConfiguration(unittest.TestCase): result = 'vrrp_script gizmo {\n running dumdums\n}\nvrrp_instance dumdums {\n fred flintstone\n}\n' self.renderTest(testdata, result) - def test_carrover_vrrp_sync_group(self): + def test_carryover_vrrp_sync_group(self): testdata = {'vrrp_sync_group': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}} result = 'vrrp_sync_group gizmo {\n barney rubble\n fred flintstone\n}\n' self.renderTest(testdata, result) - def test_carrover_virtual_server_group(self): + def test_carryover_virtual_server_group(self): testdata = {'virtual_server_group': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}} result = 'virtual_server_group gizmo {\n barney rubble\n fred flintstone\n}\n' self.renderTest(testdata, result) - def test_carrover_virtual_server(self): + def test_carryover_virtual_server(self): testdata = {'virtual_server': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}} result = 'virtual_server gizmo {\n barney rubble\n fred flintstone\n}\n' self.renderTest(testdata, result) - def test_carrover_real_server(self): + def test_carryover_real_server(self): testdata = {'real_server': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}} result = 'real_server gizmo {\n barney rubble\n fred flintstone\n}\n' self.renderTest(testdata, result) + def test_carryover_within_carryover(self): + testdata = {'virtual_server': {'gizmo': {'real_server': {'dumdums': {'fred': 'flintstone', 'barney': 'rubble'}}}}} + result = 'virtual_server gizmo {\n real_server dumdums {\n barney rubble\n fred flintstone\n }\n}\n' + self.renderTest(testdata, result) + if __name__ == '__main__': unittest.main()