Skip to content

Commit f729fca

Browse files
arlakshmmssonicbld
authored andcommitted
[chassis] add condition is yang model to make lanes not mandatory for chassis (#19968)
### Why I did it In the sonic chassis the port table on the host does not lanes. Add conditions in the lab chassis to make lanes not mandatory for chassis devices ### How I did it Add the check in `sonic-port.yang` to make lanes are mandatory in the host config_db only for non-chassis devices. #### How to verify it UT.
1 parent c785950 commit f729fca

File tree

5 files changed

+150
-45
lines changed

5 files changed

+150
-45
lines changed

src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml

-31
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@
146146
</SubInterface>
147147
</SubInterfaces>
148148
<IPInterfaces>
149-
<IPInterface>
150-
<Name i:nil="true"/>
151-
<AttachTo>Eth1/1/47</AttachTo>
152-
<Prefix>27.1.1.1/24</Prefix>
153-
</IPInterface>
154149
</IPInterfaces>
155150
<DownstreamSummaries/>
156151
<DownstreamSummarySet xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
@@ -206,11 +201,6 @@
206201
<PortChannelInterfaces>
207202
</PortChannelInterfaces>
208203
<IPInterfaces>
209-
<IPInterface>
210-
<Name i:nil="true"/>
211-
<AttachTo>Eth1/1/47</AttachTo>
212-
<Prefix>27.1.1.1/24</Prefix>
213-
</IPInterface>
214204
</IPInterfaces>
215205
<VlanInterfaces>
216206
</VlanInterfaces>
@@ -261,13 +251,6 @@
261251
</LinkMetadataDeclaration>
262252
<PngDec>
263253
<DeviceInterfaceLinks>
264-
<DeviceLinkBase>
265-
<ElementType>DeviceInterfaceLink</ElementType>
266-
<EndDevice>IXIA-EBGP</EndDevice>
267-
<EndPort>Ethernet1</EndPort>
268-
<StartDevice>str2-8808-lc2-1</StartDevice>
269-
<StartPort>Eth1/1/47</StartPort>
270-
</DeviceLinkBase>
271254
<DeviceLinkBase i:type="DeviceInterfaceLink">
272255
<ElementType>DeviceInterfaceLink</ElementType>
273256
<Bandwidth>100000</Bandwidth>
@@ -402,20 +385,6 @@
402385
<DeviceInfo>
403386
<AutoNegotiation>true</AutoNegotiation>
404387
<EthernetInterfaces xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
405-
<a:EthernetInterface>
406-
<ElementType>DeviceInterface</ElementType>
407-
<AlternateSpeeds i:nil="true"/>
408-
<EnableAutoNegotiation>true</EnableAutoNegotiation>
409-
<EnableFlowControl>true</EnableFlowControl>
410-
<Index>1</Index>
411-
<InterfaceName>Ethernet1/1/47</InterfaceName>
412-
<InterfaceType i:nil="true"/>
413-
<MultiPortsInterface>false</MultiPortsInterface>
414-
<PortName>47</PortName>
415-
<Priority>0</Priority>
416-
<Speed>100000</Speed>
417-
<SonicName>Ethernet47</SonicName>
418-
</a:EthernetInterface>
419388
</EthernetInterfaces>
420389
<FlowControl>true</FlowControl>
421390
<Height>0</Height>

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

+15-11
Original file line numberDiff line numberDiff line change
@@ -1020,15 +1020,26 @@ def test_minigraph_dhcp(self):
10201020
"'Vlan2000': {'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4']}}"
10211021
)
10221022
)
1023-
1024-
def test_minigraph_packet_chassis_acl(self):
1025-
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-v', "ACL_TABLE"]
1023+
1024+
def test_minigraph_packet_chassis_acl_local_host(self):
1025+
# CFGGEN_UNIT_TESTING is set to '2' in the set_up function
1026+
# this causes the port_table to have ports from the previous test
1027+
# causing yang validation to fail
1028+
1029+
os.environ["CFGGEN_UNIT_TESTING"] = ""
1030+
argument = ['-m', self.packet_chassis_graph, '-v', "ACL_TABLE"]
10261031
output = self.run_script(argument)
1032+
print(output)
10271033
self.assertEqual(
10281034
utils.to_dict(output.strip()),
10291035
utils.to_dict("{'SNMP_ACL': {'policy_desc': 'SNMP_ACL', 'type': 'CTRLPLANE', 'stage': 'ingress', 'services': ['SNMP']}, 'SSH_ONLY': {'policy_desc': 'SSH_ONLY', 'type': 'CTRLPLANE', 'stage': 'ingress', 'services': ['SSH']}}")
10301036
)
10311037

