-
Notifications
You must be signed in to change notification settings - Fork 661
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
[show] fix "show interfaces breakout" command #1198
Merged
qiluo-msft
merged 2 commits into
sonic-net:master
from
dmytroxshevchuk:fix_breakout_show
Jan 27, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 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
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
import json | ||
import os | ||
|
||
import click | ||
import utilities_common.cli as clicommon | ||
import utilities_common.multi_asic as multi_asic_util | ||
from natsort import natsorted | ||
from tabulate import tabulate | ||
from sonic_py_common import multi_asic | ||
from sonic_py_common import device_info | ||
from swsssdk import ConfigDBConnector | ||
from portconfig import get_child_ports | ||
|
||
from . import portchannel | ||
from collections import OrderedDict | ||
|
||
HWSKU_JSON = 'hwsku.json' | ||
|
||
# Read given JSON file | ||
def readJsonFile(fileName): | ||
try: | ||
with open(fileName) as f: | ||
result = json.load(f) | ||
except Exception as e: | ||
click.echo(str(e)) | ||
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.
echo to stderr #Closed |
||
raise click.Abort() | ||
return result | ||
|
||
def try_convert_interfacename_from_alias(ctx, interfacename): | ||
"""try to convert interface name from alias""" | ||
|
@@ -144,13 +161,14 @@ def breakout(ctx): | |
|
||
if ctx.invoked_subcommand is None: | ||
# Get port capability from platform and hwsku related files | ||
platform_path, hwsku_path = device_info.get_paths_to_platform_and_hwsku_dirs() | ||
platform_file = os.path.join(platform_path, PLATFORM_JSON) | ||
hwsku_path = device_info.get_path_to_hwsku_dir() | ||
platform_file = device_info.get_path_to_port_config_file() | ||
platform_dict = readJsonFile(platform_file)['interfaces'] | ||
hwsku_dict = readJsonFile(os.path.join(hwsku_path, HWSKU_JSON))['interfaces'] | ||
hwsku_file = os.path.join(hwsku_path, HWSKU_JSON) | ||
hwsku_dict = readJsonFile(hwsku_file)['interfaces'] | ||
|
||
if not platform_dict or not hwsku_dict: | ||
click.echo("Can not load port config from {} or {} file".format(PLATFORM_JSON, HWSKU_JSON)) | ||
click.echo("Can not load port config from {} or {} file".format(platform_file, hwsku_file)) | ||
raise click.Abort() | ||
|
||
for port_name in platform_dict: | ||
|
@@ -161,9 +179,9 @@ def breakout(ctx): | |
platform_dict[port_name]["Current Breakout Mode"] = cur_brkout_mode | ||
|
||
# List all the child ports if present | ||
child_port_dict = get_child_ports(port_name, cur_brkout_mode, platformFile) | ||
child_port_dict = get_child_ports(port_name, cur_brkout_mode, platform_file) | ||
if not child_port_dict: | ||
click.echo("Cannot find ports from {} file ".format(PLATFORM_JSON)) | ||
click.echo("Cannot find ports from {} file ".format(platform_file)) | ||
raise click.Abort() | ||
|
||
child_ports = natsorted(list(child_port_dict.keys())) | ||
|
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.
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 catch the specific type/types? such as file exception, json format exceptions, etc? #Closed