diff --git a/src/sonic-config-engine/data/l2switch.j2 b/src/sonic-config-engine/data/l2switch.j2 index c9f166b679..22de3158c5 100644 --- a/src/sonic-config-engine/data/l2switch.j2 +++ b/src/sonic-config-engine/data/l2switch.j2 @@ -2,13 +2,16 @@ "DEVICE_METADATA": {{ DEVICE_METADATA | tojson }}, {% set ns = {'firstPrinted': False} -%} "PORT": { - {%- for key,value in PORT.iteritems() -%} + {%- for key, value in PORT.items() -%} {%- if ns.firstPrinted %},{% endif %} "{{ key }}": { - "alias": "{{ value.alias }}", - "lanes": "{{ value.lanes }}", - "admin_status": "up" + {%- for keyPort, valuePort in value.items() %} + + {% if keyPort != "admin_status" %}"{{ keyPort }}": "{{ valuePort }}",{% endif %} + {%- endfor %} + + "admin_status": "{{ value.admin_status|default("up") }}" } {%- if ns.update({'firstPrinted': True}) %}{% endif -%} {%- endfor %} diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index c4c100a449..1eccdd94ee 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -99,6 +99,13 @@ class TestJ2Files(TestCase): self.assertTrue(json.dumps(sample_output_json, sort_keys=True) == json.dumps(output_json, sort_keys=True)) + template_dir = os.path.join(self.test_dir, '..', 'data', 'l2switch.j2') + argument = '-t ' + template_dir + ' -k Mellanox-SN2700 -p ' + self.t0_port_config + output = self.run_script(argument) + output_json = json.loads(output) + + self.assertTrue(json.dumps(sample_output_json, sort_keys=True) == json.dumps(output_json, sort_keys=True)) + def test_qos_arista7050_render_template(self): arista_dir_path = os.path.join(self.test_dir, '..', '..', '..', 'device', 'arista', 'x86_64-arista_7050_qx32s', 'Arista-7050-QX-32S') qos_file = os.path.join(arista_dir_path, 'qos.json.j2')