|
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:
|
@@ -1122,6 +1125,31 @@ def migrate(self):
|
1122 | 1125 | version = next_version
|
1123 | 1126 | # Perform common migration ops
|
1124 | 1127 | self.common_migration_ops()
|
| 1128 | + config = self.configDB.get_config() |
| 1129 | + # Fix table key in tuple |
| 1130 | + for table_name, table in config.items(): |
| 1131 | + new_table = {} |
| 1132 | + hit = False |
| 1133 | + for table_key, table_val in table.items(): |
| 1134 | + if isinstance(table_key, tuple): |
| 1135 | + new_key = "|".join(table_key) |
| 1136 | + new_table[new_key] = table_val |
| 1137 | + hit = True |
| 1138 | + else: |
| 1139 | + new_table[table_key] = table_val |
| 1140 | + if hit: |
| 1141 | + config[table_name] = new_table |
| 1142 | + # Run yang validation |
| 1143 | + yang_parser = sonic_yang.SonicYang(YANG_MODELS_DIR) |
| 1144 | + yang_parser.loadYangModel() |
| 1145 | + try: |
| 1146 | + yang_parser.loadData(configdbJson=config) |
| 1147 | + yang_parser.validate_data_tree() |
| 1148 | + except sonic_yang.SonicYangException as e: |
| 1149 | + syslog.syslog(syslog.LOG_CRIT, "Yang validation failed: " + str(e)) |
| 1150 | + if os.environ["UTILITIES_UNIT_TESTING"] == "2": |
| 1151 | + raise |
| 1152 | + |
1125 | 1153 |
|
1126 | 1154 | def main():
|
1127 | 1155 | try:
|
|
0 commit comments