Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[db_migrator] make LOG_LEVEL_DB migration more robust #2651

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception

Could you use more specific exception type?
If you really want to catch all exception, log the stack info.

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"
}
}