|
6 | 6 | import sys
|
7 | 7 | import traceback
|
8 | 8 | import re
|
| 9 | +import sonic_yang |
| 10 | +import syslog |
9 | 11 |
|
10 | 12 | from sonic_py_common import device_info, logger
|
11 | 13 | from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
|
12 | 14 | from minigraph import parse_xml
|
13 | 15 |
|
14 | 16 | INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
|
15 | 17 | MINIGRAPH_FILE = '/etc/sonic/minigraph.xml'
|
| 18 | +YANG_MODELS_DIR = "/usr/local/yang-models" |
16 | 19 |
|
17 | 20 | # mock the redis for unit test purposes #
|
18 | 21 | try:
|
@@ -1137,6 +1140,31 @@ def migrate(self):
|
1137 | 1140 | version = next_version
|
1138 | 1141 | # Perform common migration ops
|
1139 | 1142 | 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 | + |
1140 | 1168 |
|
1141 | 1169 | def main():
|
1142 | 1170 | try:
|
|
0 commit comments