Skip to content

Commit

Permalink
[db_migrator] make LOG_LEVEL_DB migration more robust (#2651)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stepanblyschak committed Feb 7, 2023
1 parent a2520e6 commit f9130d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 12 additions & 8 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,18 @@ def version_3_0_5(self):
keys = self.loglevelDB.keys(self.loglevelDB.LOGLEVEL_DB, "*")
if keys is not None:
for key in keys:
if key != "JINJA2_CACHE":
fvs = self.loglevelDB.get_all(self.loglevelDB.LOGLEVEL_DB, key)
component = key.split(":")[1]
loglevel = fvs[loglevel_field]
logoutput = fvs[logoutput_field]
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), loglevel_field, loglevel)
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), logoutput_field, logoutput)
self.loglevelDB.delete(self.loglevelDB.LOGLEVEL_DB, key)
try:
if key != "JINJA2_CACHE":
fvs = self.loglevelDB.get_all(self.loglevelDB.LOGLEVEL_DB, key)
component = key.split(":")[1]
loglevel = fvs[loglevel_field]
logoutput = fvs[logoutput_field]
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), loglevel_field, loglevel)
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, component), logoutput_field, logoutput)
except Exception as err:
log.log_warning('Error occured during LOGLEVEL_DB migration for {}. Ignoring key {}'.format(err, key))
finally:
self.loglevelDB.delete(self.loglevelDB.LOGLEVEL_DB, key)
self.set_version('version_3_0_6')
return 'version_3_0_6'

Expand Down
7 changes: 5 additions & 2 deletions tests/db_migrator_input/loglevel_db/logger_tables_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"LOGLEVEL": "SAI_LOG_LEVEL_NOTICE",
"LOGOUTPUT": "SYSLOG"
},
"JINJA2_CACHE": {}
}
"JINJA2_CACHE": {},
"INVALID:INVALID": {
"invalid": "invalid"
}
}

0 comments on commit f9130d1

Please sign in to comment.