Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teamd]: Fix Jinja2 template for calculating min_ports #791

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dockers/docker-teamd/teamd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"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": {
"name": "ethtool"
},
"ports": {
{% for member in minigraph_portchannels[pc]['members'] %}
"{{member}}": {}{% if not loop.last %},{% endif %}
"{{ member }}": {}{% if not loop.last %},{% endif %}

{% endfor %}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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": {}
}
}

31 changes: 22 additions & 9 deletions src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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.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')

Expand All @@ -30,21 +31,33 @@ def test_alias_map(self):
self.assertEqual(data["Ethernet4"], "fortyGigE0/4")

def test_teamd(self):
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):
def test_render_teamd(self, pc, minigraph, sample_output):
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
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)
assert filecmp.cmp(sample_output_file, self.output_file)
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()

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')
Expand Down