Skip to content

Commit 5739cd9

Browse files
authored
[show][config] fix for show/config muxcable hwmode model value; fix show/config muxcable return codes; (sonic-net#1494)
his PR fixes the show mux hwmode muxdirection config mux hwmode state cli commands to correctly use the model values for matching the vendor model value present in TRANSCEIVER_INFO table in state DB. This PR also supports the fix for return codes for show mux config mux commands to return 0 if the command executes correctly. What I did fix for show/config muxcable hwmode model value; fix show/config muxcable return codes; Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent 4a5bd47 commit 5739cd9

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

config/muxcable.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44

55
import click
6+
import re
67
import utilities_common.cli as clicommon
78
from sonic_py_common import multi_asic
89
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector
@@ -13,11 +14,11 @@
1314

1415
REDIS_TIMEOUT_MSECS = 0
1516

16-
CONFIG_SUCCESSFUL = 100
17+
CONFIG_SUCCESSFUL = 0
1718
CONFIG_FAIL = 1
1819

1920
VENDOR_NAME = "Credo"
20-
VENDOR_MODEL = "CAC125321P2PA0MS"
21+
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")
2122

2223
# Helper functions
2324

@@ -333,7 +334,7 @@ def state(state, port):
333334
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
334335
TODO: this should be removed once their is support for multiple vendors on Y cable"""
335336

336-
if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
337+
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
337338
click.echo("ERR: Got invalid vendor value and model for port {}".format(port))
338339
sys.exit(CONFIG_FAIL)
339340

@@ -419,7 +420,7 @@ def state(state, port):
419420
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
420421
TODO: this should be removed once their is support for multiple vendors on Y cable"""
421422

422-
if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
423+
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
423424
continue
424425

425426
physical_port = physical_port_list[0]

show/muxcable.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44

55
import click
6+
import re
67
import utilities_common.cli as clicommon
78
from natsort import natsorted
89
from sonic_py_common import multi_asic
@@ -14,15 +15,15 @@
1415

1516
REDIS_TIMEOUT_MSECS = 0
1617

17-
CONFIG_SUCCESSFUL = 101
18+
CONFIG_SUCCESSFUL = 0
1819
CONFIG_FAIL = 1
1920
EXIT_FAIL = 1
2021
EXIT_SUCCESS = 0
2122
STATUS_FAIL = 1
22-
STATUS_SUCCESSFUL = 102
23+
STATUS_SUCCESSFUL = 0
2324

2425
VENDOR_NAME = "Credo"
25-
VENDOR_MODEL = "CAC125321P2PA0MS"
26+
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")
2627

2728

2829
#
@@ -489,7 +490,7 @@ def muxdirection(port):
489490
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
490491
TODO: this should be removed once their is support for multiple vendors on Y cable"""
491492

492-
if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
493+
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
493494
click.echo("ERR: Got invalid vendor value and model for port {}".format(port))
494495
sys.exit(EXIT_FAIL)
495496

@@ -585,7 +586,7 @@ def muxdirection(port):
585586
or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
586587
TODO: this should be removed once their is support for multiple vendors on Y cable"""
587588

588-
if vendor_value != VENDOR_NAME or model_value != VENDOR_MODEL:
589+
if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value):
589590
continue
590591

591592
physical_port = physical_port_list[0]

tests/mock_tables/state_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"hardware_rev": "AC",
2323
"serial": "MT1706FT02064",
2424
"manufacturer": "Credo",
25-
"model": "CAC125321P2PA0MS",
25+
"model": "CACL1X321P2PA1MS",
2626
"vendor_oui": "00-02-c9",
2727
"vendor_date": "2017-01-13 ",
2828
"connector": "No separable connector",

tests/muxcable_test.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_muxcable_status(self):
188188
db = Db()
189189
result = runner.invoke(show.cli.commands["muxcable"].commands["status"], obj=db)
190190

191-
assert result.exit_code == 102
191+
assert result.exit_code == 0
192192
assert result.output == tabular_data_status_output_expected
193193

194194
def test_muxcable_status_json(self):
@@ -197,7 +197,7 @@ def test_muxcable_status_json(self):
197197

198198
result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["--json"], obj=db)
199199

200-
assert result.exit_code == 102
200+
assert result.exit_code == 0
201201
assert result.output == json_data_status_output_expected
202202

203203
def test_muxcable_status_config(self):
@@ -206,7 +206,7 @@ def test_muxcable_status_config(self):
206206

207207
result = runner.invoke(show.cli.commands["muxcable"].commands["config"], obj=db)
208208

209-
assert result.exit_code == 101
209+
assert result.exit_code == 0
210210
assert result.output == tabular_data_config_output_expected
211211

212212
def test_muxcable_status_config_json(self):
@@ -215,7 +215,7 @@ def test_muxcable_status_config_json(self):
215215

216216
result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["--json"], obj=db)
217217

