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

[show] fix "show interfaces breakout" command #1198

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Changes from 1 commit
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
30 changes: 24 additions & 6 deletions show/interfaces/__init__.py
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:
Copy link
Contributor

@qiluo-msft qiluo-msft Jan 21, 2021

Choose a reason for hiding this comment

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

Exception [](start = 11, length = 9)

Could you catch the specific type/types? such as file exception, json format exceptions, etc? #Closed

click.echo(str(e))
Copy link
Contributor

@qiluo-msft qiluo-msft Jan 21, 2021

Choose a reason for hiding this comment

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

echo [](start = 14, length = 4)

echo to stderr #Closed

raise click.Abort()
return result

def try_convert_interfacename_from_alias(ctx, interfacename):
"""try to convert interface name from alias"""
Expand Down Expand Up @@ -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:
Expand All @@ -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()))
Expand Down