Skip to content

Commit d414970

Browse files
authored
[unit test][CLI][pfcwd] Added pfcwd config tests for single and multi ASIC platform. (#1248)
* Update Db object to include multi ASIC db clients. * Updated pfcwd CLI commands to use decorator to pass Db object.
1 parent 2b4a58c commit d414970

File tree

5 files changed

+441
-31
lines changed

5 files changed

+441
-31
lines changed

pfcwd/main.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import click
55

6+
import utilities_common.cli as clicommon
7+
68
from natsort import natsorted
79
from sonic_py_common.multi_asic import get_external_ports
810
from tabulate import tabulate
@@ -98,10 +100,14 @@ def get_server_facing_ports(db):
98100

99101

100102
class PfcwdCli(object):
101-
def __init__(self, namespace=None, display=constants.DISPLAY_ALL):
103+
def __init__(
104+
self, db=None, namespace=None, display=constants.DISPLAY_ALL
105+
):
102106
self.db = None
103107
self.config_db = None
104-
self.multi_asic = multi_asic_util.MultiAsic(display, namespace)
108+
self.multi_asic = multi_asic_util.MultiAsic(
109+
display, namespace, db
110+
)
105111
self.table = []
106112
self.all_ports = []
107113

@@ -397,6 +403,7 @@ def big_red_switch(self, big_red_switch):
397403
pfcwd_info
398404
)
399405

406+
400407
# Show stats
401408
class Show(object):
402409
# Show commands
@@ -408,19 +415,21 @@ def show():
408415
@multi_asic_util.multi_asic_click_options
409416
@click.option('-e', '--empty', is_flag=True)
410417
@click.argument('queues', nargs=-1)
411-
def stats(namespace, display, empty, queues):
418+
@clicommon.pass_db
419+
def stats(db, namespace, display, empty, queues):
412420
""" Show PFC Watchdog stats per queue """
413421
if (len(queues)):
414422
display = constants.DISPLAY_ALL
415-
PfcwdCli(namespace, display).show_stats(empty, queues)
423+
PfcwdCli(db, namespace, display).show_stats(empty, queues)
416424

417425
# Show config
418426
@show.command()
419427
@multi_asic_util.multi_asic_click_options
420428
@click.argument('ports', nargs=-1)
421-
def config(namespace, display, ports):
429+
@clicommon.pass_db
430+
def config(db, namespace, display, ports):
422431
""" Show PFC Watchdog configuration """
423-
PfcwdCli(namespace, display).config(ports)
432+
PfcwdCli(db, namespace, display).config(ports)
424433

425434

426435
# Start WD
@@ -432,7 +441,8 @@ class Start(object):
432441
@click.option('--restoration-time', '-r', type=click.IntRange(100, 60000))
433442
@click.argument('ports', nargs=-1)
434443
@click.argument('detection-time', type=click.IntRange(100, 5000))
435-
def start(action, restoration_time, ports, detection_time):
444+
@clicommon.pass_db
445+
def start(db, action, restoration_time, ports, detection_time):
436446
"""
437447
Start PFC watchdog on port(s). To config all ports, use all as input.
438448
@@ -441,51 +451,58 @@ def start(action, restoration_time, ports, detection_time):
441451
sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400
442452
443453
"""
444-
PfcwdCli().start(action, restoration_time, ports, detection_time)
454+
PfcwdCli(db).start(
455+
action, restoration_time, ports, detection_time
456+
)
445457

446458

447459
# Set WD poll interval
448460
class Interval(object):
449461
@cli.command()
450462
@click.argument('poll_interval', type=click.IntRange(100, 3000))
451-
def interval(poll_interval):
463+
@clicommon.pass_db
464+
def interval(db, poll_interval):
452465
""" Set PFC watchdog counter polling interval """
453-
PfcwdCli().interval(poll_interval)
466+
PfcwdCli(db).interval(poll_interval)
454467

455468

456469
# Stop WD
457470
class Stop(object):
458471
@cli.command()
459472
@click.argument('ports', nargs=-1)
460-
def stop(ports):
473+
@clicommon.pass_db
474+
def stop(db, ports):
461475
""" Stop PFC watchdog on port(s) """
462-
PfcwdCli().stop(ports)
476+
PfcwdCli(db).stop(ports)
463477

464478

465479
# Set WD default configuration on server facing ports when enable flag is on
466480
class StartDefault(object):
467481
@cli.command("start_default")
468-
def start_default():
482+
@clicommon.pass_db
483+
def start_default(db):
469484
""" Start PFC WD by default configurations """
470-
PfcwdCli().start_default()
485+
PfcwdCli(db).start_default()
471486

472487

473488
# Enable/disable PFC WD counter polling
474489
class CounterPoll(object):
475490
@cli.command('counter_poll')
476491
@click.argument('counter_poll', type=click.Choice(['enable', 'disable']))
477-
def counter_poll(counter_poll):
492+
@clicommon.pass_db
493+
def counter_poll(db, counter_poll):
478494
""" Enable/disable counter polling """
479-
PfcwdCli().counter_poll(counter_poll)
495+
PfcwdCli(db).counter_poll(counter_poll)
480496

481497

482498
# Enable/disable PFC WD BIG_RED_SWITCH mode
483499
class BigRedSwitch(object):
484500
@cli.command('big_red_switch')
485501
@click.argument('big_red_switch', type=click.Choice(['enable', 'disable']))
486-
def big_red_switch(big_red_switch):
502+
@clicommon.pass_db
503+
def big_red_switch(db, big_red_switch):
487504
""" Enable/disable BIG_RED_SWITCH mode """
488-
PfcwdCli().big_red_switch(big_red_switch)
505+
PfcwdCli(db).big_red_switch(big_red_switch)
489506

490507

491508
def get_pfcwd_clis():

tests/pfcwd_input/pfcwd_test_vectors.py

+106
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,47 @@
77
Ethernet8 drop 600 600
88
"""
99

10+
pfcwd_show_start_config_output_pass = """\
11+
Changed polling interval to 600ms
12+
PORT ACTION DETECTION TIME RESTORATION TIME
13+
--------- -------- ---------------- ------------------
14+
Ethernet0 forward 102 101
15+
Ethernet4 drop 600 600
16+
Ethernet8 drop 600 600
17+
"""
18+
19+
pfcwd_show_start_action_forward_output = """\
20+
Changed polling interval to 600ms
21+
PORT ACTION DETECTION TIME RESTORATION TIME
22+
--------- -------- ---------------- ------------------
23+
Ethernet0 forward 302 301
24+
Ethernet4 forward 302 301
25+
Ethernet8 forward 302 301
26+
"""
27+
28+
pfcwd_show_start_action_alert_output = """\
29+
Changed polling interval to 600ms
30+
PORT ACTION DETECTION TIME RESTORATION TIME
31+
--------- -------- ---------------- ------------------
32+
Ethernet0 alert 502 501
33+
Ethernet4 alert 502 501
34+
Ethernet8 alert 502 501
35+
"""
36+
37+
pfcwd_show_start_action_drop_output = """\
38+
Changed polling interval to 600ms
39+
PORT ACTION DETECTION TIME RESTORATION TIME
40+
--------- -------- ---------------- ------------------
41+
Ethernet0 drop 602 601
42+
Ethernet4 drop 602 601
43+
Ethernet8 drop 602 601
44+
"""
45+
46+
pfcwd_show_start_config_output_fail = """\
47+
Failed to run command, invalid options:
48+
Ethernet1000
49+
"""
50+
1051
pfcwd_show_config_single_port_output="""\
1152
Changed polling interval to 600ms
1253
PORT ACTION DETECTION TIME RESTORATION TIME
@@ -222,6 +263,71 @@
222263
Ethernet-BP260 drop 200 200
223264
"""
224265

266+
show_pfc_config_start_pass = """\
267+
Changed polling interval to 199ms on asic0
268+
BIG_RED_SWITCH status is enable on asic0
269+
Changed polling interval to 199ms on asic1
270+
BIG_RED_SWITCH status is enable on asic1
271+
PORT ACTION DETECTION TIME RESTORATION TIME
272+
-------------- -------- ---------------- ------------------
273+
Ethernet0 forward 102 101
274+
Ethernet4 drop 200 200
275+
Ethernet-BP0 drop 200 200
276+
Ethernet-BP4 forward 102 101
277+
Ethernet-BP256 drop 200 200
278+
Ethernet-BP260 drop 200 200
279+
"""
280+
281+
show_pfc_config_start_action_drop_masic = """\
282+
Changed polling interval to 199ms on asic0
283+
BIG_RED_SWITCH status is enable on asic0
284+
Changed polling interval to 199ms on asic1
285+
BIG_RED_SWITCH status is enable on asic1
286+
PORT ACTION DETECTION TIME RESTORATION TIME
287+
-------------- -------- ---------------- ------------------
288+
Ethernet0 drop 302 301
289+
Ethernet4 drop 302 301
290+
Ethernet-BP0 drop 302 301
291+
Ethernet-BP4 drop 302 301
292+
Ethernet-BP256 drop 302 301
293+
Ethernet-BP260 drop 302 301
294+
"""
295+
296+
show_pfc_config_start_action_alert_masic = """\
297+
Changed polling interval to 199ms on asic0
298+
BIG_RED_SWITCH status is enable on asic0
299+
Changed polling interval to 199ms on asic1
300+
BIG_RED_SWITCH status is enable on asic1
301+
PORT ACTION DETECTION TIME RESTORATION TIME
302+
-------------- -------- ---------------- ------------------
303+
Ethernet0 alert 402 401
304+
Ethernet4 alert 402 401
305+
Ethernet-BP0 alert 402 401
306+
Ethernet-BP4 alert 402 401
307+
Ethernet-BP256 alert 402 401
308+
Ethernet-BP260 alert 402 401
309+
"""
310+
311+
show_pfc_config_start_action_forward_masic = """\
312+
Changed polling interval to 199ms on asic0
313+
BIG_RED_SWITCH status is enable on asic0
314+
Changed polling interval to 199ms on asic1
315+
BIG_RED_SWITCH status is enable on asic1
316+
PORT ACTION DETECTION TIME RESTORATION TIME
317+
-------------- -------- ---------------- ------------------
318+
Ethernet0 forward 702 701
319+
Ethernet4 forward 702 701
320+
Ethernet-BP0 forward 702 701
321+
Ethernet-BP4 forward 702 701
322+
Ethernet-BP256 forward 702 701
323+
Ethernet-BP260 forward 702 701
324+
"""
325+
326+
show_pfc_config_start_fail = """\
327+
Failed to run command, invalid options:
328+
Ethernet-500
329+
"""
330+
225331
show_pfcwd_stats_with_queues = """\
226332
QUEUE STATUS STORM DETECTED/RESTORED TX OK/DROP RX OK/DROP TX LAST OK/DROP RX LAST OK/DROP
227333
----------------- -------- ------------------------- ------------ ------------ ----------------- -----------------

0 commit comments

Comments
 (0)