Skip to content

Commit d423841

Browse files
rodnymolinalguohan
authored andcommitted
[sonic-cfggen]: Sorting the information generated by sonic-cfggen for all j2 templates. (sonic-net#1616)
With this patch all the content of the files generated by "sonic-cfggen -d -t" instructions will now be sorted, which is very useful for operational and troubleshooting purposes. See below a few examples of this behavior. Also, a few sonic-cfggen UT's have been modified to accomodate the new sorted configurations. admin@lnos-x1-a-asw02:~$ sonic-cfggen -d -t /usr/share/sonic/templates/interfaces.j2 | more … auto lo iface lo inet loopback iface lo inet static address 10.10.1.2 netmask 255.255.255.255 auto eth0 iface eth0 inet dhcp allow-hotplug Ethernet112 iface Ethernet112 inet static mtu 9100 address 10.1.2.2 netmask 255.255.255.0 allow-hotplug Ethernet112 iface Ethernet112 inet6 static mtu 9100 address fc00:1:2::2 netmask 64 allow-hotplug Ethernet116 iface Ethernet116 inet static mtu 9100 address 10.2.2.2 netmask 255.255.255.0 allow-hotplug Ethernet116 iface Ethernet116 inet6 static mtu 9100 address fc00:2:2::2 netmask 64 allow-hotplug Ethernet120 iface Ethernet120 inet static mtu 9100 address 10.3.2.2 netmask 255.255.255.0 root@lnos-x1-a-csw01:/# sonic-cfggen -d -y /etc/sonic/deployment_id_asn_map.yml -t /usr/share/sonic/templates/bgpd.conf.j2 … router bgp 65100 … network 10.10.2.1/32 neighbor 10.0.0.1 remote-as 65200 neighbor 10.0.0.1 description ARISTA01T2 address-family ipv4 neighbor 10.0.0.1 activate maximum-paths 64 exit-address-family neighbor 10.0.0.11 remote-as 65200 neighbor 10.0.0.11 description ARISTA06T2 address-family ipv4 neighbor 10.0.0.11 activate maximum-paths 64 exit-address-family neighbor 10.0.0.13 remote-as 65200 neighbor 10.0.0.13 description ARISTA07T2 address-family ipv4 neighbor 10.0.0.13 activate maximum-paths 64 exit-address-family neighbor 10.0.0.15 remote-as 65200 neighbor 10.0.0.15 description ARISTA08T2 address-family ipv4 neighbor 10.0.0.15 activate maximum-paths 64 exit-address-family root@lnos-x1-a-asw02:/# sonic-cfggen -d -t /usr/share/sonic/templates/lldpd.conf.j2 … configure ports Ethernet4 lldp portidsubtype local Eth2/1 description ixia-card2-port8:Eth1/2/8 configure ports Ethernet112 lldp portidsubtype local Eth29/1 description lnos-x1-a-csw01:Eth29/1 configure ports Ethernet116 lldp portidsubtype local Eth30/1 description lnos-x1-a-csw02:Eth30/1 configure ports Ethernet120 lldp portidsubtype local Eth31/1 description lnos-x1-a-csw03:Eth31/1 configure ports Ethernet124 lldp portidsubtype local Eth32/1 description lnos-x1-a-csw04:Eth32/1 root@lnos-x1-a-asw02:/# sonic-cfggen -d -t /usr/share/sonic/templates/ports.json.j2 | more [ { "PORT_TABLE:Ethernet0": { "speed": "10000", "description": "" }, "OP": "SET" }, { "PORT_TABLE:Ethernet1": { "speed": "10000", "description": "" }, "OP": "SET" }, { "PORT_TABLE:Ethernet2": { "speed": "10000", "description": "" }, "OP": "SET" }, ]
1 parent 5ebefeb commit d423841

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

src/sonic-config-engine/sonic-cfggen

+8-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def deep_update(dst, src):
128128
dst[key] = value
129129
return dst
130130

131+
def sort_data(data):
132+
for table in data:
133+
if type(data[table]) is dict:
134+
data[table] = OrderedDict(natsorted(data[table].items()))
135+
return data
136+
131137

132138
def main():
133139
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
@@ -210,8 +216,8 @@ def main():
210216
for attr in ['ip', 'network', 'prefixlen', 'netmask']:
211217
env.filters[attr] = partial(prefix_attr, attr)
212218
template = env.get_template(template_file)
213-
print template.render(data)
214-
219+
print template.render(sort_data(data))
220+
215221
if args.var != None:
216222
template = jinja2.Template('{{' + args.var + '}}')
217223
print template.render(data)

src/sonic-config-engine/tests/sample_output/docker-dhcp-relay.supervisord.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ stderr_logfile=syslog
2323
programs=isc-dhcp-relay-Vlan1000
2424

2525
[program:isc-dhcp-relay-Vlan1000]
26-
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -i Vlan1000 -i PortChannel02 -i PortChannel03 -i PortChannel04 -i PortChannel01 192.0.0.1 192.0.0.2
26+
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -i Vlan1000 -i PortChannel01 -i PortChannel02 -i PortChannel03 -i PortChannel04 192.0.0.1 192.0.0.2
2727
priority=3
2828
autostart=false
2929
autorestart=false
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
configure ports eth0 lldp portidsubtype local eth0
2-
configure ports Ethernet116 lldp portidsubtype local fortyGigE0/116 description ARISTA02T1:Ethernet1/1
3-
configure ports Ethernet124 lldp portidsubtype local fortyGigE0/124 description ARISTA04T1:Ethernet1/1
42
configure ports Ethernet112 lldp portidsubtype local fortyGigE0/112 description ARISTA01T1:Ethernet1/1
3+
configure ports Ethernet116 lldp portidsubtype local fortyGigE0/116 description ARISTA02T1:Ethernet1/1
54
configure ports Ethernet120 lldp portidsubtype local fortyGigE0/120 description ARISTA03T1:Ethernet1/1
5+
configure ports Ethernet124 lldp portidsubtype local fortyGigE0/124 description ARISTA04T1:Ethernet1/1
66

src/sonic-config-engine/tests/sample_output/msn27.32ports.json

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
{
22
"CABLE_LENGTH": {
33
"AZURE": {
4-
"Ethernet8": "300m",
54
"Ethernet0": "300m",
65
"Ethernet4": "300m",
7-
"Ethernet108": "300m",
8-
"Ethernet100": "300m",
9-
"Ethernet104": "300m",
10-
"Ethernet68": "300m",
11-
"Ethernet96": "300m",
12-
"Ethernet124": "300m",
13-
"Ethernet92": "300m",
14-
"Ethernet120": "300m",
6+
"Ethernet8": "300m",
7+
"Ethernet12": "300m",
8+
"Ethernet16": "300m",
9+
"Ethernet20": "300m",
10+
"Ethernet24": "300m",
11+
"Ethernet28": "300m",
12+
"Ethernet32": "300m",
13+
"Ethernet36": "300m",
14+
"Ethernet40": "300m",
15+
"Ethernet44": "300m",
16+
"Ethernet48": "300m",
1517
"Ethernet52": "300m",
1618
"Ethernet56": "300m",
17-
"Ethernet76": "300m",
18-
"Ethernet72": "300m",
19+
"Ethernet60": "300m",
1920
"Ethernet64": "300m",
20-
"Ethernet32": "300m",
21-
"Ethernet16": "300m",
22-
"Ethernet36": "300m",
23-
"Ethernet12": "300m",
24-
"Ethernet88": "300m",
25-
"Ethernet116": "300m",
21+
"Ethernet68": "300m",
22+
"Ethernet72": "300m",
23+
"Ethernet76": "300m",
2624
"Ethernet80": "300m",
27-
"Ethernet112": "300m",
2825
"Ethernet84": "300m",
29-
"Ethernet48": "300m",
30-
"Ethernet44": "300m",
31-
"Ethernet40": "300m",
32-
"Ethernet28": "300m",
33-
"Ethernet60": "300m",
34-
"Ethernet20": "300m",
35-
"Ethernet24": "300m"
26+
"Ethernet88": "300m",
27+
"Ethernet92": "300m",
28+
"Ethernet96": "300m",
29+
"Ethernet100": "300m",
30+
"Ethernet104": "300m",
31+
"Ethernet108": "300m",
32+
"Ethernet112": "300m",
33+
"Ethernet116": "300m",
34+
"Ethernet120": "300m",
35+
"Ethernet124": "300m"
3636
}
3737
},
3838
"BUFFER_POOL": {
@@ -95,25 +95,25 @@
9595
}
9696
},
9797
"BUFFER_PORT_INGRESS_PROFILE_LIST": {
98-
"Ethernet8,Ethernet0,Ethernet4,Ethernet108,Ethernet100,Ethernet104,Ethernet68,Ethernet96,Ethernet124,Ethernet92,Ethernet120,Ethernet52,Ethernet56,Ethernet76,Ethernet72,Ethernet64,Ethernet32,Ethernet16,Ethernet36,Ethernet12,Ethernet88,Ethernet116,Ethernet80,Ethernet112,Ethernet84,Ethernet48,Ethernet44,Ethernet40,Ethernet28,Ethernet60,Ethernet20,Ethernet24": {
98+
"Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124": {
9999
"profile_list" : "[BUFFER_PROFILE|ingress_lossless_profile],[BUFFER_PROFILE|ingress_lossy_profile]"
100100
}
101101
},
102102
"BUFFER_PORT_EGRESS_PROFILE_LIST": {
103-
"Ethernet8,Ethernet0,Ethernet4,Ethernet108,Ethernet100,Ethernet104,Ethernet68,Ethernet96,Ethernet124,Ethernet92,Ethernet120,Ethernet52,Ethernet56,Ethernet76,Ethernet72,Ethernet64,Ethernet32,Ethernet16,Ethernet36,Ethernet12,Ethernet88,Ethernet116,Ethernet80,Ethernet112,Ethernet84,Ethernet48,Ethernet44,Ethernet40,Ethernet28,Ethernet60,Ethernet20,Ethernet24": {
103+
"Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124": {
104104
"profile_list" : "[BUFFER_PROFILE|egress_lossless_profile],[BUFFER_PROFILE|egress_lossy_profile]"
105105
}
106106
},
107107
"BUFFER_PG": {
108-
"Ethernet8,Ethernet0,Ethernet4,Ethernet108,Ethernet100,Ethernet104,Ethernet68,Ethernet96,Ethernet124,Ethernet92,Ethernet120,Ethernet52,Ethernet56,Ethernet76,Ethernet72,Ethernet64,Ethernet32,Ethernet16,Ethernet36,Ethernet12,Ethernet88,Ethernet116,Ethernet80,Ethernet112,Ethernet84,Ethernet48,Ethernet44,Ethernet40,Ethernet28,Ethernet60,Ethernet20,Ethernet24|0-1": {
108+
"Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|0-1": {
109109
"profile" : "[BUFFER_PROFILE|pg_lossy_profile]"
110110
}
111111
},
112112
"BUFFER_QUEUE": {
113-
"Ethernet8,Ethernet0,Ethernet4,Ethernet108,Ethernet100,Ethernet104,Ethernet68,Ethernet96,Ethernet124,Ethernet92,Ethernet120,Ethernet52,Ethernet56,Ethernet76,Ethernet72,Ethernet64,Ethernet32,Ethernet16,Ethernet36,Ethernet12,Ethernet88,Ethernet116,Ethernet80,Ethernet112,Ethernet84,Ethernet48,Ethernet44,Ethernet40,Ethernet28,Ethernet60,Ethernet20,Ethernet24|3-4": {
113+
"Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|3-4": {
114114
"profile" : "[BUFFER_PROFILE|q_lossless_profile]"
115115
},
116-
"Ethernet8,Ethernet0,Ethernet4,Ethernet108,Ethernet100,Ethernet104,Ethernet68,Ethernet96,Ethernet124,Ethernet92,Ethernet120,Ethernet52,Ethernet56,Ethernet76,Ethernet72,Ethernet64,Ethernet32,Ethernet16,Ethernet36,Ethernet12,Ethernet88,Ethernet116,Ethernet80,Ethernet112,Ethernet84,Ethernet48,Ethernet44,Ethernet40,Ethernet28,Ethernet60,Ethernet20,Ethernet24|0-1": {
116+
"Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|0-1": {
117117
"profile" : "[BUFFER_PROFILE|q_lossy_profile]"
118118
}
119119
}

src/sonic-config-engine/tests/sample_output/ports.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
[
2-
{
3-
"PORT_TABLE:Ethernet8": {
4-
"speed": "1000",
5-
"description": "Interface description"
6-
},
7-
"OP": "SET"
8-
},
92
{
103
"PORT_TABLE:Ethernet0": {
114
"speed": "10000",
@@ -20,6 +13,13 @@
2013
},
2114
"OP": "SET"
2215
},
16+
{
17+
"PORT_TABLE:Ethernet8": {
18+
"speed": "1000",
19+
"description": "Interface description"
20+
},
21+
"OP": "SET"
22+
},
2323
{
2424
"PORT_TABLE:Ethernet12": {
2525
"speed": "100000",

src/sonic-config-engine/tests/sample_output/wait_for_intf.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ function wait_until_iface_ready
3232

3333
# Wait for all interfaces to come up and have IPv4 addresses assigned
3434
wait_until_iface_ready Vlan1000
35-
wait_until_iface_ready PortChannel04
35+
wait_until_iface_ready PortChannel01
36+
wait_until_iface_ready PortChannel01
37+
wait_until_iface_ready PortChannel02
3638
wait_until_iface_ready PortChannel02
3739
wait_until_iface_ready PortChannel03
3840
wait_until_iface_ready PortChannel03
39-
wait_until_iface_ready PortChannel01
40-
wait_until_iface_ready PortChannel02
4141
wait_until_iface_ready PortChannel04
42-
wait_until_iface_ready PortChannel01
42+
wait_until_iface_ready PortChannel04
4343

0 commit comments

Comments
 (0)