Skip to content

[LEDD] Subscribe to PORT_TABLE in APPL_DB for port oper status#798

Merged
judyjoseph merged 2 commits intosonic-net:masterfrom
prgeor:ledd
Apr 20, 2026
Merged

[LEDD] Subscribe to PORT_TABLE in APPL_DB for port oper status#798
judyjoseph merged 2 commits intosonic-net:masterfrom
prgeor:ledd

Conversation

@prgeor
Copy link
Copy Markdown
Collaborator

@prgeor prgeor commented Apr 17, 2026

Description

Subscribe to PORT_TABLE in APPL_DB for port oper status

Motivation and Context

Continuous log flooding from ledd daemon even if there is change in port operational status

2026 Apr 17 15:15:31.558551 SW1 NOTICE pmon#ledd[2219]: Setting Port Ethernet428 LED state change for down
2026 Apr 17 15:15:31.558737  SW1 NOTICE pmon#ledd[2219]: Received PORT table event: key=Ethernet428, state=up
2026 Apr 17 15:15:31.564639  SW1 NOTICE pmon#ledd[2219]: Received PORT table event: key=Ethernet424, state=up

This is because previously the ledd daemon had subscribed to PORT_TABLE of STATE_DB which can get updated by Orchagent which can unnecessarily trigger processing of port oper status by ledd

How Has This Been Tested?

Validated this in lab switch where the logs were getting flooded

Additional Information (Optional)

Signed-off-by: Prince George <prgeor@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates sonic-ledd to track port operational status from PORT_TABLE in APPL_DB (instead of STATE_DB) to reduce unnecessary event processing/log flooding caused by STATE_DB updates.

Changes:

  • Switch PORT table subscription from STATE_DB to APPL_DB (APP_PORT_TABLE_NAME).
  • Update the expected oper-status field name from netdev_oper_status to oper_status.
Comments suppressed due to low confidence (1)

sonic-ledd/scripts/ledd:212

  • PORT_OP_FIELD was changed to oper_status, but findFrontPanelPorts() still reads initial port state from STATE_DB STATE_PORT_TABLE_NAME (which historically uses netdev_oper_status, as reflected by existing unit tests). This will likely default ports to down at startup and initialize LEDs incorrectly because the subscriber table only delivers changes, not the current snapshot. Consider fetching the initial oper status from APPL_DB APP_PORT_TABLE_NAME (to match the new subscription) or handling different field names per DB.

        for namespace in namespaces:
            port_cfg_table = self.portObserver.getDatabaseTable("CONFIG_DB", swsscommon.CFG_PORT_TABLE_NAME, namespace)
            port_st_table = self.portObserver.getDatabaseTable("STATE_DB", swsscommon.STATE_PORT_TABLE_NAME, namespace)
            for key in port_cfg_table.getKeys():

Comment thread sonic-ledd/scripts/ledd
Comment on lines 128 to +135
def __init__(self):
# Subscribe to PORT table notifications in the STATE DB
self.tables = {}
self.sel = swsscommon.Select()

def subscribePortTable(self, namespaces):
for namespace in namespaces:
self.subscribeDbTable("STATE_DB", swsscommon.STATE_PORT_TABLE_NAME, namespace)
self.subscribeDbTable("APPL_DB", swsscommon.APP_PORT_TABLE_NAME, namespace)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

The comment in PortStateObserver.__init__ says it subscribes to PORT table notifications in STATE_DB, but subscribePortTable() now subscribes to APPL_DB. Updating this comment will avoid confusion for future maintainers/debugging.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Comment thread sonic-ledd/scripts/ledd
Comment on lines 40 to +43
class Port():
PORT_UP = "up" # All subports are up
PORT_DOWN = "down" # All subports are down
PORT_OP_FIELD = "netdev_oper_status"
PORT_OP_FIELD = "oper_status"
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This change switches the subscribed table/field name (STATE_DB + netdev_oper_status -> APPL_DB + oper_status). The existing sonic-ledd/tests/test_ledd.py fixtures assert netdev_oper_status and mock STATE_DB behavior, so unit tests will fail and won’t validate the new behavior. Please update/add tests to cover APPL_DB PORT_TABLE events and the oper_status field.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

@judyjoseph
Copy link
Copy Markdown
Contributor

can you update the tests too @prgeor

Signed-off-by: Prince George <prgeor@microsoft.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@prgeor
Copy link
Copy Markdown
Collaborator Author

prgeor commented Apr 18, 2026

can you update the tests too @prgeor

@judyjoseph addressed

@judyjoseph judyjoseph merged commit 3bb3540 into sonic-net:master Apr 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants