Skip to content

Commit 42354e6

Browse files
[201911][db_migrator] fix old 1911 feature config migration to a new … (sonic-net#1637)
* [201911][db_migrator] fix old 1911 feature config migration to a new one. This change is in addition to sonic-net#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 <[email protected]>
1 parent 5f62262 commit 42354e6

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

scripts/db_migrator.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ def migrate_intf_table(self):
154154
self.appDB.set(self.appDB.APPL_DB, table, 'NULL', 'NULL')
155155
if_db.append(if_name)
156156

157+
def migrate_feature_table(self):
158+
'''
159+
Combine CONTAINER_FEATURE and FEATURE tables into FEATURE table.
160+
'''
161+
feature_table = self.configDB.get_table('FEATURE')
162+
for feature, config in feature_table.items():
163+
state = config.pop('status', 'disabled')
164+
config['state'] = state
165+
self.configDB.set_entry('FEATURE', feature, config)
166+
167+
container_feature_table = self.configDB.get_table('CONTAINER_FEATURE')
168+
for feature, config in container_feature_table.items():
169+
self.configDB.mod_entry('FEATURE', feature, config)
170+
self.configDB.set_entry('CONTAINER_FEATURE', feature, None)
171+
157172
def version_unknown(self):
158173
"""
159174
version_unknown tracks all SONiC versions that doesn't have a version
@@ -207,6 +222,8 @@ def version_1_0_3(self):
207222
"""
208223
log.log_info('Handling version_1_0_3')
209224

225+
self.migrate_feature_table()
226+
210227
# Check ASIC type, if Mellanox platform then need DB migration
211228
if self.asic_type == "mellanox":
212229
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'):
@@ -246,15 +263,13 @@ def get_version(self):
246263

247264
return 'version_unknown'
248265

249-
250266
def set_version(self, version=None):
251267
if not version:
252268
version = self.CURRENT_VERSION
253269
log.log_info('Setting version to ' + version)
254270
entry = { self.TABLE_FIELD : version }
255271
self.configDB.set_entry(self.TABLE_NAME, self.TABLE_KEY, entry)
256272

257-
258273
def common_migration_ops(self):
259274
try:
260275
with open(INIT_CFG_FILE) as f:
@@ -263,15 +278,16 @@ def common_migration_ops(self):
263278
raise Exception(str(e))
264279

265280
for init_cfg_table, table_val in init_db.items():
266-
data = self.configDB.get_table(init_cfg_table)
267-
if data:
268-
# Ignore overriding the values that pre-exist in configDB
269-
continue
270281
log.log_info("Migrating table {} from INIT_CFG to config_db".format(init_cfg_table))
271-
# Update all tables that do not exist in configDB but are present in INIT_CFG
272-
for init_table_key, init_table_val in table_val.items():
273-
self.configDB.set_entry(init_cfg_table, init_table_key, init_table_val)
274-
282+
for key in table_val:
283+
curr_cfg = self.configDB.get_entry(init_cfg_table, key)
284+
init_cfg = table_val[key]
285+
286+
# Override init config with current config.
287+
# This will leave new fields from init_config
288+
# in new_config, but not override existing configuration.
289+
new_cfg = {**init_cfg, **curr_cfg}
290+
self.configDB.set_entry(init_cfg_table, key, new_cfg)
275291

276292
def migrate(self):
277293
version = self.get_version()

0 commit comments

Comments
 (0)