218-
assert result.exit_code == 101
218+
assert result.exit_code == 0
219219
assert result.output == json_data_status_config_output_expected
220220

221221
def test_muxcable_config_json_with_incorrect_port(self):
@@ -233,7 +233,7 @@ def test_muxcable_status_json_with_correct_port(self):
233233
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
234234
result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet0", "--json"], obj=db)
235235

236-
assert result.exit_code == 102
236+
assert result.exit_code == 0
237237

238238
def test_muxcable_status_json_port_incorrect_index(self):
239239
runner = CliRunner()
@@ -266,7 +266,7 @@ def test_muxcable_config_with_correct_port(self):
266266
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
267267
result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0"], obj=db)
268268

269-
assert result.exit_code == 101
269+
assert result.exit_code == 0
270270

271271
def test_muxcable_config_json_with_correct_port(self):
272272
runner = CliRunner()
@@ -275,7 +275,7 @@ def test_muxcable_config_json_with_correct_port(self):
275275
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
276276
result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0", "--json"], obj=db)
277277

278-
assert result.exit_code == 101
278+
assert result.exit_code == 0
279279

280280
def test_muxcable_config_json_port_with_incorrect_index(self):
281281
runner = CliRunner()
@@ -284,7 +284,7 @@ def test_muxcable_config_json_port_with_incorrect_index(self):
284284
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 1
285285
result = runner.invoke(show.cli.commands["muxcable"].commands["config"], ["Ethernet0", "--json"], obj=db)
286286

287-
assert result.exit_code == 101
287+
assert result.exit_code == 0
288288

289289
def test_muxcable_config_json_with_incorrect_port_patch(self):
290290
runner = CliRunner()
@@ -302,7 +302,7 @@ def test_muxcable_status_json_port_eth0(self):
302302
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
303303
result = runner.invoke(show.cli.commands["muxcable"].commands["status"], ["Ethernet0"], obj=db)
304304

305-
assert result.exit_code == 102
305+
assert result.exit_code == 0
306306

307307
def test_config_muxcable_tabular_port_Ethernet8_active(self):
308308
runner = CliRunner()
@@ -312,7 +312,7 @@ def test_config_muxcable_tabular_port_Ethernet8_active(self):
312312
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
313313
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet8"], obj=db)
314314

315-
assert result.exit_code == 100
315+
assert result.exit_code == 0
316316

317317
def test_config_muxcable_tabular_port_Ethernet8_auto(self):
318318
runner = CliRunner()
@@ -322,15 +322,15 @@ def test_config_muxcable_tabular_port_Ethernet8_auto(self):
322322
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
323323
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "Ethernet8"], obj=db)
324324

325-
assert result.exit_code == 100
325+
assert result.exit_code == 0
326326

327327
def test_config_muxcable_mode_auto_json(self):
328328
runner = CliRunner()
329329
db = Db()
330330

331331
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "all", "--json"], obj=db)
332332

333-
assert result.exit_code == 100
333+
assert result.exit_code == 0
334334
assert result.output == json_data_config_output_auto_expected
335335

336336
def test_config_muxcable_mode_active_json(self):
@@ -341,7 +341,7 @@ def test_config_muxcable_mode_active_json(self):
341341
f = open("newfile1", "w")
342342
f.write(result.output)
343343

344-
assert result.exit_code == 100
344+
assert result.exit_code == 0
345345
assert result.output == json_data_config_output_active_expected
346346

347347
def test_config_muxcable_json_port_auto_Ethernet0(self):
@@ -353,7 +353,7 @@ def test_config_muxcable_json_port_auto_Ethernet0(self):
353353
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [
354354
"auto", "Ethernet0", "--json"], obj=db)
355355

356-
assert result.exit_code == 100
356+
assert result.exit_code == 0
357357

358358
def test_config_muxcable_json_port_active_Ethernet0(self):
359359
runner = CliRunner()
@@ -364,13 +364,13 @@ def test_config_muxcable_json_port_active_Ethernet0(self):
364364
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], [
365365
"active", "Ethernet0", "--json"], obj=db)
366366

367-
assert result.exit_code == 100
367+
assert result.exit_code == 0
368368

369369
def test_config_muxcable_mode_auto_tabular(self):
370370
runner = CliRunner()
371371
db = Db()
372372
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "all"], obj=db)
373-
assert result.exit_code == 100
373+
assert result.exit_code == 0
374374

375375
def test_config_muxcable_mode_active_tabular(self):
376376
runner = CliRunner()
@@ -380,7 +380,7 @@ def test_config_muxcable_mode_active_tabular(self):
380380
f = open("newfile", "w")
381381
f.write(result.output)
382382

383-
assert result.exit_code == 100
383+
assert result.exit_code == 0
384384

