Skip to content

Commit

Permalink
Copy missing values from INIT_CFG to config_db as part of db_migratio…
Browse files Browse the repository at this point in the history
…n task (sonic-net#1209)
  • Loading branch information
vaibhavhd authored Nov 6, 2020
1 parent 927bf9b commit ee6bc49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
24 changes: 22 additions & 2 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
@@ -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'


Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit ee6bc49

Please sign in to comment.