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

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

Merged
merged 8 commits into from
Oct 26, 2017

Conversation

taoyl-ms
Copy link
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

start = 0
end = 0
while end < len(line):
if line[end].isalnum():
Copy link
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
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

platform = tokens[1]
return (platform, hwsku)

def main():
Copy link
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
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.

else:
# End of a word
word = line[start:end]
if port.has_key(word):
Copy link
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
Contributor Author

retest this please

3 similar comments
@taoyl-ms
Copy link
Contributor Author

retest this please

@taoyl-ms
Copy link
Contributor Author

retest this please

@taoyl-ms
Copy link
Contributor Author

retest this please

@taoyl-ms
Copy link
Contributor Author

retest this please

2 similar comments
@taoyl-ms
Copy link
Contributor Author

retest this please

@taoyl-ms
Copy link
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
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