From b5b5883c27df1bbe5bfa3e941a46c3e55a406b69 Mon Sep 17 00:00:00 2001
From: abdosi <58047199+abdosi@users.noreply.github.com>
Date: Fri, 19 May 2023 11:49:10 -0700
Subject: [PATCH] [minigraph.py]: Updated Static Route Minigraph Attribute
property (#14951)
What I did:
Updated Static Route Attribute in Minigraph. NGS Minigraph has define semantics of static route differently.
See below for differences:-
Microsoft ADO: 17956325
Before
8.0.0.1/32
192.168.1.2,192.168.2.2
PortChannel40,PortChannel50
Now:
8.0.0.1
PortChannel40,192.168.1.2;PortChannel50,192.168.2.2
Signed-off-by: Abhishek Dosi
---
src/sonic-config-engine/minigraph.py | 22 ++++++++++++++-----
.../tests/sample-chassis-packet-lc-graph.xml | 12 ++++------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py
index dd02a501b8..11ddf165cd 100644
--- a/src/sonic-config-engine/minigraph.py
+++ b/src/sonic-config-engine/minigraph.py
@@ -585,11 +585,23 @@ def parse_dpg(dpg, hname):
elif ":" in ipnhaddr:
port_nhipv6_map[ipnhfmbr] = ipnhaddr
elif ipnh.find(str(QName(ns, "Type"))).text == 'StaticRoute':
- prefix = ipnh.find(str(QName(ns, "AssociatedTo"))).text
- ifname = ipnh.find(str(QName(ns, "AttachTo"))).text
- nexthop = ipnh.find(str(QName(ns, "Address"))).text
- advertise = ipnh.find(str(QName(ns, "Advertise"))).text
- static_routes[prefix] = {'nexthop': nexthop, 'ifname': ifname, 'advertise': advertise}
+ prefix = ipnh.find(str(QName(ns, "Address"))).text
+ ifname = []
+ nexthop = []
+ for nexthop_tuple in ipnh.find(str(QName(ns, "AttachTo"))).text.split(";"):
+ ifname.append(nexthop_tuple.split(",")[0])
+ nexthop.append(nexthop_tuple.split(",")[1])
+ if ipnh.find(str(QName(ns, "Advertise"))):
+ advertise = ipnh.find(str(QName(ns, "Advertise"))).text
+ else:
+ advertise = "false"
+ if '/' not in prefix:
+ if ":" in prefix:
+ prefix = prefix + "/128"
+ else:
+ prefix = prefix + "/32"
+ static_routes[prefix] = {'nexthop': ",".join(nexthop), 'ifname': ",".join(ifname), 'advertise': advertise}
+
if port_nhipv4_map and port_nhipv6_map:
subnet_check_ip = list(port_nhipv4_map.values())[0]
for subnet_range in ip_intfs_map:
diff --git a/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml b/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml
index 6b22d30336..debefcc15d 100644
--- a/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml
+++ b/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml
@@ -121,11 +121,9 @@
IPNextHop
- 8.0.0.1/32
- 192.168.1.2,192.168.2.2
- PortChannel40,PortChannel50
+ 8.0.0.1
+ PortChannel40,192.168.1.2;PortChannel50,192.168.2.2
StaticRoute
- false
@@ -213,11 +211,9 @@
IPNextHop
- 8.0.0.1/32
- 192.168.1.2,192.168.2.2
- PortChannel40,PortChannel50
+ 8.0.0.1
+ PortChannel40,192.168.1.2;PortChannel50,192.168.2.2
StaticRoute
- false