Skip to content

Add a tool to convert port alias when used as bash pipe#135

Merged
taoyl-ms merged 8 commits intosonic-net:masterfrom
taoyl-ms:taoyl/port2alias
Oct 26, 2017
Merged

Add a tool to convert port alias when used as bash pipe#135
taoyl-ms merged 8 commits intosonic-net:masterfrom
taoyl-ms:taoyl/port2alias

Conversation

@taoyl-ms
Copy link
Copy Markdown
Contributor

Sample Usage (on a S6000):

admin@s6000-1:~$ portstat                
      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        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
  Ethernet4        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
  Ethernet8        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet12        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet16        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet20        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet24        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet28        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet32        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet36        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet40        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet44        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet48        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet52        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet56        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet60        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet64        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet68        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet72        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet76        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet80        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet84        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet88        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet92        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 Ethernet96        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet100        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet104        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet108        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet112        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet116        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet120        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
Ethernet124        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
admin@s6000-1:~$ portstat | port2alias 
      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
-----------  -------  -------  --------  ---------  --------  --------  --------  -------  --------  ---------  --------  --------  --------
  fortyGigE0/0        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
  fortyGigE0/4        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
  fortyGigE0/8        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/12        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/16        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/20        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/24        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/28        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/32        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/36        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/40        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/44        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/48        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/52        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/56        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/60        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/64        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/68        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/72        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/76        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/80        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/84        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/88        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/92        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
 fortyGigE0/96        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/100        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/104        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/108        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/112        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/116        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/120        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
fortyGigE0/124        U        0       N/A        N/A         0         0         0    20748       N/A        N/A         0         0         0
admin@s6000-1:~$

Depends on sonic-net/sonic-buildimage#1072

Comment thread scripts/port2alias Outdated
start = 0
end = 0
while end < len(line):
if line[end].isalnum():
Copy link
Copy Markdown
Contributor

@lguohan lguohan Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, you have an assumption that the port name does not contain char other than alnum. For example, the port name cannot be et5_1 #Resolved

Copy link
Copy Markdown
Contributor Author

@taoyl-ms taoyl-ms Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the legal charset for sonic interface names? I thought only alnum characters are allowed. #Closed

Comment thread scripts/port2alias
platform = tokens[1]
return (platform, hwsku)

def main():
Copy link
Copy Markdown
Contributor

@lguohan lguohan Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is probably good to have a unit test for this string conversion. We need to have some positive and negative case.

for example,

Ethernet3 should not be converted if Ethernet3 is not in the alias map.

Ethernet43 should not be converted if Etherent4 is in but not Ethernet43,

Ethernet4: should be converted if Ethernet4 is in. #Resolved

Copy link
Copy Markdown
Contributor

@lguohan lguohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need at least add some unit test for this tool.

Comment thread scripts/port2alias Outdated
else:
# End of a word
word = line[start:end]
if port.has_key(word):
Copy link
Copy Markdown
Contributor

@jleveque jleveque Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider if word in port: (or if word in port.keys(): to make it more understandable at first glance) instead. More portable for the future as it appears has_key() is deprecated and has been removed in Python 3. #Resolved

@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

3 similar comments
@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

2 similar comments
@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

@taoyl-ms
Copy link
Copy Markdown
Contributor Author

retest this please

@taoyl-ms taoyl-ms merged commit 67f8806 into sonic-net:master Oct 26, 2017
vdahiya12 pushed a commit to vdahiya12/sonic-utilities that referenced this pull request Jul 23, 2021
Why I did this?

xcvrd unit test failed when building it with python3: 

```
17:23:50  _____________________ ERROR collecting tests/test_xcvrd.py _____________________
17:23:50  tests/test_xcvrd.py:36: in <module>
17:23:50      class TestXcvrdScript(object):
17:23:50  tests/test_xcvrd.py:41: in TestXcvrdScript
17:23:50      @patch('xcvrd.xcvrd.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
17:23:50  E   NameError: name 'patch' is not defined
```

How I did this?
import the package patch
mihirpat1 pushed a commit to mihirpat1/sonic-utilities that referenced this pull request Sep 15, 2023
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Junchao-Mellanox pushed a commit to Junchao-Mellanox/sonic-utilities that referenced this pull request Mar 20, 2025
sonic-net#135)

```<br>* b7fbd2f9 - (HEAD -> 202412) Merge branch '202411' of https://github.com/sonic-net/sonic-utilities into 202412 (2025-02-28) [Sonic Automation]
* 17a7b18 - (origin/202411) Fix `vnet_route_check` for active and inactive routes, add `--all` option (sonic-net#3780) (2025-02-25) [mssonicbld]
* 5cc1012 - [202411][FC] remove FC delay field (sonic-net#3768) (2025-02-21) [Stepan Blyshchak]
* 8ceba38 - [QOS] Skip showing unnecessary warning message (sonic-net#3762) (2025-02-11) [mssonicbld]
* 04b60e2 - Fix call for spanning-tree commands in dump script (sonic-net#3752) (2025-02-07) [mssonicbld]
* bbe29ae - [show][interface] Add changes for show interface errors command (sonic-net#3749) (2025-02-04) [mssonicbld]<br>```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants