Skip to content

Commit

Permalink
[console] Include Flow Control status in show line result (sonic-net#…
Browse files Browse the repository at this point in the history
…1549)

- Render the flow control option in show line table
- Update unit test case
- Update document

Signed-off-by: Jing Kan jika@microsoft.com
  • Loading branch information
Blueve committed Apr 7, 2021
1 parent b1097b2 commit 5976399
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
5 changes: 3 additions & 2 deletions consutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ def show(db, brief):
ports.sort(key=lambda p: int(p.line_num))

# set table header style
header = ["Line", "Baud", "PID", "Start Time", "Device"]
header = ["Line", "Baud", "Flow Control", "PID", "Start Time", "Device"]
body = []
for port in ports:
# runtime information
busy = "*" if port.busy else " "
pid = port.session_pid if port.session_pid else "-"
date = port.session_start_date if port.session_start_date else "-"
baud = port.baud
body.append([busy+port.line_num, baud if baud else "-", pid if pid else "-", date if date else "-", port.remote_device])
flow_control = "Enabled" if port.flow_control else "Disabled"
body.append([busy+port.line_num, baud if baud else "-", flow_control, pid if pid else "-", date if date else "-", port.remote_device])
click.echo(tabulate(body, header, stralign='right'))

# 'clear' subcommand
Expand Down
20 changes: 10 additions & 10 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1993,23 +1993,23 @@ This command displays serial port or a virtual network connection status.
- Example:
```
admin@sonic:~$ show line
Line Baud PID Start Time Device
------ ------ ----- ------------ --------
0 - - -
1 9600 - - switch1
2 - - -
3 - - -
4 - - -
Line Baud Flow Control PID Start Time Device
------ ------ -------------- ----- ------------ --------
1 9600 Enabled - - switch1
2 - Disabled - -
3 - Disabled - -
4 - Disabled - -
5 - Disabled - -
```

Optionally, you can display configured console ports only by specifying the `-b` or `--breif` flag.

- Example:
```
admin@sonic:~$ show line -b
Line Baud PID Start Time Device
------ ------ ----- ------------ --------
1 9600 - - switch1
Line Baud Flow Control PID Start Time Device
------ ------ -------------- ----- ------------ --------
1 9600 Enabled - - switch1
```

## Console config commands
Expand Down
12 changes: 6 additions & 6 deletions tests/console_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,19 @@ def setup_class(cls):
print("SETUP")

expect_show_output = ''+ \
""" Line Baud PID Start Time Device
------ ------ ----- ------------------------ --------
1 9600 - - switch1
*2 9600 223 Wed Mar 6 08:31:35 2019 switch2
3 9600 - -
""" Line Baud Flow Control PID Start Time Device
------ ------ -------------- ----- ------------------------ --------
1 9600 Disabled - - switch1
*2 9600 Disabled 223 Wed Mar 6 08:31:35 2019 switch2
3 9600 Enabled - -
"""
@mock.patch('consutil.lib.SysInfoProvider.init_device_prefix', mock.MagicMock(return_value=None))
def test_show(self):
runner = CliRunner()
db = Db()
db.cfgdb.set_entry("CONSOLE_PORT", 1, { "remote_device" : "switch1", "baud_rate" : "9600" })
db.cfgdb.set_entry("CONSOLE_PORT", 2, { "remote_device" : "switch2", "baud_rate" : "9600" })
db.cfgdb.set_entry("CONSOLE_PORT", 3, { "baud_rate" : "9600" })
db.cfgdb.set_entry("CONSOLE_PORT", 3, { "baud_rate" : "9600", "flow_control" : "1" })

db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "state", "busy")
db.db.set(db.db.STATE_DB, "CONSOLE_PORT|2", "pid", "223")
Expand Down

0 comments on commit 5976399

Please sign in to comment.