Skip to content

Commit f9130d1

Browse files
[db_migrator] make LOG_LEVEL_DB migration more robust (#2651)
It could be that LOG_LEVEL_DB includes some invalid data and/or a KEY_SET that is not cleaned up due to an issue, for example we observed _gearsyncd_KEY_SET set included in the LOG_LEVEL_DB and preserved in warm reboot. However, this key is not of type hash which leads to an exception and migration failure. The migration logic should be more robust allowing users to upgrade even though some daemon has left overs in the LOG_LEVEL_DB or invalid data is written. - What I did To fix migration issue that leads to device configuration being lost. - How I did it Wrap the logic in try/except/finally. - How to verify it 202205 -> 202211/master upgrade. Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
1 parent a2520e6 commit f9130d1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

scripts/db_migrator.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,18 @@ def version_3_0_5(self):
822822
keys = self.loglevelDB.keys(self.loglevelDB.LOGLEVEL_DB, "*")
823823
if keys is not None:
824824
for key in keys:
825-
if key != "JINJA2_CACHE":
826-
fvs = self.loglevelDB.get_all(self.loglevelDB.LOGLEVEL_DB, key)
827-
component = key.split(":")[1]
828-
loglevel = fvs[loglevel_field]
829-
logoutput = fvs[logoutput_field]
830-
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), loglevel_field, loglevel)
831-
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), logoutput_field, logoutput)
832-
self.loglevelDB.delete(self.loglevelDB.LOGLEVEL_DB, key)
825+
try:
826+
if key != "JINJA2_CACHE":
827+
fvs = self.loglevelDB.get_all(self.loglevelDB.LOGLEVEL_DB, key)
828+
component = key.split(":")[1]
829+
loglevel = fvs[loglevel_field]
830+
logoutput = fvs[logoutput_field]
831+
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), loglevel_field, loglevel)
832+
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), logoutput_field, logoutput)
833+
except Exception as err:
834+
log.log_warning('Error occured during LOGLEVEL_DB migration for {}. Ignoring key {}'.format(err, key))
835+
finally:
836+
self.loglevelDB.delete(self.loglevelDB.LOGLEVEL_DB, key)
833837
self.set_version('version_3_0_6')
834838
return 'version_3_0_6'
835839

tests/db_migrator_input/loglevel_db/logger_tables_input.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"LOGLEVEL": "SAI_LOG_LEVEL_NOTICE",
88
"LOGOUTPUT": "SYSLOG"
99
},
10-
"JINJA2_CACHE": {}
11-
}
10+
"JINJA2_CACHE": {},
11+
"INVALID:INVALID": {
12+
"invalid": "invalid"
13+
}
14+
}

0 commit comments

Comments
 (0)