Repository: sonic-net/sonic-utilities

Issue:
In alias mode, "show interfaces counters detailed <alias_name>" cannot be displayed. 
<!--
    If you are reporting a new issue, make sure that we do not have any duplicates
    already open. You can ensure this by searching the issue list for this
    repository. If there is a duplicate, please close your issue and add a comment
    to the existing issue instead.

    If you suspect your issue is a bug, please edit your issue description to
    include the BUG REPORT INFORMATION shown below. If you fail to provide this
    information within 7 days, we cannot debug your issue and will close it. We
    will, however, reopen it if you later provide the information.

    For more information about reporting issues, see
    https://github.com/Azure/SONiC/wiki#report-issues

    ---------------------------------------------------
    GENERAL SUPPORT INFORMATION
    ---------------------------------------------------

    The GitHub issue tracker is for bug reports and feature requests.
    General support can be found at the following locations:

    - SONiC Support Forums - https://groups.google.com/forum/#!forum/sonicproject

    ---------------------------------------------------
    BUG REPORT INFORMATION
    ---------------------------------------------------
    Use the commands below to provide key information from your environment:
    You do NOT have to include this information if this is a FEATURE REQUEST
-->

#### Description
Using "show interfaces counters detailed" command with alias interface name not showing any information.
<!--
     Briefly describe the problem you are having in a few paragraphs.
-->

## Steps to reproduce the issue
1. Change interface naming mode to alias.
2. Logout & Login
3. Execute "show interfaces counters detailed Eth1" command

#### Describe the results you received
<pre>
admin@sonic:~$ show interfaces naming_mode
default
admin@sonic:~$ sudo config interface_naming_mode alias
Please logout and log back in for changes take effect.
admin@sonic:~$ exit
logout

Linux sonic 4.19.0-12-2-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64
You are on
  ____   ___  _   _ _  ____
 / ___| / _ \| \ | (_)/ ___|
 \___ \| | | |  \| | | |
  ___) | |_| | |\  | | |___
 |____/ \___/|_| \_|_|\____|

-- Software for Open Networking in the Cloud --

Unauthorized access and/or use are prohibited.
All access and/or use are subject to monitoring.

Help:    http://azure.github.io/SONiC/

Last login: Mon Oct 31 07:36:15 2022 from 10.133.176.105
admin@sonic:~$
admin@sonic:~$ show inteface status
Usage: show [OPTIONS] COMMAND [ARGS]...
Try "show -h" for help.

Error: No such command "inteface".
admin@sonic:~$ show interfaces status
  Interface                            Lanes    Speed    MTU    FEC    Alias    Vlan    Oper    Admin             Type    Asym PFC
-----------  -------------------------------  -------  -----  -----  -------  ------  ------  -------  ---------------  ----------
  Ethernet0                  241,242,243,244     100G   9100     rs     Eth1  routed      up       up  QSFP28 or later         N/A
  Ethernet8                  249,250,251,252     100G   9100     rs     Eth2  routed    down       up              N/A         N/A
 Ethernet16                  225,226,227,228     100G   9100     rs     Eth3  routed    down       up  QSFP28 or later         N/A
 Ethernet24                  233,234,235,236     100G   9100     rs     Eth4  routed    down       up              N/A         N/A
 Ethernet32  217,218,219,220,221,222,223,224     400G   9100     rs     Eth5  routed    down       up              N/A         N/A
 Ethernet40  209,210,211,212,213,214,215,216     400G   9100     rs     Eth6  routed    down       up              N/A         N/A
 Ethernet48  201,202,203,204,205,206,207,208     400G   9100     rs     Eth7  routed    down       up  QSFP28 or later         N/A
 Ethernet56  193,194,195,196,197,198,199,200     400G   9100     rs     Eth8  routed    down       up              N/A         N/A
 Ethernet64  185,186,187,188,189,190,191,192     400G   9100     rs     Eth9  routed    down       up              N/A         N/A
 Ethernet72  177,178,179,180,181,182,183,184     400G   9100     rs    Eth10  routed    down       up              N/A         N/A
 Ethernet80  169,170,171,172,173,174,175,176     400G   9100     rs    Eth11  routed    down       up  QSFP28 or later         N/A
 Ethernet88  161,162,163,164,165,166,167,168     400G   9100     rs    Eth12  routed    down       up              N/A         N/A
 Ethernet96  153,154,155,156,157,158,159,160     400G   9100     rs    Eth13  routed    down       up              N/A         N/A
