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

[config] Add support of PortChannels to portconfig #1375

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Jan 21, 2021

- What I did
Resolves sonic-net/sonic-buildimage#6430
Added support of PortChannels to portconfig script.
Added mocking of redis into portconfig script.
Added unit tests for subcommand config interface mtu.

- How I did it
Added checking of prefix in name of port, passed to the script. If it is EthernetXX, the script uses table name PORT to operate with DB, if it is PortChannelXX, then the script will use table name PORTCHANNEL, otherwise it will throw an exception to notify that port type is wrong.

- How to verify it

  1. sudo config portchannel add PortChannel0001
  2. sudo config interface mtu PortChannel0001 1510
  3. see current MTU of the PortChannel with
    ip link show PortChannel0001

Test result in case the portchannel has no members:

admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------
 0011  PortChannel0011  LACP(A)(Dw)  N/A
admin@sonic:~$ sudo config int mtu PortChannel0011 512
admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 512 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ sudo config portchannel member add PortChannel0011 Ethernet12
Usage: config portchannel member add [OPTIONS] <portchannel_name> <port_name>
Try "config portchannel member add -h" for help.

Error: Port MTU of Ethernet12 is different than the PortChannel0011 MTU size
admin@sonic:~$ sudo config int mtu Ethernet12 512
admin@sonic:~$ sudo config portchannel member add PortChannel0011 Ethernet12
admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------------
 0011  PortChannel0011  LACP(A)(Dw)  Ethernet12(D)

Test result in case the portchannel has a member:

admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------------
 0011  PortChannel0011  LACP(A)(Dw)  Ethernet12(D)
admin@sonic:~$ 
admin@sonic:~$ sudo config int mtu PortChannel0011 9100
admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9100 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ ip link show Ethernet12
87: Ethernet12: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9100 qdisc pfifo_fast master PortChannel0011 state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff

- Previous command output (if the output of a command-line utility has changed)

- New command output (if the output of a command-line utility has changed)
if to try to pass some trash as port argument, like this sudo config interface mtu Unknown0002 9100, you will receive error in console output: Invalid port type specified

@ghost ghost marked this pull request as ready for review January 21, 2021 16:03
@anamehra
Copy link
Contributor

Diff looks good, works fine with Ethernet and PortChannel ports, will need this for 201911. Thanks

@prsunny prsunny requested a review from judyjoseph January 29, 2021 01:59
@gechiang
Copy link
Contributor

@maksymbelei95
What if the port channel although configured but has no member ports in it?
Can you try it out and see what is the end result?
also, it is a policy that all code changes require unit test code that goes with it. Please include the unit test code for this change.
Thanks!

@ghost
Copy link
Author

ghost commented Feb 15, 2021

@gechiang

What if the port channel although configured but has no member ports in it?

I have tested the case. Here is my output:

admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------
 0011  PortChannel0011  LACP(A)(Dw)  N/A
admin@sonic:~$ sudo config int mtu PortChannel0011 512
admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 512 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ sudo config portchannel member add PortChannel0011 Ethernet12
Usage: config portchannel member add [OPTIONS] <portchannel_name> <port_name>
Try "config portchannel member add -h" for help.

Error: Port MTU of Ethernet12 is different than the PortChannel0011 MTU size
admin@sonic:~$ sudo config int mtu Ethernet12 512
admin@sonic:~$ sudo config portchannel member add PortChannel0011 Ethernet12
admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------------
 0011  PortChannel0011  LACP(A)(Dw)  Ethernet12(D)

Another case(the port channel has a member):

admin@sonic:~$ show int portchannel 
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  -------------
 0011  PortChannel0011  LACP(A)(Dw)  Ethernet12(D)
admin@sonic:~$ 
admin@sonic:~$ sudo config int mtu PortChannel0011 9100
admin@sonic:~$ ip link show PortChannel0011
83: PortChannel0011: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9100 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff
admin@sonic:~$ ip link show Ethernet12
87: Ethernet12: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9100 qdisc pfifo_fast master PortChannel0011 state DOWN mode DEFAULT group default qlen 1000
    link/ether 1c:34:da:eb:ca:80 brd ff:ff:ff:ff:ff:ff

