Skip to content

Commit 8dab09b

Browse files
committed
[config][muxcable] add support to enable/disable ycable telemetry (sonic-net#2297)
This PR provides a capability to sonic-utilities CLI to enable/disable telemetry for ycabled. Basically there is a periodic loop for ycabled which posts telemetry data for that configured interval of time(currently 60 sec). This PR diables this data posting, and does not call platform API calls for ycable. This PR is required for the initiative of getting some failover/switchover not get interfered because of sonic-telemetry API calls. The CLI for enabling/disabling telemetry is config muxcable telemetry enable/disable What I did How I did it How to verify it Previous command output (if the output of a command-line utility has changed) New command output (if the output of a command-line utility has changed) Dependent on sonic-net/sonic-platform-daemons#279 and submodule update Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent 6da339c commit 8dab09b

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

config/muxcable.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,3 +1190,46 @@ def set_fec(db, port, target, mode):
11901190
else:
11911191
click.echo("ERR: Unable to set fec enable/disable port {} to {}".format(port, mode))
11921192
sys.exit(CONFIG_FAIL)
1193+
1194+
def update_configdb_ycable_telemetry_data(config_db, key, val):
1195+
log_verbosity = get_value_for_key_in_config_tbl(config_db, key, "log_verbosity", "XCVRD_LOG")
1196+
1197+
config_db.set_entry("XCVRD_LOG", key, {"log_verbosity": log_verbosity,
1198+
"disable_telemetry": val})
1199+
return 0
1200+
1201+
@muxcable.command()
1202+
@click.argument('state', metavar='<enable/disable telemetry>', required=True, type=click.Choice(["enable", "disable"]))
1203+
@clicommon.pass_db
1204+
def telemetry(db, state):
1205+
"""Enable/Disable Telemetry for ycabled """
1206+
1207+
per_npu_configdb = {}
1208+
xcvrd_log_cfg_db_tbl = {}
1209+
1210+
if state == 'enable':
1211+
val = 'False'
1212+
elif state == 'disable':
1213+
val = 'True'
1214+
1215+
1216+
# Getting all front asic namespace and correspding config and state DB connector
1217+
1218+
namespaces = multi_asic.get_front_end_namespaces()
1219+
for namespace in namespaces:
1220+
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
1221+
# replace these with correct macros
1222+
per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
1223+
per_npu_configdb[asic_id].connect()
1224+
1225+
xcvrd_log_cfg_db_tbl[asic_id] = per_npu_configdb[asic_id].get_table("XCVRD_LOG")
1226+
1227+
asic_index = multi_asic.get_asic_index_from_namespace(EMPTY_NAMESPACE)
1228+
rc = update_configdb_ycable_telemetry_data(per_npu_configdb[asic_index], "Y_CABLE", val)
1229+
1230+
1231+
if rc == 0:
1232+
click.echo("Success in ycabled telemetry state to {}".format(state))
1233+
else:
1234+
click.echo("ERR: Unable to set ycabled telemetry state to {}".format(state))
1235+
sys.exit(CONFIG_FAIL)

tests/muxcable_test.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,94 @@ def test_show_muxcable_packetloss_port_json(self):
20952095
assert result.exit_code == 0
20962096
assert result.output == show_muxcable_packetloss_expected_output_json
20972097

2098+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2099+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2100+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2101+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2102+
def test_show_muxcable_tunnel_route(self):
2103+
runner = CliRunner()
2104+
db = Db()
2105+
2106+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"], obj=db)
2107+
2108+
assert result.exit_code == 0
2109+
assert result.output == show_muxcable_tunnel_route_expected_output
2110+
2111+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2112+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2113+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2114+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2115+
def test_show_muxcable_tunnel_route_json(self):
2116+
runner = CliRunner()
2117+
db = Db()
2118+
2119+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2120+
["--json"], obj=db)
2121+
2122+
assert result.exit_code == 0
2123+
assert result.output == show_muxcable_tunnel_route_expected_output_json
2124+
2125+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2126+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2127+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2128+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2129+
def test_show_muxcable_tunnel_route_port(self):
2130+
runner = CliRunner()
2131+
db = Db()
2132+
2133+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2134+
["Ethernet0"], obj=db)
2135+
2136+
assert result.exit_code == 0
2137+
assert result.output == show_muxcable_tunnel_route_expected_port_output
2138+
2139+
@mock.patch('utilities_common.platform_sfputil_helper.get_logical_list', mock.MagicMock(return_value=["Ethernet0", "Ethernet12"]))
2140+
@mock.patch('utilities_common.platform_sfputil_helper.get_asic_id_for_logical_port', mock.MagicMock(return_value=0))
2141+
@mock.patch('show.muxcable.platform_sfputil', mock.MagicMock(return_value={0: ["Ethernet12", "Ethernet0"]}))
2142+
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
2143+
def test_show_muxcable_tunnel_route_json_port(self):
2144+
runner = CliRunner()
2145+
db = Db()
2146+
2147+
result = runner.invoke(show.cli.commands["muxcable"].commands["tunnel-route"],
2148+
["Ethernet0", "--json"], obj=db)
2149+
assert result.exit_code == 0
2150+
assert result.output == show_muxcable_tunnel_route_expected_output_port_json
2151+
2152+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2153+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2154+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2155+
def test_config_muxcable_telemetry_enable_without_patch(self):
2156+
runner = CliRunner()
2157+
db = Db()
2158+
2159+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2160+
"enable"], obj=db)
2161+
assert result.exit_code == 1
2162+
2163+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2164+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2165+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2166+
def test_config_muxcable_telemetry_disable_without_patch(self):
2167+
runner = CliRunner()
2168+
db = Db()
2169+
2170+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2171+
"disable"], obj=db)
2172+
assert result.exit_code == 1
2173+
2174+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2175+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2176+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2177+
@mock.patch('config.muxcable.update_configdb_ycable_telemetry_data', mock.MagicMock(return_value=0))
2178+
def test_config_muxcable_telemetry_enable(self):
2179+
runner = CliRunner()
2180+
db = Db()
2181+
2182+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2183+
"enable"], obj=db)
2184+
assert result.exit_code == 0
2185+
20982186
@classmethod
20992187
def teardown_class(cls):
21002188
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)