Skip to content

Commit

Permalink
[201911][db_migrator] fix old 1911 feature config migration to a new … (
Browse files Browse the repository at this point in the history
#1637)

* [201911][db_migrator] fix old 1911 feature config migration to a new one.

This change is in addition to #1522.
The init_cfg.json may have important fields added to configuration, while in
previous fix these entries will not be added when table already exists.
This change fixes this behaviour. Also, in order to preserve users auto_restart
configuration a special logic for migrating CONTAINER_FEATURE table has been implemented.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Jun 3, 2021
1 parent 5f62262 commit 42354e6
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ def migrate_intf_table(self):
self.appDB.set(self.appDB.APPL_DB, table, 'NULL', 'NULL')
if_db.append(if_name)

def migrate_feature_table(self):
'''
Combine CONTAINER_FEATURE and FEATURE tables into FEATURE table.
'''
feature_table = self.configDB.get_table('FEATURE')
for feature, config in feature_table.items():
state = config.pop('status', 'disabled')
config['state'] = state
self.configDB.set_entry('FEATURE', feature, config)

container_feature_table = self.configDB.get_table('CONTAINER_FEATURE')
for feature, config in container_feature_table.items():
self.configDB.mod_entry('FEATURE', feature, config)
self.configDB.set_entry('CONTAINER_FEATURE', feature, None)

def version_unknown(self):
"""
version_unknown tracks all SONiC versions that doesn't have a version
Expand Down Expand Up @@ -207,6 +222,8 @@ def version_1_0_3(self):
"""
log.log_info('Handling version_1_0_3')

self.migrate_feature_table()

# Check ASIC type, if Mellanox platform then need DB migration
if self.asic_type == "mellanox":
if self.mellanox_buffer_migrator.mlnx_migrate_buffer_pool_size('version_1_0_3', 'version_1_0_4') and self.mellanox_buffer_migrator.mlnx_migrate_buffer_profile('version_1_0_3', 'version_1_0_4'):
Expand Down Expand Up @@ -246,15 +263,13 @@ def get_version(self):

return 'version_unknown'


def set_version(self, version=None):
if not version:
version = self.CURRENT_VERSION
log.log_info('Setting version to ' + version)
entry = { self.TABLE_FIELD : version }
self.configDB.set_entry(self.TABLE_NAME, self.TABLE_KEY, entry)


def common_migration_ops(self):
try:
with open(INIT_CFG_FILE) as f:
Expand All @@ -263,15 +278,16 @@ def common_migration_ops(self):
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)

for key in table_val:
curr_cfg = self.configDB.get_entry(init_cfg_table, key)
init_cfg = table_val[key]

# Override init config with current config.
# This will leave new fields from init_config
# in new_config, but not override existing configuration.
new_cfg = {**init_cfg, **curr_cfg}
self.configDB.set_entry(init_cfg_table, key, new_cfg)

def migrate(self):
version = self.get_version()
Expand Down

0 comments on commit 42354e6

Please sign in to comment.