33
44import subprocess
55import click
6+ from utilities_common import constants
67import utilities_common .cli as clicommon
78import utilities_common .multi_asic as multi_asic_util
89from natsort import natsorted
@@ -658,35 +659,21 @@ def fec_stats(verbose, period, namespace, display):
658659 clicommon .run_command (cmd , display_cmd = verbose )
659660
660661
661- def get_port_oid_mapping ():
662+ def get_port_oid_mapping (db , namespace ):
662663 ''' Returns dictionary of all ports interfaces and their OIDs. '''
663- db = SonicV2Connector (host = REDIS_HOSTIP )
664- db .connect (db .COUNTERS_DB )
665-
666- port_oid_map = db .get_all (db .COUNTERS_DB , 'COUNTERS_PORT_NAME_MAP' )
667-
668- db .close (db .COUNTERS_DB )
669-
664+ port_oid_map = db .db_clients [namespace ].get_all (db .db .COUNTERS_DB , 'COUNTERS_PORT_NAME_MAP' )
670665 return port_oid_map
671666
672667
673- def fetch_fec_histogram (port_oid_map , target_port ):
668+ def fetch_fec_histogram (db , namespace , port_oid_map , target_port ):
674669 ''' Fetch and display FEC histogram for the given port. '''
675- asic_db = SonicV2Connector (host = REDIS_HOSTIP )
676- asic_db .connect (asic_db .ASIC_DB )
677-
678- config_db = ConfigDBConnector ()
679- config_db .connect ()
680-
681- counter_db = SonicV2Connector (host = REDIS_HOSTIP )
682- counter_db .connect (counter_db .COUNTERS_DB )
683670
684671 if target_port not in port_oid_map :
685672 click .echo ('Port {} not found in COUNTERS_PORT_NAME_MAP' .format (target_port ), err = True )
686673 raise click .Abort ()
687674
688675 port_oid = port_oid_map [target_port ]
689- asic_db_kvp = counter_db . get_all (counter_db .COUNTERS_DB , 'COUNTERS:{}' .format (port_oid ))
676+ asic_db_kvp = db . db_clients [ namespace ]. get_all (db . db .COUNTERS_DB , 'COUNTERS:{}' .format (port_oid ))
690677
691678 if asic_db_kvp is not None :
692679
@@ -705,24 +692,26 @@ def fetch_fec_histogram(port_oid_map, target_port):
705692 click .echo ('No kvp found in ASIC DB for port {}, exiting' .format (target_port ), err = True )
706693 raise click .Abort ()
707694
708- asic_db .close (asic_db .ASIC_DB )
709- config_db .close (config_db .CONFIG_DB )
710- counter_db .close (counter_db .COUNTERS_DB )
711695
712696
713697# 'fec-histogram' subcommand ("show interfaces counters fec-histogram")
714698@counters .command ('fec-histogram' )
715699@multi_asic_util .multi_asic_click_options
716700@click .argument ('interfacename' , required = True )
717- def fec_histogram (interfacename , namespace , display ):
701+ @clicommon .pass_db
702+ def fec_histogram (db , interfacename , namespace , display ):
718703 """Show interface counters fec-histogram"""
719- port_oid_map = get_port_oid_mapping ()
704+
705+ if namespace is None :
706+ namespace = constants .DEFAULT_NAMESPACE
707+
708+ port_oid_map = get_port_oid_mapping (db , namespace )
720709
721710 # Try to convert interface name from alias
722711 interfacename = try_convert_interfacename_from_alias (click .get_current_context (), interfacename )
723712
724713 # Fetch and display the FEC histogram
725- fetch_fec_histogram (port_oid_map , interfacename )
714+ fetch_fec_histogram (db , namespace , port_oid_map , interfacename )
726715
727716
728717# 'rates' subcommand ("show interfaces counters rates")
0 commit comments