Skip to content

Commit 6a48ea6

Browse files
authored
Revert "Revert "Run yang validation in unit test (#3025)" (#3055)"
This reverts commit 17e77fe.
1 parent 19ea849 commit 6a48ea6

11 files changed

+96
-20
lines changed

scripts/db_migrator.py

+28
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import sys
77
import traceback
88
import re
9+
import sonic_yang
10+
import syslog
911

1012
from sonic_py_common import device_info, logger
1113
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
1214
from minigraph import parse_xml
1315

1416
INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
1517
MINIGRAPH_FILE = '/etc/sonic/minigraph.xml'
18+
YANG_MODELS_DIR = "/usr/local/yang-models"
1619

1720
# mock the redis for unit test purposes #
1821
try:
@@ -1137,6 +1140,31 @@ def migrate(self):
11371140
version = next_version
11381141
# Perform common migration ops
11391142
self.common_migration_ops()
1143+
config = self.configDB.get_config()
1144+
# Fix table key in tuple
1145+
for table_name, table in config.items():
1146+
new_table = {}
1147+
hit = False
1148+
for table_key, table_val in table.items():
1149+
if isinstance(table_key, tuple):
1150+
new_key = "|".join(table_key)
1151+
new_table[new_key] = table_val
1152+
hit = True
1153+
else:
1154+
new_table[table_key] = table_val
1155+
if hit:
1156+
config[table_name] = new_table
1157+
# Run yang validation
1158+
yang_parser = sonic_yang.SonicYang(YANG_MODELS_DIR)
1159+
yang_parser.loadYangModel()
1160+
try:
1161+
yang_parser.loadData(configdbJson=config)
1162+
yang_parser.validate_data_tree()
1163+
except sonic_yang.SonicYangException as e:
1164+
syslog.syslog(syslog.LOG_CRIT, "Yang validation failed: " + str(e))
1165+
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
1166+
raise
1167+
11401168

11411169
def main():
11421170
try:

tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_3_expected.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"VERSION": "version_4_0_3"
44
},
55
"FLEX_COUNTER_TABLE|ACL": {
6-
"FLEX_COUNTER_STATUS": "true",
6+
"FLEX_COUNTER_STATUS": "enable",
77
"FLEX_COUNTER_DELAY_STATUS": "true",
88
"POLL_INTERVAL": "10000"
99
},
1010
"FLEX_COUNTER_TABLE|QUEUE": {
11-
"FLEX_COUNTER_STATUS": "true",
11+
"FLEX_COUNTER_STATUS": "enable",
1212
"FLEX_COUNTER_DELAY_STATUS": "true",
1313
"POLL_INTERVAL": "10000"
1414
},
1515
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
16-
"FLEX_COUNTER_STATUS": "false",
16+
"FLEX_COUNTER_STATUS": "disable",
1717
"FLEX_COUNTER_DELAY_STATUS": "true"
1818
}
1919
}

tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_3_input.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"VERSION": "version_1_0_1"
44
},
55
"FLEX_COUNTER_TABLE|ACL": {
6-
"FLEX_COUNTER_STATUS": "true",
6+
"FLEX_COUNTER_STATUS": "enable",
77
"FLEX_COUNTER_DELAY_STATUS": "true",
88
"POLL_INTERVAL": "10000"
99
},
1010
"FLEX_COUNTER_TABLE|QUEUE": {
11-
"FLEX_COUNTER_STATUS": "true",
11+
"FLEX_COUNTER_STATUS": "enable",
1212
"FLEX_COUNTER_DELAY_STATUS": "false",
1313
"POLL_INTERVAL": "10000"
1414
},
1515
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
16-
"FLEX_COUNTER_STATUS": "false"
16+
"FLEX_COUNTER_STATUS": "disable"
1717
}
1818
}

tests/db_migrator_input/config_db/portchannel-expected.json

