Skip to content

Commit

Permalink
Using config_db CHASSIS_MODULE table admin_status change notification…
Browse files Browse the repository at this point in the history
… to call the platform API
  • Loading branch information
rameshraghupathy committed Nov 18, 2024
1 parent 2469f7f commit 364f522
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 55 deletions.
9 changes: 7 additions & 2 deletions sonic-chassisd/scripts/chassisd
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,14 @@ class SmartSwitchConfigManagerTask(ProcessTaskBase):
(key, op, fvp) = sst.pop()

if op == 'SET':
admin_state = MODULE_ADMIN_DOWN
fvs = dict(fvp)
admin_status = fvs.get('admin_status')
if admin_status == 'up':
admin_state = MODULE_ADMIN_UP
else:
admin_state = MODULE_ADMIN_DOWN
elif op == 'DEL':
admin_state = MODULE_ADMIN_UP
admin_state = MODULE_ADMIN_DOWN
else:
continue

Expand Down
48 changes: 0 additions & 48 deletions sonic-chassisd/tests/mock_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,54 +177,6 @@ def get_dataplane_state(self):
def get_controlplane_state(self):
raise NotImplementedError

def _is_first_boot(self, module):
"""Checks if the reboot-cause file indicates a first boot."""
file_path = os.path.join("path_to_reboot_cause_dir", module.lower(), "reboot-cause.txt")
try:
with open(file_path, 'r') as f:
content = f.read().strip()
return content == "First boot"
except FileNotFoundError:
return False

def persist_dpu_reboot_cause(self, reboot_cause, module):
"""Mock implementation to persist reboot cause."""
file_path = os.path.join("path_to_reboot_cause_dir", module.lower(), "reboot-cause.txt")
with open(file_path, 'w') as f:
f.write(reboot_cause)

def _rotate_files(self, module):
"""Mock implementation to simulate file rotation."""
os.rename(f"{module}_reboot-cause.txt", f"{module}_reboot-cause.old.txt")
os.remove(f"{module}_reboot-cause.older.txt")

def update_dpu_reboot_cause_to_db(self, module):
"""Mock implementation to update reboot cause in a database."""
pass

def _get_current_time_str(self):
"""Mock implementation to get the current time string."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

def _get_history_path(self, module, file_name):
"""Mock implementation to get the history file path."""
return os.path.join("path_to_history_dir", module.lower(), file_name)

def persist_dpu_reboot_time(self, module):
"""Mock implementation to persist the current reboot time."""
file_path = os.path.join("path_to_reboot_time_dir", module.lower(), "reboot-time.txt")
with open(file_path, 'w') as f:
f.write(self._get_current_time_str())

def retrieve_dpu_reboot_time(self, module):
"""Mock implementation to retrieve the persisted reboot time."""
file_path = os.path.join("path_to_reboot_time_dir", module.lower(), "reboot-time.txt")
try:
with open(file_path, 'r') as f:
return f.read().strip()
except FileNotFoundError:
return None

class MockDpuChassis:

def get_dpu_id(self):
Expand Down
5 changes: 0 additions & 5 deletions sonic-chassisd/tests/test_chassisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,6 @@ def test_smartswitch_module_db_update():
module_updater._is_first_boot(name)
module_updater.persist_dpu_reboot_time(name)
module_updater.update_dpu_reboot_cause_to_db(name)
# Verify that the custom open was called with the expected file path
# mock_file_instance = open(expected_path)
# mock_file_instance.write.assert_any_call("cause: Power loss\n")
# mock_file.assert_called_with(expected_path, 'r')
# mock_makedirs.assert_called_once_with("/host/reboot-cause/module/reboot_cause/dpu0/history", exist_ok=True)


def test_platform_json_file_exists_and_valid():
Expand Down

0 comments on commit 364f522

Please sign in to comment.