-
Notifications
You must be signed in to change notification settings - Fork 753
Fetch capability of mirror before configuring it #4089
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Failure is caused by rebasing the commit to the latest master. Investigating. |
Depends on sonic-net/sonic-swss#3934 |
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Depends on sonic-net/sonic-swss#3934 |
|
@qiluo-msft Can you help review this change? Thanks |
config/main.py
Outdated
| def is_port_mirror_capability_supported(direction, namespace=None): | ||
| """ Check if port mirror capability is supported for the given direction """ | ||
| try: | ||
| state_db = SonicV2Connector(host='127.0.0.1') |
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.
Could you use unix socket which has better performance?
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.
Fixed
config/main.py
Outdated
| return False | ||
|
|
||
| return True | ||
| except Exception: |
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.
Could you use more specific exception type?
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.
Removed as we do not expect any exception 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.
Pull Request Overview
This PR adds ASIC capability checking for port mirror direction support before allowing mirror session configuration. The change prevents users from configuring mirror sessions with directions (rx/tx/both) that are not supported by the underlying ASIC hardware.
- Added
is_port_mirror_capability_supported()function to query STATE_DB for ASIC capabilities - Integrated capability validation into
validate_mirror_session_config() - Added comprehensive test coverage for capability checking functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| config/main.py | Added capability checking function and validation logic to prevent unsupported mirror directions |
| tests/config_mirror_session_test.py | Added test cases for capability checking and removed trailing whitespace |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
config/main.py
Outdated
| def is_port_mirror_capability_supported(direction, namespace=None): | ||
| """ Check if port mirror capability is supported for the given direction """ | ||
| try: | ||
| state_db = SonicV2Connector(host='127.0.0.1') |
Copilot
AI
Nov 4, 2025
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.
The function accepts a namespace parameter but never uses it. Based on other functions in the codebase (e.g., lines 6188-6190), the namespace should be used when initializing SonicV2Connector. Either use the namespace parameter to create the connector with use_unix_socket_path=True and the appropriate namespace, or remove the unused parameter.
| state_db = SonicV2Connector(host='127.0.0.1') | |
| if namespace is not None: | |
| state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace) | |
| else: | |
| state_db = SonicV2Connector(host='127.0.0.1') |
config/main.py
Outdated
|
|
||
| # If no direction is specified, check both ingress and egress capabilities | ||
| if not direction: | ||
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | ||
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | ||
| return ingress_supported == "true" and egress_supported == "true" | ||
|
|
||
| if direction in ['rx', 'both']: | ||
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | ||
| if ingress_supported != "true": | ||
| return False | ||
|
|
||
| if direction in ['tx', 'both']: | ||
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | ||
| if egress_supported != "true": | ||
| return False | ||
|
|
||
| return True |
Copilot
AI
Nov 4, 2025
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.
The state_db connection is never explicitly closed. Based on patterns elsewhere in the codebase (e.g., line 6195), the connection should be closed after use with state_db.close(state_db.STATE_DB) to prevent resource leaks.
| # If no direction is specified, check both ingress and egress capabilities | |
| if not direction: | |
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | |
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | |
| return ingress_supported == "true" and egress_supported == "true" | |
| if direction in ['rx', 'both']: | |
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | |
| if ingress_supported != "true": | |
| return False | |
| if direction in ['tx', 'both']: | |
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | |
| if egress_supported != "true": | |
| return False | |
| return True | |
| try: | |
| # If no direction is specified, check both ingress and egress capabilities | |
| if not direction: | |
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | |
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | |
| return ingress_supported == "true" and egress_supported == "true" | |
| if direction in ['rx', 'both']: | |
| ingress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_INGRESS_MIRROR_CAPABLE") | |
| if ingress_supported != "true": | |
| return False | |
| if direction in ['tx', 'both']: | |
| egress_supported = state_db.get(state_db.STATE_DB, entry_name, "PORT_EGRESS_MIRROR_CAPABLE") | |
| if egress_supported != "true": | |
| return False | |
| return True | |
| finally: | |
| state_db.close(state_db.STATE_DB) |
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
It's weird that pretest passed locally but failed in the github |
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Stephen Sun <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@qiluo-msft can you please check if you are ok with comments handling and approve this PR? |
What I did
Fetch capability of ingress/egress mirror before configuring it and avoid configuring ingress/egress mirror on a platform that does not support it.
How I did it
Check the capability in
PORT_INGRESS_MIRROR_CAPABLEandPORT_EGRESS_MIRROR_CAPABLEinSTATE_DBtableSWITCH_CAPABILITY.The capability of ingress/egress mirror is inserted to STATE_DB by orchagent during initialization.
How to verify it
Manual test and unit test
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)