Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show]: split show interfaces commands into separate file #1044

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions scripts/intfstat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#####################################################################
#
# intfstat is a tool for summarizing l3 network statistics.
# intfstat is a tool for summarizing l3 network statistics.
#
#####################################################################

Expand All @@ -17,7 +17,7 @@ import time

# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "1":
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
lguohan marked this conversation as resolved.
Show resolved Hide resolved
modules_path = os.path.join(os.path.dirname(__file__), "..")
test_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
Expand All @@ -34,7 +34,7 @@ from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json,
NStats = namedtuple("NStats", "rx_b_ok, rx_p_ok, tx_b_ok, tx_p_ok,\
rx_b_err, rx_p_err, tx_b_err, tx_p_err,")

header = ['IFACE', 'RX_OK', 'RX_BPS', 'RX_PPS', 'RX_ERR',
header = ['IFACE', 'RX_OK', 'RX_BPS', 'RX_PPS', 'RX_ERR',
'TX_OK', 'TX_BPS', 'TX_PPS', 'TX_ERR']

counter_names = (
Expand Down Expand Up @@ -95,7 +95,7 @@ class Intfstat(object):
if counter_rif_name_map is None:
print "No %s in the DB!" % COUNTERS_RIF_NAME_MAP
sys.exit(1)

if rif and not rif in counter_rif_name_map:
print "Interface %s missing from %s! Make sure it exists" % (rif, COUNTERS_RIF_NAME_MAP)
sys.exit(2)
Expand All @@ -105,7 +105,7 @@ class Intfstat(object):
return cnstat_dict

for rif in natsorted(counter_rif_name_map):
cnstat_dict[rif] = get_counters(counter_rif_name_map[rif])
cnstat_dict[rif] = get_counters(counter_rif_name_map[rif])
return cnstat_dict

def get_intf_state(self, port_name):
Expand Down Expand Up @@ -187,12 +187,12 @@ class Intfstat(object):
print tabulate(table, header, tablefmt='simple', stralign='right')

def cnstat_single_interface(self, rif, cnstat_new_dict, cnstat_old_dict):

header = rif + '\n' + '-'*len(rif)
body = """
RX:
%10s packets
%10s bytes
%10s packets
%10s bytes
%10s error packets
%10s error bytes
TX:
Expand All @@ -202,7 +202,7 @@ class Intfstat(object):
%10s error bytes"""

cntr = cnstat_new_dict.get(rif)

if cnstat_old_dict:
old_cntr = cnstat_old_dict.get(rif)
if old_cntr:
Expand Down
38 changes: 19 additions & 19 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import os

# mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "1":
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), "..")
tests_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
Expand Down Expand Up @@ -49,10 +49,10 @@ def db_connect_configdb():
Connect to configdb
"""
config_db = ConfigDBConnector()
if config_db is None:
return None
if config_db is None:
return None
config_db.connect()
return config_db
return config_db

def get_frontpanel_port_list(config_db):
ports_dict = config_db.get_table('PORT')
Expand Down Expand Up @@ -96,7 +96,7 @@ def config_db_vlan_port_keys_get(int_to_vlan_dict, front_panel_ports_list, intf_
if intf_name in int_to_vlan_dict.keys():
vlan = int_to_vlan_dict[intf_name]
if "Vlan" in vlan:
vlan = "trunk"
vlan = "trunk"
return vlan


Expand Down Expand Up @@ -169,9 +169,9 @@ def state_db_port_optics_get(state_db, intf_name, type):
"""
full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + intf_name
optics_type = state_db.get(state_db.STATE_DB, full_table_id, type)
if optics_type is None:
return "N/A"
return optics_type
if optics_type is None:
return "N/A"
return optics_type

def merge_dicts(x,y):
# store a copy of x, but overwrite with y's values where applicable
Expand All @@ -188,7 +188,7 @@ def merge_dicts(x,y):
def tuple_to_dict(tup, new_dict):
"""
From a tuple create a dictionary that uses the first item in the tuple as a key
and the 2nd item in the tuple as a value.
and the 2nd item in the tuple as a value.
"""
for a, b in tup:
new_dict.setdefault(a, []).append(b)
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_portchannel_list(get_raw_po_int_configdb_info):
>>> portchannel_list = get_portchannel_list(get_raw_po_int_configdb_info)
>>> pprint(portchannel_list)
['PortChannel0001', 'PortChannel0002', 'PortChannel0003', 'PortChannel0004']
>>>
>>>
"""
portchannel_list = []
for po in get_raw_po_int_configdb_info:
Expand All @@ -234,7 +234,7 @@ def create_po_int_tuple_list(get_raw_po_int_configdb_info):
('PortChannel0004', 'Ethernet124'),
('PortChannel0003', 'Ethernet120'),
('PortChannel0001', 'Ethernet112')]
>>>
>>>
"""
po_int_tuple_list = get_raw_po_int_configdb_info.keys()
return po_int_tuple_list
Expand Down Expand Up @@ -262,11 +262,11 @@ def create_int_to_portchannel_dict(po_int_tuple_list):

def po_speed_dict(po_int_dict, appl_db):
"""
This function takes the portchannel to interface dictionary
This function takes the portchannel to interface dictionary
and the appl_db and then creates a portchannel to speed
dictionary.
dictionary.
"""
if po_int_dict:
if po_int_dict:
po_list = []
for key, value in po_int_dict.iteritems():
agg_speed_list = []
Expand Down Expand Up @@ -311,9 +311,9 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por
return status
status = appl_db.get(appl_db.APPL_DB, full_table_id, status_type)
#print(status)
if status is None:
if status is None:
return "N/A"
return status
return status

def appl_db_sub_intf_status_get(appl_db, config_db, front_panel_ports_list, portchannel_speed_dict, sub_intf_name, status_type):
sub_intf_sep_idx = sub_intf_name.find(VLAN_SUB_INTERFACE_SEPARATOR)
Expand Down Expand Up @@ -415,16 +415,16 @@ class IntfStatus(object):
def __init__(self, intf_name):
"""
Class constructor method
:param self:
:param self:
:param intf_name: string of interface
:return:
:return:
"""
self.appl_db = db_connect_appl()
self.state_db = db_connect_state()
self.config_db = db_connect_configdb()
if self.appl_db is None:
return
if self.state_db is None:
if self.state_db is None:
return
if self.config_db is None:
return
Expand Down
18 changes: 9 additions & 9 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""
Script to show sfp eeprom and presence status.
Not like sfputil this scripts get the sfp data from DB directly.
Not like sfputil this scripts get the sfp data from DB directly.
"""
import sys
import click
Expand All @@ -15,14 +15,14 @@ from tabulate import tabulate

# Mock the redis for unit test purposes #
try:
if os.environ["UTILITIES_UNIT_TESTING"] == "1":
if os.environ["UTILITIES_UNIT_TESTING"] == "2":
modules_path = os.path.join(os.path.dirname(__file__), "..")
test_path = os.path.join(modules_path, "tests")
sys.path.insert(0, modules_path)
sys.path.insert(0, test_path)
import mock_tables.dbconnector
except KeyError:
pass
pass

qsfp_data_map = {'model': 'Vendor PN',
'vendor_oui': 'Vendor OUI',
Expand Down Expand Up @@ -159,7 +159,7 @@ class SFPShow(object):
dom_unit_map[key])
out_put = out_put + current_val + '\n'
return out_put

# Convert dom sensor info in DB to cli output string
def convert_dom_to_output_string(self, sfp_type, dom_info_dict):
ident = ' '
Expand Down Expand Up @@ -253,7 +253,7 @@ class SFPShow(object):
def convert_sfp_info_to_output_string(self, sfp_info_dict):
ident = ' '
out_put = ''

sorted_qsfp_data_map = sorted(qsfp_data_map.items(), key=operator.itemgetter(1))
for key in sorted_qsfp_data_map:
key1 = key[0]
Expand Down Expand Up @@ -299,7 +299,7 @@ class SFPShow(object):
if presence:
out_put = self.convert_interface_sfp_info_to_cli_output_string(self.sdb, interfacename, dump_dom)
else:
out_put = out_put + interfacename + ': ' + 'SFP EEPROM Not detected' + '\n'
out_put = out_put + interfacename + ': ' + 'SFP EEPROM Not detected' + '\n'
else:
port_table_keys = self.adb.keys(self.adb.APPL_DB, "PORT_TABLE:*")
sorted_table_keys = natsorted(port_table_keys)
Expand All @@ -310,9 +310,9 @@ class SFPShow(object):
if presence:
out_put = out_put + self.convert_interface_sfp_info_to_cli_output_string(self.sdb, interface, dump_dom)
else:
out_put = out_put + interface + ': ' + 'SFP EEPROM Not detected' + '\n'
out_put = out_put + interface + ': ' + 'SFP EEPROM Not detected' + '\n'

out_put = out_put + '\n'
out_put = out_put + '\n'

print out_put

Expand All @@ -336,7 +336,7 @@ class SFPShow(object):
port_table.append((key,'Present'))
else:
port_table.append((key,'Not present'))

sorted_port_table = natsorted(port_table)
click.echo(tabulate(sorted_port_table, header))

Expand Down
Loading