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

[config][muxcable] Add support for displaying soc_ipv4 and cable_type in config/show muxcable commands #2189

Merged
merged 5 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
16 changes: 13 additions & 3 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from swsscommon import swsscommon
from tabulate import tabulate
from utilities_common import platform_sfputil_helper
from utilities_common.general import get_optional_value_for_key_in_config_tbl

platform_sfputil = None

Expand Down Expand Up @@ -203,7 +204,6 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_

return res_dict


def get_value_for_key_in_config_tbl(config_db, port, key, table):
info_dict = {}
info_dict = config_db.get_entry(table, port)
Expand Down Expand Up @@ -244,6 +244,8 @@ def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, sta
configdb_state = get_value_for_key_in_config_tbl(config_db, port, "state", "MUX_CABLE")
ipv4_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv4", "MUX_CABLE")
ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE")
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(config_db, port, "soc_ipv4", "MUX_CABLE")
cable_type = get_optional_value_for_key_in_config_tbl(config_db, port, "cable_type", "MUX_CABLE")

state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE")

Expand All @@ -252,8 +254,16 @@ def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, sta
if str(state_cfg_val) == str(configdb_state):
port_status_dict[port_name] = 'OK'
else:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value, "server_ipv6": ipv6_value})
if cable_type is not None and soc_ipv4_value is not None:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value,
"server_ipv6": ipv6_value,
"soc_ipv4":soc_ipv4_value,
"cable_type": cable_type})
else:
config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val,
"server_ipv4": ipv4_value,
"server_ipv6": ipv6_value})
if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'):
port_status_dict[port_name] = 'INPROGRESS'
else:
Expand Down
34 changes: 29 additions & 5 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from swsscommon import swsscommon
from tabulate import tabulate
from utilities_common import platform_sfputil_helper
from utilities_common.general import get_optional_value_for_key_in_config_tbl

platform_sfputil = None

Expand Down Expand Up @@ -460,7 +461,7 @@ def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcab
print_data.append(print_port_data)


def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port):
def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active):

port_list = []
port_name = platform_sfputil_helper.get_interface_alias(port, db)
Expand All @@ -471,6 +472,13 @@ def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id,
port_list.append(ipv4_value)
ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE")
port_list.append(ipv6_value)
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE")
if soc_ipv4_value is not None:
port_list.append(soc_ipv4_value)
is_dualtor_active_active[0] = True
cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE")
if cable_type is not None:
port_list.append(cable_type)
print_data.append(port_list)


Expand All @@ -484,6 +492,12 @@ def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asi
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv4"] = ipv4_value
ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE")
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv6"] = ipv6_value
soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE")
if soc_ipv4_value is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv4"] = soc_ipv4_value
cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE")
if cable_type is not None:
port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["cable_type"] = cable_type


@muxcable.command()
Expand Down Expand Up @@ -688,16 +702,21 @@ def config(db, port, json_output):
else:
print_data = []
print_peer_tor = []
is_dualtor_active_active = [False]

create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port)

create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active)

headers = ['SWITCH_NAME', 'PEER_TOR']
peer_tor_data = []
peer_tor_data.append(switch_name)
peer_tor_data.append(peer_switch_value)
print_peer_tor.append(peer_tor_data)
click.echo(tabulate(print_peer_tor, headers=headers))
headers = ['port', 'state', 'ipv4', 'ipv6']
if is_dualtor_active_active[0]:
headers = ['port', 'state', 'ipv4', 'ipv6', 'soc_ipv4', 'cable_type']
else:
headers = ['port', 'state', 'ipv4', 'ipv6']
click.echo(tabulate(print_data, headers=headers))

sys.exit(CONFIG_SUCCESSFUL)
Expand Down Expand Up @@ -733,18 +752,23 @@ def config(db, port, json_output):
else:
print_data = []
print_peer_tor = []
is_dualtor_active_active = [False]

for namespace in namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
for port in natsorted(port_mux_tbl_keys[asic_id]):
create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port)
create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active)

headers = ['SWITCH_NAME', 'PEER_TOR']
peer_tor_data = []
peer_tor_data.append(switch_name)
peer_tor_data.append(peer_switch_value)
print_peer_tor.append(peer_tor_data)
click.echo(tabulate(print_peer_tor, headers=headers))
headers = ['port', 'state', 'ipv4', 'ipv6']
if is_dualtor_active_active[0]:
headers = ['port', 'state', 'ipv4', 'ipv6', 'soc_ipv4', 'cable_type']
else:
headers = ['port', 'state', 'ipv4', 'ipv6']
click.echo(tabulate(print_data, headers=headers))

sys.exit(CONFIG_SUCCESSFUL)
Expand Down
13 changes: 12 additions & 1 deletion utilities_common/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ def load_db_config():
swsscommon.SonicDBConfig.load_sonic_global_db_config()
else:
if not swsscommon.SonicDBConfig.isInit():
swsscommon.SonicDBConfig.load_sonic_db_config()
swsscommon.SonicDBConfig.load_sonic_db_config()

def get_optional_value_for_key_in_config_tbl(config_db, port, key, table):
info_dict = {}
info_dict = config_db.get_entry(table, port)
if info_dict is None:
return None

value = info_dict.get(key, None)

return value