Skip to content

Commit 3e316cb

Browse files
authored
Don't create the members@ array in config_db for PC when reading from minigraph (#13660)
Fixes #11873. #### Why I did it When loading from minigraph, for port channels, don't create the members@ array in config_db in the PORTCHANNEL table. This is no longer needed or used. In addition, when adding a port channel member from the CLI, that member doesn't get added into the members@ array, resulting in a bit of inconsistency. This gets rid of that inconsistency.
1 parent f4550e8 commit 3e316cb

File tree

10 files changed

+30
-96
lines changed

10 files changed

+30
-96
lines changed

src/sonic-config-engine/minigraph.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ def parse_dpg(dpg, hname):
532532
intfs_inpc.append(pcmbr_list[i])
533533
pc_members[(pcintfname, pcmbr_list[i])] = {}
534534
if pcintf.find(str(QName(ns, "Fallback"))) != None:
535-
pcs[pcintfname] = {'members': pcmbr_list, 'fallback': pcintf.find(str(QName(ns, "Fallback"))).text, 'min_links': str(int(math.ceil(len() * 0.75))), 'lacp_key': 'auto'}
535+
pcs[pcintfname] = {'fallback': pcintf.find(str(QName(ns, "Fallback"))).text, 'min_links': str(int(math.ceil(len() * 0.75))), 'lacp_key': 'auto'}
536536
else:
537-
pcs[pcintfname] = {'members': pcmbr_list, 'min_links': str(int(math.ceil(len(pcmbr_list) * 0.75))), 'lacp_key': 'auto' }
537+
pcs[pcintfname] = {'min_links': str(int(math.ceil(len(pcmbr_list) * 0.75))), 'lacp_key': 'auto' }
538538
port_nhipv4_map = {}
539539
port_nhipv6_map = {}
540540
nhg_int = ""
@@ -1244,7 +1244,7 @@ def filter_acl_table_for_backend(acls, vlan_members):
12441244
}
12451245
return filter_acls
12461246

1247-
def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role, device_type, is_storage_device, vlan_members):
1247+
def filter_acl_table_bindings(acls, neighbors, port_channels, pc_members, sub_role, device_type, is_storage_device, vlan_members):
12481248
if device_type == 'BackEndToRRouter' and is_storage_device:
12491249
return filter_acl_table_for_backend(acls, vlan_members)
12501250

@@ -1263,8 +1263,8 @@ def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role, device_t
12631263

12641264
# Get the front panel port channel.
12651265
for port_channel_intf in port_channels:
1266-
backend_port_channel = any(lag_member in backplane_port_list \
1267-
for lag_member in port_channels[port_channel_intf]['members'])
1266+
backend_port_channel = any(lag_member[1] in backplane_port_list \
1267+
for lag_member in list(pc_members.keys()) if lag_member[0] == port_channel_intf)
12681268
if not backend_port_channel:
12691269
front_port_channel_intf.append(port_channel_intf)
12701270

@@ -1763,12 +1763,15 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
17631763

17641764
if port_config_file:
17651765
port_set = set(ports.keys())
1766-
for (pc_name, mbr_map) in list(pcs.items()):
1766+
for (pc_name, pc_member) in list(pc_members.keys()):
17671767
# remove portchannels that contain ports not existing in port_config.ini
17681768
# when port_config.ini exists
1769-
if not set(mbr_map['members']).issubset(port_set):
1770-
print("Warning: ignore '%s' as part of its member interfaces is not in the port_config.ini" % pc_name, file=sys.stderr)
1769+
if (pc_name, pc_member) in pc_members and pc_member not in port_set:
1770+
print("Warning: ignore '%s' as at least one of its member interfaces ('%s') is not in the port_config.ini" % (pc_name, pc_member), file=sys.stderr)
17711771
del pcs[pc_name]
1772+
pc_mbr_del_keys = [f for f in list(pc_members.keys()) if f[0] == pc_name]
1773+
for pc_mbr_del_key in pc_mbr_del_keys:
1774+
del pc_members[pc_mbr_del_key]
17721775

