Skip to content

Commit d81d665

Browse files
committed
[cfggen]: ignore acl when its type is not defined (#1568)
Signed-off-by: Guohan Lu <[email protected]>
1 parent 765bf0a commit d81d665

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/sonic-config-engine/minigraph.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,15 @@ def parse_dpg(dpg, hname):
207207
'type': 'MIRROR' if is_mirror else 'L3'}
208208
else:
209209
# This ACL has no interfaces to attach to -- consider this a control plane ACL
210-
aclservice = aclintf.find(str(QName(ns, "Type"))).text
211-
acls[aclname] = {'policy_desc': aclname,
212-
'ports': acl_intfs,
213-
'type': 'CTRLPLANE',
214-
'service': aclservice if aclservice is not None else 'UNKNOWN'}
210+
try:
211+
aclservice = aclintf.find(str(QName(ns, "Type"))).text
212+
acls[aclname] = {'policy_desc': aclname,
213+
'ports': acl_intfs,
214+
'type': 'CTRLPLANE',
215+
'service': aclservice if aclservice is not None else 'UNKNOWN'}
216+
except:
217+
print >> sys.stderr, "Warning: Ingore Control Plane ACL %s without type" % aclname
218+
215219
return intfs, lo_intfs, mgmt_intf, vlans, vlan_members, pcs, acls
216220
return None, None, None, None, None, None, None
217221

src/sonic-config-engine/tests/t0-sample-graph.xml

+14
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@
271271
<InAcl>SNMP_ACL</InAcl>
272272
<Type>SNMP</Type>
273273
</AclInterface>
274+
<AclInterface>
275+
<AttachTo>NTP</AttachTo>
276+
<InAcl>NTP_ACL</InAcl>
277+
<Type>NTP</Type>
278+
</AclInterface>
279+
<AclInterface>
280+
<AttachTo>SSH</AttachTo>
281+
<InAcl>SSH_ACL</InAcl>
282+
<Type>SSH</Type>
283+
</AclInterface>
284+
<AclInterface>
285+
<AttachTo>NTP</AttachTo>
286+
<InAcl>NTP_ACL</InAcl>
287+
</AclInterface>
274288
</AclInterfaces>
275289
<DownstreamSummaries/>
276290
<DownstreamSummarySet xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ def setUp(self):
1616
self.sample_device_desc = os.path.join(self.test_dir, 'device.xml')
1717
self.port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini')
1818

19-
def run_script(self, argument):
19+
def run_script(self, argument, check_stderr=False):
2020
print '\n Running sonic-cfggen ' + argument
21-
output = subprocess.check_output(self.script_file + ' ' + argument, shell=True)
21+
if check_stderr:
22+
output = subprocess.check_output(self.script_file + ' ' + argument, stderr=subprocess.STDOUT, shell=True)
23+
else:
24+
output = subprocess.check_output(self.script_file + ' ' + argument, shell=True)
25+
2226
linecount = output.strip().count('\n')
2327
if linecount <= 0:
2428
print ' Output: ' + output.strip()
@@ -73,10 +77,12 @@ def test_render_template(self):
7377

7478
def test_minigraph_acl(self):
7579
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
76-
output = self.run_script(argument)
77-
self.assertEqual(output.strip(), "{'SNMP_ACL': {'type': 'CTRLPLANE', 'policy_desc': 'SNMP_ACL', 'service': 'SNMP', 'ports': []},"
78-
" 'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
79-
80+
output = self.run_script(argument, True)
81+
self.assertEqual(output.strip(), "Warning: Ingore Control Plane ACL NTP_ACL without type\n"
82+
"{'SSH_ACL': {'type': 'CTRLPLANE', 'policy_desc': 'SSH_ACL', 'service': 'SSH', 'ports': []},"
83+
" 'SNMP_ACL': {'type': 'CTRLPLANE', 'policy_desc': 'SNMP_ACL', 'service': 'SNMP', 'ports': []},"
84+
" 'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']},"
85+
" 'NTP_ACL': {'type': 'CTRLPLANE', 'policy_desc': 'NTP_ACL', 'service': 'NTP', 'ports': []}}")
8086
def test_minigraph_everflow(self):
8187
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v MIRROR_SESSION'
8288
output = self.run_script(argument)

0 commit comments

Comments
 (0)