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

[System ready] Report ready status to Sysmonitor daemon #481

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ def test_is_cmis_api(self, mock_class, expected_return_value):
mock_xcvr_api.__class__ = mock_class
assert is_cmis_api(mock_xcvr_api) == expected_return_value

@patch('swsscommon.swsscommon.SonicV2Connector')
def test_notify_system_ready(self, mock_dbconn):
mock_db = MagicMock()
mock_db.connect = MagicMock()
mock_db.delete = MagicMock()
mock_db.hmset = MagicMock()
mock_dbconn.return_value = mock_db

# Case 1: Report ready status
notify_system_ready()
mock_db.hmset.assert_called_once()

# Case 2: Should not report status again
mock_db.hmset.reset_mock()
notify_system_ready()
mock_db.hmset.assert_not_called()

@patch('xcvrd.xcvrd._wrapper_get_sfp_type')
@patch('xcvrd.xcvrd_utilities.port_event_helper.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
Expand Down
36 changes: 36 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,37 @@ def strip_unit_and_beautify(value, unit):
return str(value)


def notify_system_ready(fail_status=False, fail_reason='-'):
key = 'FEATURE|pmon'
statusvalue = {}

try:
state_db = swsscommon.SonicV2Connector()
state_db.connect(state_db.STATE_DB)
except Exception:
helper_logger.log_error('Failed to connect STATE_DB to report '
f'{SYSLOG_IDENTIFIER} ready status')
return

if fail_status:
statusvalue['up_status'] = 'false'
statusvalue['fail_reason'] = fail_reason
else:
statusvalue['up_status'] = 'true'

if getattr(notify_system_ready, 'reported', False):
helper_logger.log_debug(
f'{SYSLOG_IDENTIFIER} ready status already reported. Tried to '
f'report status: {statusvalue}')
return

state_db.delete(state_db.STATE_DB, key)
state_db.hmset(state_db.STATE_DB, key, statusvalue)
helper_logger.log_info(f'Report {SYSLOG_IDENTIFIER} ready status: '
f'{statusvalue}')
notify_system_ready.reported = True


def _wrapper_get_presence(physical_port):
if platform_chassis is not None:
try:
Expand Down Expand Up @@ -2375,6 +2406,11 @@ def retry_eeprom_reading(self):
# Update retry EEPROM set
self.retry_eeprom_set -= retry_success_set

# If we were here and now retry_eeprom_set is empty, then we can state
# that all SFPs accessible
if not self.retry_eeprom_set:
notify_system_ready()
fastiuk marked this conversation as resolved.
Show resolved Hide resolved


#
# Daemon =======================================================================
Expand Down
Loading