1038+
# set it back to the original value
1039+
os.environ["CFGGEN_UNIT_TESTING"] = "2"
1040+
1041+
def test_minigraph_packet_chassis_acl_namespace(self):
1042+
10321043
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-n', "asic1", '-v', "ACL_TABLE"]
10331044
output = self.run_script(argument)
10341045
self.assertEqual(
@@ -1045,20 +1056,13 @@ def test_minigraph_bgp_packet_chassis_peer(self):
10451056
)
10461057

10471058
def test_minigraph_bgp_packet_chassis_static_route(self):
1048-
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-v', "STATIC_ROUTE"]
1049-
output = self.run_script(argument)
1050-
self.assertEqual(
1051-
utils.to_dict(output.strip()),
1052-
utils.to_dict("{'8.0.0.1/32': {'nexthop': '192.168.1.2,192.168.2.2', 'ifname': 'PortChannel40,PortChannel50', 'advertise':'false', 'bfd':'true'}}")
1053-
)
1054-
10551059
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-n', "asic1", '-v', "STATIC_ROUTE"]
10561060
output = self.run_script(argument)
10571061
self.assertEqual(
10581062
utils.to_dict(output.strip()),
10591063
utils.to_dict("{'8.0.0.1/32': {'nexthop': '192.168.1.2,192.168.2.2', 'ifname': 'PortChannel40,PortChannel50', 'advertise':'false', 'bfd':'true'}}")
10601064
)
1061-
1065+
os.environ["CFGGEN_UNIT_TESTING_TOPOLOGY"] = ""
10621066
def test_minigraph_bgp_packet_chassis_vlan_subintf(self):
10631067
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-n', "asic1", '-v', "VLAN_SUB_INTERFACE"]
10641068
output = self.run_script(argument)

src/sonic-yang-models/tests/yang_model_tests/tests/port.json

+23-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,27 @@
151151
"eStrKey" : "InvalidValue",
152152
"eStr": ["dom_polling"]
153153
},
154-
"PORT_AUTO_FEC_TEST": {
155-
"desc": "PORT_AUTO_FEC_TEST validate auto mode in fec."
156-
}
154+
"PORT_AUTO_FEC_TEST": {
155+
"desc": "PORT_AUTO_FEC_TEST validate auto mode in fec."
156+
},
157+
"PORT_NO_LANES_NEGATIVE_TEST": {
158+
"desc": "PORT_NO_LANES_NEGATIVE_TEST no lanes.",
159+
"eStrKey": "Mandatory",
160+
"eStr": ["Missing"]
161+
},
162+
"PORT_VOQ_CHASSIS_WITH_NO_LANES": {
163+
"desc": "PORT_VOQ_CHASSIS_WITH_NO_LANES no failure."
164+
},
165+
"PORT_PACKET_CHASSIS_WITH_NO_LANES": {
166+
"desc": "PORT_PACKET_CHASSIS_WITH_NO_LANES no failure."
167+
},
168+
"PORT_FABRIC_WITH_NO_LANES": {
169+
"desc": "PORT_FABRIC_WITH_NO_LANES no failure."
170+
},
171+
"PORT_VOQ_CHASSIS_WITH_LANES": {
172+
"desc": "PORT_VOQ_CHASSIS_WITH_LANES no failure."
173+
}
174+
175+
176+
157177
}

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