385385
def test_config_muxcable_tabular_port(self):
386386
runner = CliRunner()
@@ -390,7 +390,7 @@ def test_config_muxcable_tabular_port(self):
390390
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
391391
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet0"], obj=db)
392392

393-
assert result.exit_code == 100
393+
assert result.exit_code == 0
394394

395395
def test_config_muxcable_tabular_port_Ethernet4_active(self):
396396
runner = CliRunner()
@@ -400,7 +400,7 @@ def test_config_muxcable_tabular_port_Ethernet4_active(self):
400400
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
401401
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["active", "Ethernet4"], obj=db)
402402

403-
assert result.exit_code == 100
403+
assert result.exit_code == 0
404404

405405
def test_config_muxcable_tabular_port_Ethernet4_auto(self):
406406
runner = CliRunner()
@@ -410,7 +410,7 @@ def test_config_muxcable_tabular_port_Ethernet4_auto(self):
410410
patched_util.SfpUtilHelper.return_value.get_asic_id_for_logical_port.return_value = 0
411411
result = runner.invoke(config.config.commands["muxcable"].commands["mode"], ["auto", "Ethernet4"], obj=db)
412412

413-
assert result.exit_code == 100
413+
assert result.exit_code == 0
414414

415415
def test_config_muxcable_tabular_port_with_incorrect_index(self):
416416
runner = CliRunner()
@@ -475,7 +475,7 @@ def test_config_muxcable_enable_prbs(self):
475475
result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["enable"],
476476
["0", "0", "0", "0"], obj=db)
477477

478-
assert result.exit_code == 100
478+
assert result.exit_code == 0
479479

480480
@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
481481
@mock.patch('sonic_y_cable.y_cable.enable_loopback_mode', mock.MagicMock(return_value=1))
@@ -486,7 +486,7 @@ def test_config_muxcable_enable_loopback(self):
486486
result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["enable"],
487487
["0", "0", "0"], obj=db)
488488

489-
assert result.exit_code == 100
489+
assert result.exit_code == 0
490490

491491
@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
492492
@mock.patch('sonic_y_cable.y_cable.disable_prbs_mode', mock.MagicMock(return_value=1))
@@ -497,7 +497,7 @@ def test_config_muxcable_disble_prbs(self):
497497
result = runner.invoke(config.config.commands["muxcable"].commands["prbs"].commands["disable"],
498498
["0", "0"], obj=db)
499499

500-
assert result.exit_code == 100
500+
assert result.exit_code == 0
501501

502502
@mock.patch('os.geteuid', mock.MagicMock(return_value=0))
503503
@mock.patch('sonic_y_cable.y_cable.disable_loopback_mode', mock.MagicMock(return_value=1))
@@ -508,7 +508,7 @@ def test_config_muxcable_disable_loopback(self):
508508
result = runner.invoke(config.config.commands["muxcable"].commands["loopback"].commands["disable"],
509509
["0", "0"], obj=db)
510510

511-
assert result.exit_code == 100
511+
assert result.exit_code == 0
512512

513513
@mock.patch('sonic_y_cable.y_cable.get_part_number', mock.MagicMock(return_value=("CACL1X321P2PA1M")))
514514
@mock.patch('sonic_y_cable.y_cable.get_vendor', mock.MagicMock(return_value=("Credo ")))
@@ -567,6 +567,7 @@ def test_show_muxcable_cableinfo_incorrect_logical_port_return_value(self):
567567
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
568568
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
569569
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(1)))
570+
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
570571
def test_show_muxcable_hwmode_muxdirection_port_active(self):
571572
runner = CliRunner()
572573
db = Db()
@@ -583,6 +584,7 @@ def test_show_muxcable_hwmode_muxdirection_port_active(self):
583584
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
584585
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
585586
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(1)))
587+
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
586588
def test_show_muxcable_hwmode_muxdirection_active(self):
587589
runner = CliRunner()
588590
db = Db()
@@ -597,6 +599,7 @@ def test_show_muxcable_hwmode_muxdirection_active(self):
597599
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
598600
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
599601
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(2)))
602+
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
600603
def test_show_muxcable_hwmode_muxdirection_port_standby(self):
601604
runner = CliRunner()
602605
db = Db()
@@ -613,6 +616,7 @@ def test_show_muxcable_hwmode_muxdirection_port_standby(self):
613616
@mock.patch('utilities_common.platform_sfputil_helper.logical_port_name_to_physical_port_list', mock.MagicMock(return_value=[0]))
614617
@mock.patch('sonic_y_cable.y_cable.check_read_side', mock.MagicMock(return_value=(1)))
615618
@mock.patch('sonic_y_cable.y_cable.check_mux_direction', mock.MagicMock(return_value=(2)))
619+
@mock.patch('re.match', mock.MagicMock(return_value=(True)))
616620
def test_show_muxcable_hwmode_muxdirection_standby(self):
617621
runner = CliRunner()
618622
db = Db()

0 commit comments

Comments
 (0)