diff --git a/dockers/docker-teamd/teamd.j2 b/dockers/docker-teamd/teamd.j2 index 08a3415f51..d6693719f1 100644 --- a/dockers/docker-teamd/teamd.j2 +++ b/dockers/docker-teamd/teamd.j2 @@ -5,7 +5,7 @@ "name": "lacp", "active": true, {# Use 75% links upperbound as min-links #} - "min_ports": {{ minigraph_portchannels[pc]['members'] | length * 0.75 | round(0, 'ceil') | int}}, + "min_ports": {{ (minigraph_portchannels[pc]['members'] | length * 0.75) | round(0, 'ceil') | int }}, "tx_hash": ["eth", "ipv4", "ipv6"] }, "link_watch": { @@ -13,7 +13,7 @@ }, "ports": { {% for member in minigraph_portchannels[pc]['members'] %} - "{{member}}": {}{% if not loop.last %},{% endif %} + "{{ member }}": {}{% if not loop.last %},{% endif %} {% endfor %} } diff --git a/src/sonic-config-engine/tests/sample_output/pc_sample_output/PortChannel01.conf b/src/sonic-config-engine/tests/sample_output/pc_sample_output/PortChannel01.conf new file mode 100644 index 0000000000..618e9baad6 --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/pc_sample_output/PortChannel01.conf @@ -0,0 +1,20 @@ +{ + "device": "PortChannel01", + "hwaddr": "e4:1d:2d:a5:f3:ad", + "runner": { + "name": "lacp", + "active": true, + "min_ports": 3, + "tx_hash": ["eth", "ipv4", "ipv6"] + }, + "link_watch": { + "name": "ethtool" + }, + "ports": { + "Ethernet112": {}, + "Ethernet116": {}, + "Ethernet120": {}, + "Ethernet124": {} + } +} + diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel01.conf b/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel01.conf similarity index 100% rename from src/sonic-config-engine/tests/sample_output/PortChannel01.conf rename to src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel01.conf diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel02.conf b/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel02.conf similarity index 100% rename from src/sonic-config-engine/tests/sample_output/PortChannel02.conf rename to src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel02.conf diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel03.conf b/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel03.conf similarity index 100% rename from src/sonic-config-engine/tests/sample_output/PortChannel03.conf rename to src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel03.conf diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel04.conf b/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel04.conf similarity index 100% rename from src/sonic-config-engine/tests/sample_output/PortChannel04.conf rename to src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel04.conf diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index 2a8c7a3568..238d8c8155 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -10,6 +10,7 @@ class TestJ2Files(TestCase): self.test_dir = os.path.dirname(os.path.realpath(__file__)) self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen') 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') self.output_file = os.path.join(self.test_dir, 'output') @@ -30,21 +31,33 @@ class TestJ2Files(TestCase): self.assertEqual(data["Ethernet4"], "fortyGigE0/4") def test_teamd(self): + + def test_render_teamd(self, pc, minigraph, sample_output): + teamd_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-teamd', 'teamd.j2') + argument = '-m ' + minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\",\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + teamd_file + ' > ' + self.output_file + self.run_script(argument) + self.assertTrue(filecmp.cmp(sample_output, self.output_file)) + + # Test T0 minigraph argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -v "minigraph_portchannels.keys() | join(\' \')"' output = self.run_script(argument) # Mock the output via config.sh in docker-teamd pc_list = output.split() - def test_render_teamd(self, pc): - teamd_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-teamd', 'teamd.j2') - sample_output_file = os.path.join(self.test_dir, 'sample_output',pc + '.conf') - argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\",\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + teamd_file + ' > ' + self.output_file - self.run_script(argument) - assert filecmp.cmp(sample_output_file, self.output_file) - for i in range(1, 5): pc_name = 'PortChannel0' + str(i) - assert pc_name in pc_list - test_render_teamd(self, pc_name) + self.assertTrue(pc_name in pc_list) + sample_output = os.path.join(self.test_dir, 'sample_output', 't0_sample_output', pc_name + '.conf') + test_render_teamd(self, pc_name, self.t0_minigraph, sample_output) + + # Test port channel test minigraph + argument = '-m ' + self.pc_minigraph + ' -p ' + self.t0_port_config + ' -v "minigraph_portchannels.keys() | join(\' \')"' + output = self.run_script(argument) # Mock the output via config.sh in docker-teamd + pc_list = output.split() + + pc_name = 'PortChannel01' + self.assertTrue(pc_name in pc_list) + sample_output = os.path.join(self.test_dir, 'sample_output', 'pc_sample_output', pc_name + '.conf') + test_render_teamd(self, pc_name, self.pc_minigraph, sample_output) def test_ipinip(self): ipinip_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-orchagent', 'ipinip.json.j2')