+102
Original file line numberDiff line numberDiff line change
@@ -804,5 +804,107 @@
804804
]
805805
}
806806
}
807+
},
808+
"PORT_NO_LANES_NEGATIVE_TEST": {
809+
"sonic-port:sonic-port": {
810+
"sonic-port:PORT": {
811+
"PORT_LIST": [
812+
{
813+
"name": "Ethernet0",
814+
"alias": "etp1a",
815+
"speed": 100000,
816+
"role": "Ext"
817+
}
818+
]
819+
}
820+
}
821+
},
822+
"PORT_VOQ_CHASSIS_WITH_NO_LANES": {
823+
"sonic-device_metadata:sonic-device_metadata": {
824+
"sonic-device_metadata:DEVICE_METADATA": {
825+
"sonic-device_metadata:localhost": {
826+
"switch_type": "voq"
827+
}
828+
}
829+
},
830+
"sonic-port:sonic-port": {
831+
"sonic-port:PORT": {
832+
"PORT_LIST": [
833+
{
834+
"name": "Ethernet0",
835+
"alias": "etp1a",
836+
"speed": 100000,
837+
"role": "Ext"
838+
}
839+
]
840+
}
841+
}
842+
},
843+
"PORT_VOQ_CHASSIS_WITH_LANES": {
844+
"sonic-device_metadata:sonic-device_metadata": {
845+
"sonic-device_metadata:DEVICE_METADATA": {
846+
"sonic-device_metadata:localhost": {
847+
"switch_type": "voq",
848+
"asic_name": "asic0"
849+
}
850+
}
851+
},
852+
"sonic-port:sonic-port": {
853+
"sonic-port:PORT": {
854+
"PORT_LIST": [
855+
{
856+
"name": "Ethernet0",
857+
"alias": "etp1a",
858+
"speed": 100000,
859+
"role": "Ext",
860+
"lanes": "60, 61"
861+
}
862+
]
863+
}
864+
}
865+
},
866+
"PORT_PACKET_CHASSIS_WITH_NO_LANES": {
867+
"sonic-device_metadata:sonic-device_metadata": {
868+
"sonic-device_metadata:DEVICE_METADATA": {
869+
"sonic-device_metadata:localhost": {
870+
"switch_type": "chassis-packet"
871+
}
872+
}
873+
},
874+
"sonic-port:sonic-port": {
875+
"sonic-port:PORT": {
876+
"PORT_LIST": [
877+
{
878+
"name": "Ethernet0",
879+
"alias": "etp1a",
880+
"speed": 100000,
881+
"role": "Ext"
882+
883+
}
884+
]
885+
}
886+
}
887+
},
888+
"PORT_FABRIC_WITH_NO_LANES": {
889+
"sonic-device_metadata:sonic-device_metadata": {
890+
"sonic-device_metadata:DEVICE_METADATA": {
891+
"sonic-device_metadata:localhost": {
892+
"switch_type": "fabric"
893+
}
894+
}
895+
},
896+
"sonic-port:sonic-port": {
897+
"sonic-port:PORT": {
898+
"PORT_LIST": [
899+
{
900+
"name": "Ethernet0",
901+
"alias": "etp1a",
902+
"speed": 100000,
903+
"role": "Int"
904+
905+
}
906+
]
907+
}
908+
}
807909
}
808910
}

src/sonic-yang-models/yang-models/sonic-port.yang

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module sonic-port{
1313
prefix ext;
1414
}
1515

16+
import sonic-device_metadata {
17+
prefix sdm;
18+
}
19+
1620
import sonic-macsec {
1721
prefix macsec;
1822
}
@@ -67,6 +71,12 @@ module sonic-port{
6771
}
6872

6973
leaf lanes {
74+
when "not(not(/sdm:sonic-device_metadata/sdm:DEVICE_METADATA/sdm:localhost/sdm:asic_name) and
75+
((/sdm:sonic-device_metadata/sdm:DEVICE_METADATA/sdm:localhost/sdm:switch_type='voq') or
76+
(/sdm:sonic-device_metadata/sdm:DEVICE_METADATA/sdm:localhost/sdm:switch_type='chassis-packet') or
77+
(/sdm:sonic-device_metadata/sdm:DEVICE_METADATA/sdm:localhost/sdm:switch_type='fabric')))";
78+
79+
description "Number of hardware lanes for the port. This is mandatory for all devices except for chassis devices";
7080
mandatory true;
7181
type string {
7282
length 1..128;

0 commit comments

Comments
 (0)