Ethernet104  145,146,147,148,149,150,151,152     400G   9100     rs    Eth14  routed    down       up              N/A         N/A
Ethernet112  137,138,139,140,141,142,143,144     400G   9100     rs    Eth15  routed    down       up              N/A         N/A
Ethernet120  129,130,131,132,133,134,135,136     400G   9100     rs    Eth16  routed    down       up              N/A         N/A
Ethernet128  121,122,123,124,125,126,127,128     400G   9100     rs    Eth17  routed    down       up              N/A         N/A
Ethernet136  113,114,115,116,117,118,119,120     400G   9100     rs    Eth18  routed    down       up              N/A         N/A
Ethernet144  105,106,107,108,109,110,111,112     400G   9100     rs    Eth19  routed    down       up              N/A         N/A
Ethernet152     97,98,99,100,101,102,103,104     400G   9100     rs    Eth20  routed    down       up              N/A         N/A
Ethernet160          89,90,91,92,93,94,95,96     400G   9100     rs    Eth21  routed    down       up              N/A         N/A
Ethernet168          81,82,83,84,85,86,87,88     400G   9100     rs    Eth22  routed    down       up              N/A         N/A
Ethernet176          73,74,75,76,77,78,79,80     400G   9100     rs    Eth23  routed    down       up              N/A         N/A
Ethernet184          65,66,67,68,69,70,71,72     400G   9100     rs    Eth24  routed    down       up              N/A         N/A
Ethernet192          57,58,59,60,61,62,63,64     400G   9100     rs    Eth25  routed    down       up              N/A         N/A
Ethernet200          49,50,51,52,53,54,55,56     400G   9100     rs    Eth26  routed    down       up              N/A         N/A
Ethernet208          41,42,43,44,45,46,47,48     400G   9100     rs    Eth27  routed    down       up              N/A         N/A
Ethernet216          33,34,35,36,37,38,39,40     400G   9100     rs    Eth28  routed    down       up              N/A         N/A
Ethernet224          25,26,27,28,29,30,31,32     400G   9100     rs    Eth29  routed    down       up              N/A         N/A
Ethernet232          17,18,19,20,21,22,23,24     400G   9100     rs    Eth30  routed    down       up              N/A         N/A
Ethernet240           9,10,11,12,13,14,15,16     400G   9100     rs    Eth31  routed    down       up              N/A         N/A
Ethernet248                  1,2,3,4,5,6,7,8     400G   9100     rs    Eth32  routed    down       up              N/A         N/A
Ethernet256                              257      10G   9100   none    Eth33  routed    down       up              N/A         N/A
Ethernet257                              258      10G   9100   none    Eth34  routed    down       up              N/A         N/A
admin@sonic:~$ show interfaces status Eth1
  Interface            Lanes    Speed    MTU    FEC    Alias    Vlan    Oper    Admin             Type    Asym PFC
-----------  ---------------  -------  -----  -----  -------  ------  ------  -------  ---------------  ----------
  Ethernet0  241,242,243,244     100G   9100     rs     Eth1  routed      up       up  QSFP28 or later         N/A
admin@sonic:~$ show interfaces counters detailed Eth1
admin@sonic:~$
</pre>

#### Describe the results you expected
<pre>
admin@sonic:~$ show interfaces counters detailed Eth1
Packets Received 64 Octets..................... 451,375
Packets Received 65-127 Octets................. 12
Packets Received 128-255 Octets................ 32,744
Packets Received 256-511 Octets................ 0
Packets Received 512-1023 Octets............... 0
Packets Received 1024-1518 Octets.............. 0
Packets Received 1519-2047 Octets.............. 0
Packets Received 2048-4095 Octets.............. 0
Packets Received 4096-9216 Octets.............. 0
Packets Received 9217-16383 Octets............. 0

Total Packets Received Without Errors.......... 484,131
Unicast Packets Received....................... 0
Multicast Packets Received..................... 32,760
Broadcast Packets Received..................... 451,371

Jabbers Received............................... 0
Fragments Received............................. 0
Undersize Received............................. 0
Overruns Received.............................. 0

Packets Transmitted 64 Octets.................. 477,651
Packets Transmitted 65-127 Octets.............. 13
Packets Transmitted 128-255 Octets............. 34,650
Packets Transmitted 256-511 Octets............. 0
Packets Transmitted 512-1023 Octets............ 0
Packets Transmitted 1024-1518 Octets........... 0
Packets Transmitted 1519-2047 Octets........... 0
Packets Transmitted 2048-4095 Octets........... 0
Packets Transmitted 4096-9216 Octets........... 0
Packets Transmitted 9217-16383 Octets.......... 0

Total Packets Transmitted Successfully......... 512,314
Unicast Packets Transmitted.................... 0
Multicast Packets Transmitted.................. 34,664
Broadcast Packets Transmitted.................. 477,650
Time Since Counters Last Cleared............... None
admin@sonic:~$ show interfaces counters detailed Ethernet0
Usage: show interfaces counters detailed [OPTIONS] <interface_name>
Try "show interfaces counters detailed -h" for help.

Error: cannot find interface name for alias Ethernet0

</pre>

#### Additional information you deem important (e.g. issue happens only occasionally)




Discussion:

Resolving patch:
diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py
--- a/show/interfaces/__init__.py
+++ b/show/interfaces/__init__.py
@@ -533,6 +533,7 @@ def counters(ctx, verbose, period, interface, printall, namespace, display):
         if period is not None:
             cmd += " -p {}".format(period)
         if interface is not None:
+            interface = try_convert_interfacename_from_alias(ctx, interface)
             cmd += " -i {}".format(interface)
         else:
             cmd += " -s {}".format(display)
@@ -598,10 +599,13 @@ def rates(verbose, period, namespace, display):
 def rif(interface, period, verbose):
     """Show interface counters"""
 
+    ctx = click.get_current_context()
+
     cmd = "intfstat"
     if period is not None:
         cmd += " -p {}".format(period)
     if interface is not None:
+        interface = try_convert_interfacename_from_alias(ctx, interface)
         cmd += " -i {}".format(interface)
 
     clicommon.run_command(cmd, display_cmd=verbose)
@@ -614,10 +618,13 @@ def rif(interface, period, verbose):
 def detailed(interface, period, verbose):
     """Show interface counters detailed"""
 
+    ctx = click.get_current_context()
+
     cmd = "portstat -l"
     if period is not None:
         cmd += " -p {}".format(period)
     if interface is not None:
+        interface = try_convert_interfacename_from_alias(ctx, interface)
         cmd += " -i {}".format(interface)
 
     clicommon.run_command(cmd, display_cmd=verbose)


Test patch: