From f2c7db7a99cd2d087666e1d3e07d267c56f24419 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Mon, 3 Dec 2018 20:32:41 +0000 Subject: [PATCH] [sonic-cfggen] Multi-key should be in form of (a,b) instead of 'a|b' --- files/build_templates/buffers_config.j2 | 3 +-- src/sonic-config-engine/minigraph.py | 9 ++++----- src/sonic-config-engine/tests/test_cfggen.py | 4 ++-- src/sonic-config-engine/tests/test_minigraph_case.py | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/files/build_templates/buffers_config.j2 b/files/build_templates/buffers_config.j2 index b4d260092c43..859ba7b307dd 100644 --- a/files/build_templates/buffers_config.j2 +++ b/files/build_templates/buffers_config.j2 @@ -60,8 +60,7 @@ def {%- else %} {%- if switch_role.lower() == 'torrouter' %} {%- for local_port in VLAN_MEMBER %} - {%- set vlan_port = local_port.split("|") %} - {%- if vlan_port[1] == port_name %} + {%- if local_port[1] == port_name %} {%- set roles3 = switch_role + '_' + 'server' %} {%- set roles3 = roles3 | lower %} {%- if roles3 in ports2cable %} diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 2352229decf1..319013c80bfd 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -25,7 +25,6 @@ ns1 = "http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution" ns2 = "Microsoft.Search.Autopilot.NetMux" ns3 = "http://www.w3.org/2001/XMLSchema-instance" -KEY_SEPARATOR = '|' class minigraph_encoder(json.JSONEncoder): def default(self, obj): @@ -187,7 +186,7 @@ def parse_dpg(dpg, hname): for i, member in enumerate(pcmbr_list): pcmbr_list[i] = port_alias_map.get(member, member) intfs_inpc.append(pcmbr_list[i]) - pc_members[pcintfname + KEY_SEPARATOR + pcmbr_list[i]] = {'NULL': 'NULL'} + pc_members[(pcintfname, pcmbr_list[i])] = {'NULL': 'NULL'} if pcintf.find(str(QName(ns, "Fallback"))) != None: pcs[pcintfname] = {'members': pcmbr_list, 'fallback': pcintf.find(str(QName(ns, "Fallback"))).text, 'min_links': str(int(math.ceil(len() * 0.75)))} else: @@ -204,8 +203,8 @@ def parse_dpg(dpg, hname): vmbr_list = vintfmbr.split(';') for i, member in enumerate(vmbr_list): vmbr_list[i] = port_alias_map.get(member, member) - sonic_vlan_member_name = "Vlan%s%s%s" % (vlanid, KEY_SEPARATOR, vmbr_list[i]) - vlan_members[sonic_vlan_member_name] = {'tagging_mode': 'untagged'} + sonic_vlan_member_name = "Vlan%s" % (vlanid) + vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'untagged'} vlan_attributes = {'vlanid': vlanid} @@ -543,7 +542,7 @@ def parse_xml(filename, platform=None, port_config_file=None): ports.get(port[0])['admin_status'] = 'up' for member in pc_members.keys() + vlan_members.keys(): - port = ports.get(member.split(KEY_SEPARATOR)[1]) + port = ports.get(member[1]) if port: port['admin_status'] = 'up' diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 44ea54c2a65f..f4ac56807ec5 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -110,7 +110,7 @@ def test_minigraph_vlans(self): def test_minigraph_vlan_members(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN_MEMBER' output = self.run_script(argument) - self.assertEqual(output.strip(), "{'Vlan1000|Ethernet8': {'tagging_mode': 'untagged'}}") + self.assertEqual(output.strip(), "{('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}}") def test_minigraph_vlan_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"' @@ -130,7 +130,7 @@ def test_minigraph_portchannel_with_more_member(self): def test_minigraph_portchannel_members(self): argument = '-m "' + self.sample_graph_pc_test + '" -p "' + self.port_config + '" -v "PORTCHANNEL_MEMBER.keys()"' output = self.run_script(argument) - self.assertEqual(output.strip(), "['PortChannel01|Ethernet112', 'PortChannel01|Ethernet124', 'PortChannel01|Ethernet116', 'PortChannel01|Ethernet120']") + self.assertEqual(output.strip(), "[('PortChannel01', 'Ethernet120'), ('PortChannel01', 'Ethernet116'), ('PortChannel01', 'Ethernet124'), ('PortChannel01', 'Ethernet112')]") def test_minigraph_portchannel_interfaces(self): argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORTCHANNEL_INTERFACE.keys()"' diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 67a82abb09b6..b58d8e05e1dd 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -77,7 +77,7 @@ def test_minigraph_vlans(self): def test_minigraph_vlan_members(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v VLAN_MEMBER' output = self.run_script(argument) - self.assertEqual(output.strip(), "{'Vlan1000|Ethernet8': {'tagging_mode': 'untagged'}}") + self.assertEqual(output.strip(), "{('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}}") def test_minigraph_vlan_interfaces(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"'