17731776
# set default port channel MTU as 9100 and admin status up and default TPID 0x8100
17741777
for pc in pcs.values():
@@ -1872,7 +1875,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
18721875
results['DHCP_RELAY'] = dhcp_relay_table
18731876
results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers)
18741877
results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers)
1875-
results['ACL_TABLE'] = filter_acl_table_bindings(acls, neighbors, pcs, sub_role, current_device['type'], is_storage_device, vlan_members)
1878+
results['ACL_TABLE'] = filter_acl_table_bindings(acls, neighbors, pcs, pc_members, sub_role, current_device['type'], is_storage_device, vlan_members)
18761879
results['FEATURE'] = {
18771880
'telemetry': {
18781881
'state': 'enabled'

src/sonic-config-engine/tests/test_cfggen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ def test_minigraph_portchannels(self, **kwargs):
328328
output = self.run_script(argument)
329329
self.assertEqual(
330330
utils.to_dict(output.strip()),
331-
utils.to_dict("{'PortChannel1': {'admin_status': 'up', 'min_links': '1', 'members': ['Ethernet4'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}")
331+
utils.to_dict("{'PortChannel1': {'admin_status': 'up', 'min_links': '1', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}")
332332
)
333333

334334
def test_minigraph_portchannel_with_more_member(self):
335335
argument = ['-m', self.sample_graph_pc_test, '-p', self.port_config, '-v', 'PORTCHANNEL']
336336
output = self.run_script(argument)
337337
self.assertEqual(
338338
utils.to_dict(output.strip()),
339-
utils.to_dict("{'PortChannel01': {'admin_status': 'up', 'min_links': '3', 'members': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}"))
339+
utils.to_dict("{'PortChannel01': {'admin_status': 'up', 'min_links': '3', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}"))
340340

341341
def test_minigraph_portchannel_members(self):
342342
argument = ['-m', self.sample_graph_pc_test, '-p', self.port_config, '-v', "PORTCHANNEL_MEMBER.keys()|list"]

src/sonic-config-engine/tests/test_minigraph_case.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_minigraph_portchannels(self):
158158
output = self.run_script(argument)
159159
self.assertEqual(
160160
utils.to_dict(output.strip()),
161-
utils.to_dict("{'PortChannel01': {'admin_status': 'up', 'min_links': '1', 'members': ['Ethernet4'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}")
161+
utils.to_dict("{'PortChannel01': {'admin_status': 'up', 'min_links': '1', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}}")
162162
)
163163

164164
def test_minigraph_console_mgmt_feature(self):

src/sonic-config-engine/tests/test_multinpu_cfggen.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ def test_frontend_asic_portchannels(self):
161161
argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "--var-json", "PORTCHANNEL"]
162162
output = json.loads(self.run_script(argument))
163163
self.assertDictEqual(output, \
164-
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet0', 'Ethernet4'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
165-
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP0', 'Ethernet-BP4'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
166-
'PortChannel4002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP8', 'Ethernet-BP12'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}})
164+
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
165+
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
166+
'PortChannel4002': {'admin_status': 'up', 'min_links': '2', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}})
167167

168168
def test_backend_asic_portchannels(self):
169169
argument = ["-m", self.sample_graph, "-p", self.port_config[3], "-n", "asic3", "--var-json", "PORTCHANNEL"]
170170
output = json.loads(self.run_script(argument))
171171
self.assertDictEqual(output, \
172-
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP384', 'Ethernet-BP388'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
173-
'PortChannel4014': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP392', 'Ethernet-BP396'], 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}})
172+
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'},
173+
'PortChannel4014': {'admin_status': 'up', 'min_links': '2', 'mtu': '9100', 'tpid': '0x8100', 'lacp_key': 'auto'}})
174174

