Skip to content

Commit

Permalink
[swss]: Fix missing comma in the ports.json.j2 file
Browse files Browse the repository at this point in the history
Add J2 test case as well as a sample output

Signed-off-by: Shu0T1an ChenG <[email protected]>
  • Loading branch information
Shu0T1an ChenG committed Dec 8, 2017
1 parent 4b2225b commit 6a4af89
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dockers/docker-orchagent/ports.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if PORT[port].has_key('speed') %}
{
"PORT_TABLE:{{ port }}": {
"speed": "{{ PORT[port]['speed'] }}"
"speed": "{{ PORT[port]['speed'] }}",
"description": "{{ PORT[port]['description'] }}"
},
"OP": "SET"
Expand Down
30 changes: 30 additions & 0 deletions src/sonic-config-engine/tests/sample_output/ports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"PORT_TABLE:Ethernet8": {
"speed": "40000",
"description": "Interface description"
},
"OP": "SET"
},
{
"PORT_TABLE:Ethernet0": {
"speed": "10000",
"description": ""
},
"OP": "SET"
},
{
"PORT_TABLE:Ethernet4": {
"speed": "25000",
"description": ""
},
"OP": "SET"
},
{
"PORT_TABLE:Ethernet12": {
"speed": "1000000",
"description": "Interface description"
},
"OP": "SET"
},
]
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/simple-sample-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
<PortName>0</PortName>
<Priority>0</Priority>
<Speed>1000000</Speed>
<Description>Interface description</Description>
</a:EthernetInterface>
</EthernetInterfaces>
<FlowControl>true</FlowControl>
Expand Down
7 changes: 7 additions & 0 deletions src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestJ2Files(TestCase):
def setUp(self):
self.test_dir = os.path.dirname(os.path.realpath(__file__))
self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen')
self.simple_minigraph = os.path.join(self.test_dir, 'simple-sample-graph.xml')
self.t0_minigraph = os.path.join(self.test_dir, 't0-sample-graph.xml')
self.pc_minigraph = os.path.join(self.test_dir, 'pc-test-graph.xml')
self.t0_port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini')
Expand All @@ -33,6 +34,12 @@ def test_alias_map(self):
data = json.loads(output)
self.assertEqual(data["Ethernet4"], "fortyGigE0/4")

def test_ports_json(self):
ports_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'ports.json.j2')
argument = '-m ' + self.simple_minigraph + ' -p ' + self.t0_port_config + ' -t ' + ports_template + ' > ' + self.output_file
self.run_script(argument)
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'ports.json'), self.output_file))

def test_lldp(self):
lldpd_conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-lldp-sv2', 'lldpd.conf.j2')
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + lldpd_conf_template + ' > ' + self.output_file
Expand Down

0 comments on commit 6a4af89

Please sign in to comment.