Got carryover indention correct.

This commit is contained in:
Jeff Baskin 2017-01-20 23:27:03 -05:00
parent 306fd72287
commit 726f34379d
2 changed files with 16 additions and 9 deletions

View File

@ -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 -%}

View File

@ -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()