-4
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
{
22
"PORTCHANNEL|PortChannel0": {
33
"admin_status": "up",
4-
"members@": "Ethernet0,Ethernet4",
54
"min_links": "2",
65
"mtu": "9100",
76
"lacp_key": "auto"
87
},
98
"PORTCHANNEL|PortChannel1": {
109
"admin_status": "up",
11-
"members@": "Ethernet8,Ethernet12",
1210
"min_links": "2",
1311
"mtu": "9100",
1412
"lacp_key": "auto"
1513
},
1614
"PORTCHANNEL|PortChannel0123": {
1715
"admin_status": "up",
18-
"members@": "Ethernet16",
1916
"min_links": "1",
2017
"mtu": "9100",
2118
"lacp_key": "auto"
2219
},
2320
"PORTCHANNEL|PortChannel0011": {
2421
"admin_status": "up",
25-
"members@": "Ethernet20,Ethernet24",
2622
"min_links": "2",
2723
"mtu": "9100",
2824
"lacp_key": "auto"

tests/db_migrator_input/config_db/portchannel-input.json

-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
{
22
"PORTCHANNEL|PortChannel0": {
33
"admin_status": "up",
4-
"members@": "Ethernet0,Ethernet4",
54
"min_links": "2",
65
"mtu": "9100"
76
},
87
"PORTCHANNEL|PortChannel1": {
98
"admin_status": "up",
10-
"members@": "Ethernet8,Ethernet12",
119
"min_links": "2",
1210
"mtu": "9100"
1311
},
1412
"PORTCHANNEL|PortChannel0123": {
1513
"admin_status": "up",
16-
"members@": "Ethernet16",
1714
"min_links": "1",
1815
"mtu": "9100"
1916
},
2017
"PORTCHANNEL|PortChannel0011": {
2118
"admin_status": "up",
22-
"members@": "Ethernet20,Ethernet24",
2319
"min_links": "2",
2420
"mtu": "9100"
2521
},

tests/db_migrator_input/config_db/qos_map_table_expected.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
"pfc_to_queue_map": "AZURE",
3030
"tc_to_pg_map": "AZURE",
3131
"tc_to_queue_map": "AZURE"
32-
}
32+
},
33+
"TC_TO_QUEUE_MAP|AZURE": {"0": "0"},
34+
"TC_TO_PRIORITY_GROUP_MAP|AZURE": {"0": "0"},
35+
"MAP_PFC_PRIORITY_TO_QUEUE|AZURE": {"0": "0"},
36+
"DSCP_TO_TC_MAP|AZURE": {"0": "0"},
37+
"PORT|Ethernet0": {"lanes": "0", "speed": "1000"},
38+
"PORT|Ethernet92": {"lanes": "92", "speed": "1000"},
39+
"PORT|Ethernet96": {"lanes": "96", "speed": "1000"},
40+
"PORT|Ethernet100": {"lanes": "100", "speed": "1000"}
3341
}
3442

tests/db_migrator_input/config_db/qos_map_table_input.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@
2727
"pfc_to_queue_map": "AZURE",
2828
"tc_to_pg_map": "AZURE",
2929
"tc_to_queue_map": "AZURE"
30-
}
30+
},
31+
"TC_TO_QUEUE_MAP|AZURE": {"0": "0"},
32+
"TC_TO_PRIORITY_GROUP_MAP|AZURE": {"0": "0"},
33+
"MAP_PFC_PRIORITY_TO_QUEUE|AZURE": {"0": "0"},
34+
"DSCP_TO_TC_MAP|AZURE": {"0": "0"},
35+
"PORT|Ethernet0": {"lanes": "0", "speed": "1000"},
36+
"PORT|Ethernet92": {"lanes": "92", "speed": "1000"},
37+
"PORT|Ethernet96": {"lanes": "96", "speed": "1000"},
38+
"PORT|Ethernet100": {"lanes": "100", "speed": "1000"}
3139
}