175175
def test_frontend_asic_portchannel_mem(self):
176176
argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "-v", "PORTCHANNEL_MEMBER.keys()|list"]

src/sonic-yang-mgmt/tests/test_cfghelp.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@
7171
7272
"""
7373

74-
portchannel_table_field_output="""\
74+
vlan_table_field_output="""\
7575
76-
PORTCHANNEL
77-
Description: PORTCHANNEL part of config_db.json
76+
VLAN
77+
Description: VLAN part of config_db.json
7878
7979
key - name
80-
+---------+-------------------------------------------+-------------+-----------+-------------+
81-
| Field | Description | Mandatory | Default | Reference |
82-
+=========+===========================================+=============+===========+=============+
83-
| members | The field contains list of unique members | | | PORT:name |
84-
+---------+-------------------------------------------+-------------+-----------+-------------+
80+
+--------------+------------------------------------------------------------------------+-------------+-----------+-------------+
81+
| Field | Description | Mandatory | Default | Reference |
82+
+==============+========================================================================+=============+===========+=============+
83+
| dhcp_servers | The field contains list of unique membersConfigure the dhcp v4 servers | | | |
84+
+--------------+------------------------------------------------------------------------+-------------+-----------+-------------+
8585
8686
"""
8787

@@ -153,9 +153,9 @@ def test_single_field(self):
153153
self.assertEqual(output, techsupport_table_field_output)
154154

155155
def test_leaf_list(self):
156-
argument = ['-t', 'PORTCHANNEL', '-f', 'members']
156+
argument = ['-t', 'VLAN', '-f', 'dhcp_servers']
157157
output = self.run_script(argument)
158-
self.assertEqual(output, portchannel_table_field_output)
158+
self.assertEqual(output, vlan_table_field_output)
159159

160160
def test_leaf_list_map(self):
161161
argument = ['-t', 'DSCP_TO_TC_MAP']

src/sonic-yang-models/tests/files/sample_config_db.json

