diff --git a/config/main.py b/config/main.py index d708f95240..ee0aac9c1e 100755 --- a/config/main.py +++ b/config/main.py @@ -1049,7 +1049,7 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart): log.log_info("'reload' stopping services...") _stop_services(db.cfgdb) - # In Single AISC platforms we have single DB service. In multi-ASIC platforms we have a global DB + # In Single ASIC platforms we have single DB service. In multi-ASIC platforms we have a global DB # service running in the host + DB services running in each ASIC namespace created per ASIC. # In the below logic, we get all namespaces in this platform and add an empty namespace '' # denoting the current namespace which we are in ( the linux host ) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 7ac65bb041..06681b6a0c 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -1,13 +1,15 @@ #!/usr/bin/env python import argparse +import json +import os import sys import traceback from sonic_py_common import device_info, logger from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector - +INIT_CFG_FILE = '/etc/sonic/init_cfg.json' SYSLOG_IDENTIFIER = 'db_migrator' @@ -228,6 +230,23 @@ def set_version(self, version=None): self.configDB.set_entry(self.TABLE_NAME, self.TABLE_KEY, entry) + def common_migration_ops(self): + try: + with open(INIT_CFG_FILE) as f: + init_db = json.load(f) + except Exception as e: + raise Exception(str(e)) + + for init_cfg_table, table_val in init_db.items(): + data = self.configDB.get_table(init_cfg_table) + if data: + # Ignore overriding the values that pre-exist in configDB + continue + log.log_info("Migrating table {} from INIT_CFG to config_db".format(init_cfg_table)) + # Update all tables that do not exist in configDB but are present in INIT_CFG + for init_table_key, init_table_val in table_val.items(): + self.configDB.set_entry(init_cfg_table, init_table_key, init_table_val) + def migrate(self): version = self.get_version() log.log_info('Upgrading from version ' + version) @@ -236,7 +255,8 @@ def migrate(self): if next_version == version: raise Exception('Version migrate from %s stuck in same version' % version) version = next_version - + # Perform common migration ops + self.common_migration_ops() def main(): try: