diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index ba9b9eea2e..116ade6a31 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -154,6 +154,22 @@ 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 @@ -207,6 +223,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'): @@ -246,7 +264,6 @@ def get_version(self): return 'version_unknown' - def set_version(self, version=None): if not version: version = self.CURRENT_VERSION @@ -254,7 +271,6 @@ def set_version(self, version=None): 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: @@ -263,15 +279,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()