-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run yang validation in db migrator (#3102)
What I did Add unit test/runtime alert for db_migrator.py/load_minigraph: ConfigDB passing yang validation How I did it Use subprocess to run yang validation, and then warm-reboot performance will not change. Check /etc/sonic/mgmt_test_mark, this mark_file means this device is under end to end test. For unit test, db_migrator will wait for validation result and raise exception. For end to end test, db_migrator will wait for validation result and raise exception. How to verify it Run unit test and run end to end test
- Loading branch information
Showing
13 changed files
with
142 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
import json | ||
import argparse | ||
import sonic_yang | ||
|
||
from sonic_py_common import logger | ||
|
||
YANG_MODELS_DIR = "/usr/local/yang-models" | ||
SYSLOG_IDENTIFIER = 'config_validator' | ||
|
||
# Global logger instance | ||
log = logger.Logger(SYSLOG_IDENTIFIER) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-c', | ||
dest='config', | ||
metavar='config file', | ||
type=str, | ||
required=True, | ||
help='the config file to be validated', | ||
default=None) | ||
|
||
args = parser.parse_args() | ||
config_file = args.config | ||
with open(config_file) as fp: | ||
config = json.load(fp) | ||
# Run yang validation | ||
yang_parser = sonic_yang.SonicYang(YANG_MODELS_DIR) | ||
yang_parser.loadYangModel() | ||
try: | ||
yang_parser.loadData(configdbJson=config) | ||
yang_parser.validate_data_tree() | ||
except sonic_yang.SonicYangException as e: | ||
log.log_error("Yang validation failed: " + str(e)) | ||
raise | ||
if len(yang_parser.tablesWithOutYang): | ||
log.log_error("Tables without yang models: " + str(yang_parser.tablesWithOutYang)) | ||
raise Exception("Tables without yang models: " + str(yang_parser.tablesWithOutYang)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters