Skip to content

Commit 441553d

Browse files
vdahiya12preetham-singh
authored andcommitted
[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 bd6b1f4 commit 441553d

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

config/muxcable.py

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

tests/muxcable_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,40 @@ def test_show_muxcable_tunnel_route_json_port(self):
22092209
assert result.exit_code == 0
22102210
assert result.output == show_muxcable_tunnel_route_expected_output_port_json
22112211

2212+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2213+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2214+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2215+
def test_config_muxcable_telemetry_enable_without_patch(self):
2216+
runner = CliRunner()
2217+
db = Db()
2218+
2219+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2220+
"enable"], obj=db)
2221+
assert result.exit_code == 1
2222+
2223+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2224+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2225+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2226+
def test_config_muxcable_telemetry_disable_without_patch(self):
2227+
runner = CliRunner()
2228+
db = Db()
2229+
2230+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2231+
"disable"], obj=db)
2232+
assert result.exit_code == 1
2233+
2234+
@mock.patch('config.muxcable.swsscommon.DBConnector', mock.MagicMock(return_value=0))
2235+
@mock.patch('config.muxcable.swsscommon.Table', mock.MagicMock(return_value=0))
2236+
@mock.patch('config.muxcable.swsscommon.Select', mock.MagicMock(return_value=0))
2237+
@mock.patch('config.muxcable.update_configdb_ycable_telemetry_data', mock.MagicMock(return_value=0))
2238+
def test_config_muxcable_telemetry_enable(self):
2239+
runner = CliRunner()
2240+
db = Db()
2241+
2242+
result = runner.invoke(config.config.commands["muxcable"].commands["telemetry"], [
2243+
"enable"], obj=db)
2244+
assert result.exit_code == 0
2245+
22122246
@classmethod
22132247
def teardown_class(cls):
22142248
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)