Both cases look good.

also, it is a policy that all code changes require unit test code that goes with it. Please include the unit test code for this change.
Thanks!

Sure. But, as I mentioned before in the related ticket, I found out that there are no unit tests, related to config interface commands. I thought it is related to #1301, isn't it?

@gechiang
Copy link
Contributor

@maksymbelei95
Thanks for the added result of various config scenario. Please update/add those under "How to verify it" of this PR.
As for the testcase, can you please refer to this PR which has both multi-asic support and single asic support for config:
#1248

Please follow the above PR and add the necessary test cases.
Thanks!

@@ -22,15 +22,20 @@ import argparse
import swsssdk

PORT_TABLE_NAME = "PORT"
PORTCHANNEL_TABLE_NAME = "PORTCHANNEL"
PORT_PREFIX_ETHERNET = "Ethernet"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the API's defined in https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-py-common/sonic_py_common/interface.py. This prevents duplicate definitions of table names and prefixes.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

if args.port.startswith(PORT_PREFIX_ETHERNET):
port_table_name = PORT_TABLE_NAME
elif args.port.startswith(PORT_PREFIX_PORTCHANNEL):
port_table_name = PORTCHANNEL_TABLE_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@ghost ghost force-pushed the fix_portconfig_portchannel branch 3 times, most recently from cc1c90a to 9e50825 Compare February 19, 2021 17:19
@ghost
Copy link
Author

ghost commented Feb 20, 2021

retest this please

@ghost
Copy link
Author

ghost commented Feb 22, 2021

@gechiang, @judyjoseph, I have added a related unit test cases to the PR. Could I ask you to review them?

@ghost ghost requested a review from judyjoseph February 22, 2021 15:44
@ghost
Copy link
Author

ghost commented Mar 23, 2021

@gechiang, @judyjoseph, could you review the PR?

@judyjoseph
Copy link
Contributor

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ghost ghost force-pushed the fix_portconfig_portchannel branch from 9e50825 to 3f07964 Compare April 14, 2021 10:28
@ghost
Copy link
Author

ghost commented Apr 14, 2021

@gechiang, @judyjoseph, I have rebased the PR, unit tests done successfully. Could your check the PR?

@judyjoseph
Copy link
Contributor

@maksymbelei95, Could you please resolve this conflict before we merge it in - thanks.

@gechiang
Copy link
Contributor

gechiang commented Jun 4, 2021

@maksymbelei95 It appears that if a port is already a member of portchannel, user can still configure its MTU on its own? If there is a conflict between portchannel configured MTU and that of its member I believe the portchannel will force its value to its member. but after that if another MTU configured to one of its member with conflicting value, I believe it will again becomes a conflict. I think if we decide to support MTU configured on port-channel, we must add check to disallow user from configuring MTU onto the individual LAG members. Also, when the port is being converted to LAG, we should check that if its MTU is at default value and if it is not, we should disallow the user from adding it to portchannel until that is corrected and then let it inherit what is already configured for the LAG itself. We also need to consider what if a member is deleted from port-channel, what would its MTU be? Retain what it inherited from the port-channel? or go back to default MTU? I think all these requires some answer before we should allow MTU configuration for portchannel. Can you work on these so that we have a solid coverage of all these scenarios? Thanks!

Maksym Belei added 4 commits October 20, 2021 20:33
* Adding support of PortChannels to portconfig script
  to be able to configure PortChannels by CLI commands,
  like 'config interface mtu'

Signed-off-by: Maksym Belei <[email protected]>
* Reformat the script according to Python code style,
  fix typos.

Signed-off-by: Maksym Belei <[email protected]>
…Minor refactoring.

* Adding mocking of redis DB into portconfig script for unit testing purpose.
* Using of commom API from sonic_py_common.interface instead of defining of
  own constants and conditions.
* Refactoring "mtu" function to be more consistant and efficient.

Signed-off-by: Maksym Belei <[email protected]>
* Adding unit tests for subcommand 'config intf mtu' including testing of
  portconfig script.

Signed-off-by: Maksym Belei <[email protected]>
@NGorb-jabil NGorb-jabil force-pushed the fix_portconfig_portchannel branch from 3f07964 to f353275 Compare October 21, 2021 08:29
@NGorb-jabil
Copy link