tests/db_migrator_input/config_db/reclaiming-buffer-dynamic-double-pools-expected.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"profile": "NULL"
1313
},
1414
"BUFFER_PG|Ethernet8|3-4": {
15-
"profile": "customized_lossless_profile"
15+
"profile": "customized_ingress_lossless_profile"
1616
},
1717
"BUFFER_PG|Ethernet12|0": {
1818
"profile": "ingress_lossy_profile"
@@ -103,6 +103,11 @@
103103
"BUFFER_PORT_INGRESS_PROFILE_LIST|Ethernet24": {
104104
"profile_list": "ingress_lossless_profile,ingress_lossy_profile"
105105
},
106+
"BUFFER_PROFILE|customized_egress_lossless_profile": {
107+
"dynamic_th": "7",
108+
"pool": "egress_lossless_pool",
109+
"size": "0"
110+
},
106111
"BUFFER_PROFILE|egress_lossless_profile": {
107112
"dynamic_th": "7",
108113
"pool": "egress_lossless_pool",
@@ -113,6 +118,11 @@
113118
"pool": "egress_lossy_pool",
114119
"size": "9216"
115120
},
121+
"BUFFER_PROFILE|customized_ingress_lossless_profile": {
122+
"dynamic_th": "7",
123+
"pool": "ingress_lossless_pool",
124+
"size": "0"
125+
},
116126
"BUFFER_PROFILE|ingress_lossless_profile": {
117127
"dynamic_th": "7",
118128
"pool": "ingress_lossless_pool",

tests/db_migrator_input/config_db/reclaiming-buffer-dynamic-double-pools-input.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"profile": "NULL"
44
},
55
"BUFFER_PG|Ethernet8|3-4": {
6-
"profile": "customized_lossless_profile"
6+
"profile": "customized_ingress_lossless_profile"
77
},
88
"BUFFER_PG|Ethernet12|0": {
99
"profile": "ingress_lossy_profile"
@@ -55,6 +55,11 @@
5555
"BUFFER_PORT_INGRESS_PROFILE_LIST|Ethernet24": {
5656
"profile_list": "ingress_lossless_profile,ingress_lossy_profile"
5757
},
58+
"BUFFER_PROFILE|customized_egress_lossless_profile": {
59+
"dynamic_th": "7",
60+
"pool": "egress_lossless_pool",
61+
"size": "0"
62+
},
5863
"BUFFER_PROFILE|egress_lossless_profile": {
5964
"dynamic_th": "7",
6065
"pool": "egress_lossless_pool",
@@ -65,6 +70,11 @@
6570
"pool": "egress_lossy_pool",
6671
"size": "9216"
6772
},
73+
"BUFFER_PROFILE|customized_ingress_lossless_profile": {
74+
"dynamic_th": "7",
75+
"pool": "ingress_lossless_pool",
76+
"size": "0"
77+
},
6878
"BUFFER_PROFILE|ingress_lossless_profile": {
6979
"dynamic_th": "7",
7080
"pool": "ingress_lossless_pool",

tests/db_migrator_input/config_db/reclaiming-buffer-dynamic-single-pool-expected.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"profile": "NULL"
1313
},
1414
"BUFFER_PG|Ethernet8|3-4": {
15-
"profile": "customized_lossless_profile"
15+
"profile": "customized_ingress_lossless_profile"
1616
},
1717
"BUFFER_PG|Ethernet12|0": {
1818
"profile": "ingress_lossy_profile"
@@ -99,6 +99,11 @@
9999
"BUFFER_PORT_INGRESS_PROFILE_LIST|Ethernet24": {
100100
"profile_list": "ingress_lossless_profile"
101101
},
102+
"BUFFER_PROFILE|customized_egress_lossless_profile": {
103+
"dynamic_th": "7",
104+
"pool": "egress_lossless_pool",
105+
"size": "0"
106+
},
102107
"BUFFER_PROFILE|egress_lossless_profile": {
103108
"dynamic_th": "7",
104109
"pool": "egress_lossless_pool",
@@ -109,6 +114,11 @@
109114
"pool": "egress_lossy_pool",
110115
"size": "9216"
111116
},
117+
"BUFFER_PROFILE|customized_ingress_lossless_profile": {
118+
"dynamic_th": "7",
119+
"pool": "ingress_lossless_pool",
120+
"size": "0"
121+
},
112122
"BUFFER_PROFILE|ingress_lossless_profile": {
113123
"dynamic_th": "7",
114124
"pool": "ingress_lossless_pool",

tests/db_migrator_input/config_db/reclaiming-buffer-dynamic-single-pool-input.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"profile": "NULL"
44
},
55
"BUFFER_PG|Ethernet8|3-4": {
6-
"profile": "customized_lossless_profile"
6+
"profile": "customized_ingress_lossless_profile"
77
},
88
"BUFFER_PG|Ethernet12|0": {
99
"profile": "ingress_lossy_profile"
@@ -51,6 +51,11 @@
5151
"BUFFER_PORT_INGRESS_PROFILE_LIST|Ethernet24": {
5252
"profile_list": "ingress_lossless_profile"
5353
},
54+
"BUFFER_PROFILE|customized_egress_lossless_profile": {
55+
"dynamic_th": "7",
56+
"pool": "egress_lossless_pool",
57+
"size": "0"
58+
},
5459
"BUFFER_PROFILE|egress_lossless_profile": {
5560
"dynamic_th": "7",
5661
"pool": "egress_lossless_pool",
@@ -61,6 +66,11 @@
6166
"pool": "egress_lossy_pool",
6267
"size": "9216"
6368
},
69+
"BUFFER_PROFILE|customized_ingress_lossless_profile": {
70+
"dynamic_th": "7",
71+
"pool": "ingress_lossless_pool",
72+
"size": "0"
73+
},
6474
"BUFFER_PROFILE|ingress_lossless_profile": {
6575
"dynamic_th": "7",
6676
"pool": "ingress_lossless_pool",

0 commit comments

Comments
 (0)