Skip to content

Commit 753b550

Browse files
authored
Chassisd do an explicit stop of the config_manager (#328)
* Fix to explicit stop the config_manager * Add tests for chassisd run method.
1 parent 879d630 commit 753b550

File tree

6 files changed

+61
-1
lines changed

6 files changed

+61
-1
lines changed

sonic-chassisd/scripts/chassisd

+3
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ class ChassisdDaemon(daemon_base.DaemonBase):
444444

445445
self.log_info("Stop daemon main loop")
446446

447+
if config_manager is not None:
448+
config_manager.task_stop()
449+
447450
# Delete all the information from DB and then exit
448451
self.module_updater.deinit()
449452

sonic-chassisd/tests/mock_swsscommon.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def __init__(self, db, table_name):
77
self.mock_dict = {}
88

99
def _del(self, key):
10-
del self.mock_dict[key]
10+
if key in self.mock_dict:
11+
del self.mock_dict[key]
1112
pass
1213

1314
def set(self, key, fvs):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
Mock implementation of sonic_platform package for unit testing
3+
"""
4+
5+
from . import chassis
6+
from . import platform
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Mock implementation of sonic_platform package for unit testing
3+
"""
4+
5+
import sys
6+
if sys.version_info.major == 3:
7+
from unittest import mock
8+
else:
9+
import mock
10+
11+
from sonic_platform_base.chassis_base import ChassisBase
12+
13+
14+
class Chassis(ChassisBase):
15+
def __init__(self):
16+
ChassisBase.__init__(self)
17+
self.eeprom = mock.MagicMock()
18+
19+
def get_eeprom(self):
20+
return self.eeprom
21+
22+
def get_my_slot(self):
23+
return 1
24+
25+
def get_supervisor_slot(self):
26+
return 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Mock implementation of sonic_platform package for unit testing
3+
"""
4+
5+
from sonic_platform_base.platform_base import PlatformBase
6+
from sonic_platform.chassis import Chassis
7+
8+
9+
class Platform(PlatformBase):
10+
def __init__(self):
11+
PlatformBase.__init__(self)
12+
self._chassis = Chassis()

sonic-chassisd/tests/test_chassisd.py

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
daemon_base.db_connect = MagicMock()
1515

1616
test_path = os.path.dirname(os.path.abspath(__file__))
17+
18+
# Add mocked_libs path so that the file under test can load mocked modules from there
19+
mocked_libs_path = os.path.join(test_path, 'mocked_libs')
20+
sys.path.insert(0, mocked_libs_path)
21+
1722
modules_path = os.path.dirname(test_path)
1823
scripts_path = os.path.join(modules_path, "scripts")
1924
sys.path.insert(0, modules_path)
@@ -503,3 +508,10 @@ def test_signal_handler():
503508
assert daemon_chassisd.log_info.call_count == 0
504509
assert daemon_chassisd.stop.set.call_count == 0
505510
assert exit_code == 0
511+
512+
def test_daemon_run():
513+
# Test the chassisd run
514+
daemon_chassisd = ChassisdDaemon(SYSLOG_IDENTIFIER)
515+
daemon_chassisd.stop = MagicMock()
516+
daemon_chassisd.stop.wait.return_value = True
517+
daemon_chassisd.run()

0 commit comments

Comments
 (0)