@gechiang I have checked all cases you mentioned above.
User unable to add port into port-channel with mtu different from port-channel mtu, also its impossible to change MTU onto the individual LAG members.
If port is deleted from port-channel, it inherits port-channel MTU.
Please, could your check last changes ?

@lgtm-com
Copy link

lgtm-com bot commented Oct 21, 2021

This pull request fixes 1 alert when merging f35327586450378678f7633fd2aae05112b299bd into 9017d99 - view on LGTM.com

fixed alerts:

  • 1 for Unused import

@NGorb-jabil NGorb-jabil force-pushed the fix_portconfig_portchannel branch from f353275 to f696658 Compare October 22, 2021 07:00
@NGorb-jabil NGorb-jabil force-pushed the fix_portconfig_portchannel branch from f696658 to cfb23f6 Compare October 22, 2021 10:44
@lgtm-com
Copy link

lgtm-com bot commented Oct 22, 2021

This pull request fixes 1 alert when merging cfb23f6 into 9017d99 - view on LGTM.com

fixed alerts:

  • 1 for Unused import

@KonstiantynHalushka
Copy link

@judyjoseph Please run this PR again for testing

@lgtm-com
Copy link

lgtm-com bot commented Nov 9, 2021

This pull request fixes 1 alert when merging e063eca into 63a5257 - view on LGTM.com

fixed alerts:

  • 1 for Unused import

@KonstiantynHalushka
Copy link

fixed alert about unused import found by bot is not an error. It is designed for unit tests.

@pshulik
Copy link

pshulik commented Nov 12, 2021

@judyjoseph Could you please review the changes

@pshulik
Copy link

pshulik commented Nov 12, 2021

Dear @gechiang and @anamehra. Could you please review the changes

stepanblyschak pushed a commit to stepanblyschak/sonic-utilities that referenced this pull request Apr 28, 2022
 [sonic-swsss] Fix the issue of field "next_hop_ip" not getting updated
 in state DB in ERSPAN Mirror (sonic-net#1375)
[vlanmgr] Support Jumbo Frame By Default (sonic-net#1393)
[fec] added logic that put port down before applying fec
onfiguration (sonic-net#1399)
 [fec] Get FEC mode when port is already admin down (sonic-net#1403)
 Refine getDbId() calling to fix build after swss-common change
 (sonic-net#1245)
# The checks are only for Ethernet interfaces and their aliases
if clicommon.get_interface_naming_mode() == "alias":
name_from_alias = interface_alias_to_name(config_db, interface_name)
if interface_name is None or name_from_alias == interface_name:
Copy link
Contributor

Choose a reason for hiding this comment

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

With this added check you are requiring that once the device is configured with naming_mode alias it must use the alias name and not the SONiC interface name and it will cause this to fail? Can we preserve the original design/check and not treat the case where the look up resulted to the same name as a failure scenario?

@@ -258,26 +263,30 @@ def main():
# Load database config files
load_db_config()
try:
port_table_name = interface.get_port_table_name(args.port)
Copy link
Contributor

Choose a reason for hiding this comment

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

have you tested this with device set to naming_mode as "alias" and if you passed the alias name instead would this still work? I think we should move the naming mode check to here instead of handled at set_mtu only so that it should be handling the alias case in case naming_mode is set to alias?

@TafkaMax
Copy link

TafkaMax commented Jun 17, 2024

Why is this not yet merged???

show interfaces portchannel
Flags: A - active, I - inactive, Up - up, Dw - Down, N/A - not available,
       S - selected, D - deselected, * - not synced
  No.  Team Dev       Protocol     Ports
-----  -------------  -----------  -------
   01  PortChannel01  LACP(A)(Dw)
   02  PortChannel02  LACP(A)(Dw)
sudo config interface mtu PortChannel02 1500
Invalid port PortChannel02
 sudo config portchannel member add PortChannel02 Ethernet0
Usage: config portchannel member add [OPTIONS] <portchannel_name> <port_name>
Try "config portchannel member add -h" for help.

Error: Port MTU of Ethernet0 is different than the PortChannel02 MTU size

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.

PortChannel mtu change fails with CLI
7 participants