Skip to content

Commit b324e90

Browse files
fix show breakout port
1 parent 05c8e33 commit b324e90

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

show/interfaces/__init__.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import json
2+
import os
23

34
import click
45
import utilities_common.cli as clicommon
56
import utilities_common.multi_asic as multi_asic_util
67
from natsort import natsorted
78
from tabulate import tabulate
89
from sonic_py_common import multi_asic
10+
from sonic_py_common import device_info
11+
from swsssdk import ConfigDBConnector
12+
from portconfig import get_child_ports
913

1014
from . import portchannel
15+
from collections import OrderedDict
16+
17+
HWSKU_JSON = 'hwsku.json'
18+
19+
# Read given JSON file
20+
def readJsonFile(fileName):
21+
try:
22+
with open(fileName) as f:
23+
result = json.load(f)
24+
except Exception as e:
25+
click.echo(str(e))
26+
raise click.Abort()
27+
return result
1128

1229
def try_convert_interfacename_from_alias(ctx, interfacename):
1330
"""try to convert interface name from alias"""
@@ -144,13 +161,14 @@ def breakout(ctx):
144161

145162
if ctx.invoked_subcommand is None:
146163
# Get port capability from platform and hwsku related files
147-
platform_path, hwsku_path = device_info.get_paths_to_platform_and_hwsku_dirs()
148-
platform_file = os.path.join(platform_path, PLATFORM_JSON)
164+
hwsku_path = device_info.get_path_to_hwsku_dir()
165+
platform_file = device_info.get_path_to_port_config_file()
149166
platform_dict = readJsonFile(platform_file)['interfaces']
150-
hwsku_dict = readJsonFile(os.path.join(hwsku_path, HWSKU_JSON))['interfaces']
167+
hwsku_file = os.path.join(hwsku_path, HWSKU_JSON)
168+
hwsku_dict = readJsonFile(hwsku_file)['interfaces']
151169

152170
if not platform_dict or not hwsku_dict:
153-
click.echo("Can not load port config from {} or {} file".format(PLATFORM_JSON, HWSKU_JSON))
171+
click.echo("Can not load port config from {} or {} file".format(platform_file, hwsku_file))
154172
raise click.Abort()
155173

156174
for port_name in platform_dict:
@@ -161,9 +179,9 @@ def breakout(ctx):
161179
platform_dict[port_name]["Current Breakout Mode"] = cur_brkout_mode
162180

163181
# List all the child ports if present
164-
child_port_dict = get_child_ports(port_name, cur_brkout_mode, platformFile)
182+
child_port_dict = get_child_ports(port_name, cur_brkout_mode, platform_file)
165183
if not child_port_dict:
166-
click.echo("Cannot find ports from {} file ".format(PLATFORM_JSON))
184+
click.echo("Cannot find ports from {} file ".format(platform_file))
167185
raise click.Abort()
168186

169187
child_ports = natsorted(list(child_port_dict.keys()))

0 commit comments

Comments
 (0)