-13
Original file line numberDiff line numberDiff line change
@@ -86,39 +86,26 @@
8686
"PortChannel0003": {
8787
"admin_status": "up",
8888
"min_links": "1",
89-
"members": [
90-
"Ethernet1"
91-
],
9289
"tpid": "0x8100",
9390
"mtu": "9100",
9491
"lacp_key": "auto"
9592
},
9693
"PortChannel0004": {
9794
"admin_status": "up",
9895
"min_links": "1",
99-
"members": [
100-
"Ethernet2"
101-
],
10296
"tpid": "0x9200",
10397
"mtu": "9100",
10498
"lacp_key": "auto"
10599
},
106100
"PortChannel2": {
107101
"admin_status": "up",
108102
"min_links": "1",
109-
"members": [
110-
"Ethernet12"
111-
],
112103
"tpid": "0x9200",
113104
"mtu": "9100",
114105
"lacp_key": "auto"
115106
},
116107
"PortChannel42": {
117108
"admin_status": "up",
118-
"members": [
119-
"Ethernet-BP0",
120-
"Ethernet-BP4"
121-
],
122109
"min_links": "2",
123110
"mtu": "9100",
124111
"tpid": "0x8100"

src/sonic-yang-models/tests/yang_model_tests/tests_config/mclag.json

-9
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@
2929
"PORTCHANNEL_LIST": [
3030
{
3131
"admin_status": "up",
32-
"members": [
33-
"Ethernet0"
34-
],
3532
"min_links": "1",
3633
"mtu": "9100",
3734
"lacp_key": "auto",
3835
"name": "PortChannel2"
3936
},
4037
{
4138
"admin_status": "up",
42-
"members": [
43-
"Ethernet10"
44-
],
4539
"min_links": "1",
4640
"mtu": "9100",
4741
"lacp_key": "auto",
@@ -151,9 +145,6 @@
151145
"PORTCHANNEL_LIST": [
152146
{
153147
"admin_status": "up",
154-
"members": [
155-
"Ethernet0"
156-
],
157148
"min_links": "1",
158149
"mtu": "9100",
159150
"lacp_key": "auto",

src/sonic-yang-models/tests/yang_model_tests/tests_config/portchannel.json

-18
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"PORTCHANNEL_LIST": [
2222
{
2323
"admin_status": "up",
24-
"members": [
25-
"Ethernet0"
26-
],
2724
"min_links": "1",
2825
"mtu": "9100",
2926
"tpid": "0x8100",
@@ -55,9 +52,6 @@
5552
"PORTCHANNEL_LIST": [
5653
{
5754
"admin_status": "up",
58-
"members": [
59-
"Ethernet0"
60-
],
6155
"min_links": "1024",
6256
"mtu": "9100",
6357
"name": "PortChannel0001"
@@ -87,9 +81,6 @@
8781
"PORTCHANNEL_LIST": [
8882
{
8983
"admin_status": "up",
90-
"members": [
91-
"Ethernet0"
92-
],
9384
"min_links": "1025",
9485
"mtu": "9100",
9586
"name": "PortChannel0001"
@@ -303,9 +294,6 @@
303294
"PORTCHANNEL_LIST": [
304295
{
305296
"admin_status": "up",
306-
"members": [
307-
"Ethernet0"
308-
],
309297
"min_links": "1",
310298
"mtu": "9100",
311299
"name": "PortChannel0001"
@@ -350,9 +338,6 @@
350338
"PORTCHANNEL_LIST": [
351339
{
352340
"admin_status": "up",
353-
"members": [
354-
"Ethernet0"
355-
],
356341
"min_links": "1",
357342
"mtu": "9100",
358343
"name": "PortChannel0001"
@@ -396,9 +381,6 @@
396381
"PORTCHANNEL_LIST": [
397382
{
398383
"admin_status": "up",
399-
"members": [
400-
"Ethernet0"
401-
],
402384
"min_links": "1",
403385
"mtu": "9100",
404386
"name": "PortChannel0001"

src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan_sub_interface.json

-12
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@
196196
"PORTCHANNEL_LIST": [
197197
{
198198
"admin_status": "up",
199-
"members": [
200-
"Ethernet0"
201-
],
202199
"min_links": "1",
203200
"mtu": "9100",
204201
"tpid": "0x8100",
@@ -246,9 +243,6 @@
246243
"PORTCHANNEL_LIST": [
247244
{
248245
"admin_status": "up",
249-
"members": [
250-
"Ethernet0"
251-
],
252246
"min_links": "1",
253247
"mtu": "9100",
254248
"tpid": "0x8100",
@@ -296,9 +290,6 @@
296290
"PORTCHANNEL_LIST": [
297291
{
298292
"admin_status": "up",
299-
"members": [
300-
"Ethernet0"
301-
],
302293
"min_links": "1",
303294
"mtu": "9100",
304295
"tpid": "0x8100",
@@ -346,9 +337,6 @@
346337
"PORTCHANNEL_LIST": [
347338
{
348339
"admin_status": "up",
349-
"members": [
350-
"Ethernet0"
351-
],
352340
"min_links": "1",
353341
"mtu": "9100",
354342
"tpid": "0x8100",

src/sonic-yang-models/yang-models/sonic-portchannel.yang

-17
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,6 @@ module sonic-portchannel {
5858
}
5959
}
6060

61-
leaf-list members {
62-
/* leaf-list members are unique by default */
63-
type union {
64-
type leafref {
65-
path /port:sonic-port/port:PORT/port:PORT_LIST/port:name;
66-
}
67-
type string {
68-
pattern "";
69-
}
70-
}
71-
/* Today in SONiC, we do not delete the list once
72-
* created, instead we set to empty list. Due to that
73-
* below default values are needed.
74-
*/
75-
default "";
76-
}
77-
7861
leaf min_links {
7962
type uint16 {
8063
range 1..1024;

0 commit comments

Comments
 (0)