-
Notifications
You must be signed in to change notification settings - Fork 747
Fixing state_db not having delete_field attribute causing a crash when DPUs in bad state #4064
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
Changes from all commits
4dab08f
8ee9b1c
0732d9b
d0b102f
6ae9fb4
d5cf771
fe12399
fc01643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import subprocess | ||
import utilities_common.cli as clicommon | ||
from utilities_common.chassis import is_smartswitch, get_all_dpus | ||
from datetime import datetime, timedelta | ||
from datetime import datetime, timedelta, timezone | ||
|
||
TIMEOUT_SECS = 10 | ||
TRANSITION_TIMEOUT = timedelta(seconds=240) # 4 minutes | ||
|
@@ -27,6 +27,12 @@ def set_entry(self, table, key, entry): | |
for field, value in entry.items(): | ||
self.db.set("STATE_DB", redis_key, field, value) | ||
|
||
def delete_field(self, table, key, field): | ||
"""Delete a specific field from table|key.""" | ||
redis_key = f"{table}|{key}" | ||
client = self.db.get_redis_client("STATE_DB") | ||
return client.hdel(redis_key, field) | ||
|
||
# | ||
# 'chassis_modules' group ('config chassis_modules ...') | ||
# | ||
|
@@ -72,8 +78,9 @@ def set_state_transition_in_progress(db, chassis_module_name, value): | |
entry = state_db.get_entry('CHASSIS_MODULE_TABLE', chassis_module_name) or {} | ||
entry['state_transition_in_progress'] = value | ||
if value == 'True': | ||
entry['transition_start_time'] = datetime.utcnow().isoformat() | ||
entry['transition_start_time'] = datetime.now(timezone.utc).isoformat() | ||
else: | ||
# Remove transition_start_time from both local entry and database | ||
entry.pop('transition_start_time', None) | ||
vvolam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
state_db.delete_field('CHASSIS_MODULE_TABLE', chassis_module_name, 'transition_start_time') | ||
state_db.set_entry('CHASSIS_MODULE_TABLE', chassis_module_name, entry) | ||
|
@@ -92,7 +99,14 @@ def is_transition_timed_out(db, chassis_module_name): | |
start_time = datetime.fromisoformat(start_time_str) | ||
except ValueError: | ||
return False | ||
return datetime.utcnow() - start_time > TRANSITION_TIMEOUT | ||
|
||
# Use UTC everywhere for consistent comparison | ||
current_time = datetime.now(timezone.utc) | ||
if start_time.tzinfo is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rameshraghupathy do we need to handle a case when tzinfo is none? as it is always updated by chassisd and module_base. why is this if condition needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gpunathilell It is a T1 switch and there is nothing wrong in doing the additional check to be resilient. |
||
# If stored time is naive, assume it's UTC | ||
start_time = start_time.replace(tzinfo=timezone.utc) | ||
|
||
return current_time - start_time > TRANSITION_TIMEOUT | ||
|
||
# | ||
# Name: check_config_module_state_with_timeout | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same redis sonic dbconnector abstraction to delete https://github.com/rameshraghupathy/sonic-utilities/blob/fc016432a4d79dbb9eebd31f7f008759dc737122/config/chassis_modules.py#L85
Since we are using the db connector abstractions for the other two functions
https://github.com/rameshraghupathy/sonic-utilities/blob/fc016432a4d79dbb9eebd31f7f008759dc737122/config/chassis_modules.py#L28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gpunathilell Thank you for the suggestion about using the database connector abstraction consistently. While I agree this would improve consistency, this logic is currently undergoing broader refactoring in PRs #4031 and related PRs across sonic-platform-common, sonic-host-services, and sonic-platform-daemons. To avoid conflicts and duplicated effort, I believe the database access pattern consistency should be addressed as part of that broader refactoring work rather than making incremental changes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since refactoring will be done, please do not resolve the review comments, I will approve as this is blocking bug fix. Thank you