-
Notifications
You must be signed in to change notification settings - Fork 799
[show interfaces] "show interfaces flap" command does not support multi-ASIC platforms #4316
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
Open
pnakka28
wants to merge
4
commits into
sonic-net:master
Choose a base branch
from
pnakka28:support_multiasic_flap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,24 +449,21 @@ def mpls(ctx, interfacename, namespace, display): | |
| interfaces.add_command(portchannel.portchannel) | ||
|
|
||
|
|
||
|
|
||
| @interfaces.command() | ||
| @click.argument('interfacename', required=False) | ||
| @multi_asic_util.multi_asic_click_options | ||
| @click.pass_context | ||
| def flap(ctx, interfacename): | ||
| def flap(ctx, interfacename, namespace, display): | ||
| """Show Interface Flap Information <interfacename>""" | ||
|
|
||
| namespace = '' # Default namespace | ||
| port_dict = multi_asic.get_port_table(namespace=namespace) | ||
| if interfacename: | ||
| display = constants.DISPLAY_ALL | ||
|
|
||
| masic = multi_asic_util.MultiAsic(display_option=display, namespace_option=namespace) | ||
| ns_list = masic.get_ns_list_based_on_options() | ||
pnakka28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # If interfacename is given, validate it | ||
| if interfacename: | ||
| interfacename = try_convert_interfacename_from_alias(ctx, interfacename) | ||
| if interfacename not in port_dict: | ||
| ctx.fail("Invalid interface name {}".format(interfacename)) | ||
|
|
||
| db = SonicV2Connector(host=REDIS_HOSTIP) | ||
| db.connect(db.APPL_DB) | ||
|
|
||
| # Prepare the table headers and body | ||
| header = [ | ||
|
|
@@ -478,41 +475,57 @@ def flap(ctx, interfacename): | |
| 'Link Up TimeStamp(UTC)' | ||
| ] | ||
| body = [] | ||
| intf_found = False | ||
|
|
||
| for ns in ns_list: | ||
| masic.current_namespace = ns | ||
| appl_db = multi_asic.connect_to_all_dbs_for_ns(namespace=ns) | ||
| port_dict = multi_asic.get_port_table(namespace=ns) | ||
|
|
||
| # Loop through all ports or the specified port | ||
| ports = [interfacename] if interfacename else natsorted(list(port_dict.keys())) | ||
|
|
||
| # Loop through all ports or the specified port | ||
| ports = [interfacename] if interfacename else natsorted(list(port_dict.keys())) | ||
| for port in ports: | ||
| if port not in port_dict: | ||
| continue | ||
|
|
||
| for port in ports: | ||
| port_data = db.get_all(db.APPL_DB, f'PORT_TABLE:{port}') or {} | ||
| # Skip internal ports based on display option | ||
| if masic.skip_display(constants.PORT_OBJ, port): | ||
| continue | ||
| if interfacename and port == interfacename: | ||
| intf_found = True | ||
| port_data = appl_db.get_all(appl_db.APPL_DB, f'PORT_TABLE:{port}') or {} | ||
|
|
||
| flap_count = port_data.get('flap_count', 'Never') | ||
| admin_status = port_data.get('admin_status', 'Unknown').capitalize() | ||
| oper_status = port_data.get('oper_status', 'Unknown').capitalize() | ||
| flap_count = port_data.get('flap_count', 'Never') | ||
| admin_status = port_data.get('admin_status', 'Unknown').capitalize() | ||
| oper_status = port_data.get('oper_status', 'Unknown').capitalize() | ||
|
|
||
| # Get timestamps and convert them to UTC format if possible | ||
| last_up_time = port_data.get('last_up_time', 'Never') | ||
| last_down_time = port_data.get('last_down_time', 'Never') | ||
| # Get timestamps and convert them to UTC format if possible | ||
| last_up_time = port_data.get('last_up_time', 'Never') | ||
| last_down_time = port_data.get('last_down_time', 'Never') | ||
|
|
||
| # Format output row | ||
| row = [ | ||
| port, | ||
| flap_count, | ||
| admin_status, | ||
| oper_status, | ||
| f"{last_down_time}" if last_down_time != 'Never' else 'Never', | ||
| f"{last_up_time}" if last_up_time != 'Never' else 'Never' | ||
| ] | ||
| # Format output row | ||
| row = [ | ||
| port, | ||
| flap_count, | ||
| admin_status, | ||
| oper_status, | ||
| last_down_time, | ||
| last_up_time | ||
| ] | ||
|
|
||
| body.append(row) | ||
| body.append(row) | ||
|
|
||
| # Validate interface name after checking all namespaces | ||
| if interfacename and not intf_found: | ||
| ctx.fail("Invalid interface name {}".format(interfacename)) | ||
|
|
||
| # Sort the body by interface name for consistent display | ||
| body = natsorted(body, key=lambda x: x[0]) | ||
|
|
||
| # Display the formatted table | ||
| click.echo(tabulate(body, header)) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pnakka28 db connection does not need to be closed at the end? |
||
| db.close(db.APPL_DB) | ||
|
|
||
|
|
||
| def get_all_port_errors(interfacename): | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import os | ||
| import importlib | ||
|
|
||
| from click.testing import CliRunner | ||
|
|
||
| import show.main as show | ||
|
|
||
| intf_flap_masic_expected_output_default = """\ | ||
| Interface Flap Count Admin Oper Link Down TimeStamp(UTC) Link Up TimeStamp(UTC) | ||
| ----------- ------------ ------- ------- -------------------------- ------------------------ | ||
| Ethernet0 5 Up Up Sat Jan 17 00:04:42 2025 Sat Jan 18 00:08:42 2025 | ||
| Ethernet4 Never Up Up Never Never | ||
| Ethernet16 Never Unknown Unknown Never Never | ||
| """ | ||
|
|
||
| # Display all: all namespaces (asic0 + asic1) including backplane ports | ||
| intf_flap_masic_expected_output_display_all = """\ | ||
| Interface Flap Count Admin Oper Link Down TimeStamp(UTC) Link Up TimeStamp(UTC) | ||
| -------------- ------------ ------- ------- -------------------------- ------------------------ | ||
| Ethernet0 5 Up Up Sat Jan 17 00:04:42 2025 Sat Jan 18 00:08:42 2025 | ||
| Ethernet4 Never Up Up Never Never | ||
| Ethernet16 Never Unknown Unknown Never Never | ||
| Ethernet64 2 Up Up Thu Feb 12 23:03:40 2026 Thu Feb 12 23:25:31 2026 | ||
| Ethernet-BP0 Never Up Up Never Never | ||
| Ethernet-BP4 Never Up Up Never Never | ||
| Ethernet-BP256 Never Up Up Never Never | ||
| Ethernet-BP260 Never Up Up Never Never | ||
| """ | ||
|
|
||
| intf_flap_masic_expected_output_ethernet0 = """\ | ||
| Interface Flap Count Admin Oper Link Down TimeStamp(UTC) Link Up TimeStamp(UTC) | ||
| ----------- ------------ ------- ------ -------------------------- ------------------------ | ||
| Ethernet0 5 Up Up Sat Jan 17 00:04:42 2025 Sat Jan 18 00:08:42 2025 | ||
| """ | ||
|
|
||
| intf_flap_masic_expected_output_ethernet64 = """\ | ||
| Interface Flap Count Admin Oper Link Down TimeStamp(UTC) Link Up TimeStamp(UTC) | ||
| ----------- ------------ ------- ------ -------------------------- ------------------------ | ||
| Ethernet64 2 Up Up Thu Feb 12 23:03:40 2026 Thu Feb 12 23:25:31 2026 | ||
| """ | ||
|
|
||
|
|
||
| class TestInterfacesFlapMasic(object): | ||
| """Test cases for 'show interfaces flap' on multi-ASIC platforms.""" | ||
|
|
||
| @classmethod | ||
| def setup_class(cls): | ||
| print("SETUP") | ||
| from .mock_tables import mock_multi_asic | ||
| importlib.reload(mock_multi_asic) | ||
| from .mock_tables import dbconnector | ||
| dbconnector.load_namespace_config() | ||
|
|
||
| def test_show_interfaces_flap_masic_default(self): | ||
| """Test frontend display shows only front-panel namespace ports.""" | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["flap"], | ||
| ["-d", "frontend"]) | ||
| assert result.exit_code == 0 | ||
| assert result.output == intf_flap_masic_expected_output_default | ||
|
|
||
| def test_show_interfaces_flap_masic_display_all(self): | ||
| """Test -d all shows all namespaces including backplane ports.""" | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["flap"], | ||
| ["-d", "all"]) | ||
| assert result.exit_code == 0 | ||
| assert result.output == intf_flap_masic_expected_output_display_all | ||
|
|
||
| def test_show_interfaces_flap_masic_ethernet0(self): | ||
| """Test specific port lookup on asic0 returns correct flap data.""" | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["flap"], | ||
| ["Ethernet0"]) | ||
| assert result.exit_code == 0 | ||
| assert result.output == intf_flap_masic_expected_output_ethernet0 | ||
|
|
||
| def test_show_interfaces_flap_masic_ethernet64(self): | ||
| """Test specific port lookup on asic1 returns correct flap data.""" | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["flap"], | ||
| ["Ethernet64"]) | ||
| assert result.exit_code == 0 | ||
| assert result.output == intf_flap_masic_expected_output_ethernet64 | ||
|
|
||
| def test_show_interfaces_flap_masic_invalid_interface(self): | ||
| """Test invalid interface name fails.""" | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["flap"], | ||
| ["Ethernet100"]) | ||
| assert result.exit_code != 0 | ||
| assert "Invalid interface name" in result.output | ||
|
|
||
| @classmethod | ||
| def teardown_class(cls): | ||
| print("TEARDOWN") | ||
| os.environ['UTILITIES_UNIT_TESTING'] = "0" | ||
| from .mock_tables import mock_single_asic | ||
| importlib.reload(mock_single_asic) | ||
| from .mock_tables import dbconnector | ||
| dbconnector.load_database_config() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.