Skip to content

Commit

Permalink
Fixed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Vadym Hlushko <[email protected]>
  • Loading branch information
vadymhlushko-mlnx committed Aug 16, 2021
1 parent 6358537 commit 0f60ccc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
6 changes: 2 additions & 4 deletions scripts/portstat
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ from utilities_common.intf_filter import parse_interface_in_filter
import utilities_common.multi_asic as multi_asic_util
from utilities_common.netstat import ns_diff, table_as_json, format_brate, format_prate, format_util

PORT_RATE = 40

"""
The order and count of statistics mentioned below needs to be in sync with the values in portstat script
So, any fields added/deleted in here should be reflected in portstat script also
Expand Down Expand Up @@ -215,8 +213,8 @@ class Portstat(object):
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)
speed = self.db.get(self.db.APPL_DB, full_table_id, PORT_SPEED_FIELD)
if speed is not None:
return int(speed)//1000
return PORT_RATE
return int(speed)
return STATUS_NA

def get_port_state(self, port_name):
"""
Expand Down
18 changes: 9 additions & 9 deletions tests/portstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR
--------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- --------
Ethernet0 D 8 0.00 B/s 0.00% 10 100 N/A 10 0.00 B/s 0.00% N/A N/A N/A
Ethernet4 N/A 4 200.00 KB/s 0.00% 0 1000 N/A 40 200.05 KB/s 0.00% N/A N/A N/A
Ethernet8 N/A 6 1318.36 KB/s 0.03% 100 10 N/A 60 12.75 MB/s 0.25% N/A N/A N/A
Ethernet4 N/A 4 200.00 KB/s N/A 0 1000 N/A 40 200.05 KB/s N/A N/A N/A N/A
Ethernet8 N/A 6 1318.36 KB/s N/A 100 10 N/A 60 12.75 MB/s N/A N/A N/A N/A
"""

intf_counters_ethernet4 = """\
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR
--------- ------- ------- ----------- --------- -------- -------- -------- ------- ----------- --------- -------- -------- --------
Ethernet4 N/A 4 200.00 KB/s 0.00% 0 1000 N/A 40 200.05 KB/s 0.00% N/A N/A N/A
Ethernet4 N/A 4 200.00 KB/s N/A 0 1000 N/A 40 200.05 KB/s N/A N/A N/A N/A
"""

intf_counters_all = """\
IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_PPS TX_UTIL TX_ERR TX_DRP TX_OVR
--------- ------- ------- ------------ --------- --------- -------- -------- -------- ------- ----------- --------- --------- -------- -------- --------
Ethernet0 D 8 0.00 B/s 0.00/s 0.00% 10 100 N/A 10 0.00 B/s 0.00/s 0.00% N/A N/A N/A
Ethernet4 N/A 4 200.00 KB/s 200.00/s 0.00% 0 1000 N/A 40 200.05 KB/s 201.00/s 0.00% N/A N/A N/A
Ethernet8 N/A 6 1318.36 KB/s 9000.00/s 0.03% 100 10 N/A 60 12.75 MB/s 9000.00/s 0.25% N/A N/A N/A
Ethernet4 N/A 4 200.00 KB/s 200.00/s N/A 0 1000 N/A 40 200.05 KB/s 201.00/s N/A N/A N/A N/A
Ethernet8 N/A 6 1318.36 KB/s 9000.00/s N/A 100 10 N/A 60 12.75 MB/s 9000.00/s N/A N/A N/A N/A
"""

intf_counters_period = """\
The rates are calculated within 3 seconds period
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR
--------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- --------
Ethernet0 D 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A
Ethernet4 N/A 0 200.00 KB/s 0.00% 0 0 N/A 0 200.05 KB/s 0.00% N/A N/A N/A
Ethernet8 N/A 0 1318.36 KB/s 0.03% 0 0 N/A 0 12.75 MB/s 0.25% N/A N/A N/A
Ethernet4 N/A 0 200.00 KB/s N/A 0 0 N/A 0 200.05 KB/s N/A N/A N/A N/A
Ethernet8 N/A 0 1318.36 KB/s N/A 0 0 N/A 0 12.75 MB/s N/A N/A N/A N/A
"""

intf_counter_after_clear = """\
IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR
--------- ------- ------- ------------ --------- -------- -------- -------- ------- ----------- --------- -------- -------- --------
Ethernet0 D 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A
Ethernet4 N/A 0 200.00 KB/s 0.00% 0 0 N/A 0 200.05 KB/s 0.00% N/A N/A N/A
Ethernet8 N/A 0 1318.36 KB/s 0.03% 0 0 N/A 0 12.75 MB/s 0.25% N/A N/A N/A"""
Ethernet4 N/A 0 200.00 KB/s N/A 0 0 N/A 0 200.05 KB/s N/A N/A N/A N/A
Ethernet8 N/A 0 1318.36 KB/s N/A 0 0 N/A 0 12.75 MB/s N/A N/A N/A N/A"""

clear_counter = """\
Cleared counters"""
Expand Down
4 changes: 2 additions & 2 deletions tests/rates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
IFACE STATE RX_OK RX_BPS RX_PPS RX_UTIL TX_OK TX_BPS TX_PPS TX_UTIL
--------- ------- ------- ------------ --------- --------- ------- ----------- --------- ---------
Ethernet0 D 8 0.00 B/s 0.00/s 0.00% 10 0.00 B/s 0.00/s 0.00%
Ethernet4 N/A 4 200.00 KB/s 200.00/s 0.00% 40 200.05 KB/s 201.00/s 0.00%
Ethernet8 N/A 6 1318.36 KB/s 9000.00/s 0.03% 60 12.75 MB/s 9000.00/s 0.25%
Ethernet4 N/A 4 200.00 KB/s 200.00/s N/A 40 200.05 KB/s 201.00/s N/A
Ethernet8 N/A 6 1318.36 KB/s 9000.00/s N/A 60 12.75 MB/s 9000.00/s N/A
"""


Expand Down
6 changes: 3 additions & 3 deletions utilities_common/netstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def format_prate(rate):
#TODO what does it mean /s maybe p/s packets per seconds
return "{:.2f}".format(float(rate))+'/s'

def format_util(brate, port_rate=PORT_RATE):
def format_util(brate, port_rate):
"""
Calculate the util.
"""
if brate == STATUS_NA:
if brate == STATUS_NA or port_rate == STATUS_NA:
return STATUS_NA
else:
util = brate/(float(port_rate)*1024*1024*1024/8.0)*100
util = brate/(float(port_rate)*1024*1024/8.0)*100
return "{:.2f}%".format(util)

def table_as_json(table, header):
Expand Down

0 comments on commit 0f60ccc

Please sign in to comment.