Skip to content

[sonic-config-engine]: Improve comparison between default and supported breakout modes.#9278

Merged
qiluo-msft merged 4 commits intosonic-net:masterfrom
oleksandrivantsiv:master
Dec 20, 2021
Merged

[sonic-config-engine]: Improve comparison between default and supported breakout modes.#9278
qiluo-msft merged 4 commits intosonic-net:masterfrom
oleksandrivantsiv:master

Conversation

@oleksandrivantsiv
Copy link
Collaborator

closes #7958

Why I did it

The previous implementation of sonic-cfggen did a simple comparison between default breakout mode in
hwsku.json and supported modes in platform.json. To set a different default speed in hwsku.json
it was required to add one more entry to supported modes in platfrom.json file:

1x10G[100G,50G] vs 1x100G[50G,10G]

The new implementation does more intelligent parsing and analysis of supported and default modes. It
allows changing default speed without adding a new entry to platform.json.

How I did it

Add more intelligent parsing and analysis of supported and default modes.

How to verify it

Run sonic-config-engine unit tests from sonic-config-engine/tests directory:

sonic-config-engine/tests$ pytest ./test_cfggen_platformJson.py -vvs

test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_dummy_run PASSED                                                                                                    [ 16%]
test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_platform_json_all_ethernet_interfaces PASSED                                                                        [ 33%]
test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_platform_json_interfaces_keys PASSED                                                                                [ 50%]
test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_platform_json_no_interfaces PASSED                                                                                  [ 66%]
test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_platform_json_specific_ethernet_interfaces PASSED                                                                   [ 83%]
test_cfggen_platformJson.py::TestCfgGenPlatformJson::test_print_data PASSED                                                                                                   [100%]

============================================================================= 6 passed in 2.46 seconds ==============================================================================

Unit tests are extended to cover changes in breakout mode parsing added in this PR

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

…ed breakout modes.

The previous implementation of sonic-cfggen did a simple comparison between default breakout mode in
hwsku.json and supported modes in platform.json. To set a different default speed in hwsku.json
it was required to add one more entry to supported modes in platfrom.json file:

1x10G[100G,50G] vs 1x100G[50G,10G]

The new implementation does more intelligent parsing and analysis of supported and default modes. It
allows changing default speed without adding a new entry to platform.json.
@dgsudharsan
Copy link
Collaborator

@praveen-li @zhenggen-xu Can you please review?

dgsudharsan
dgsudharsan previously approved these changes Nov 16, 2021
@zhenggen-xu
Copy link
Collaborator

@samaity Please review.

@oleksandrivantsiv
Copy link
Collaborator Author

@samaity Can you please review this?

@samaity
Copy link
Collaborator

samaity commented Nov 19, 2021

@samaity Can you please review this?

checking now!

@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@liat-grozovik
Copy link
Collaborator

@samaity kindly reminder. can you please provide your inputs?

@liat-grozovik liat-grozovik removed the request for review from zhenggen-xu November 24, 2021 09:09
@liat-grozovik
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liat-grozovik
Copy link
Collaborator

@oleksandrivantsiv could you please check the lgtm issue so we can now mege now that all approved the change?

@lgtm-com
Copy link

lgtm-com bot commented Dec 9, 2021

This pull request introduces 2 alerts when merging 04be47c into fc91dae - view on LGTM.com

new alerts:

  • 1 for Inconsistent equality and inequality
  • 1 for Inconsistent equality and hashing

@liat-grozovik
Copy link
Collaborator

@samaity kindly reminder, can you please review ?

alias_position += 1
lanes_start += step
def __hash__(self):
return hash((self.num_ports, tuple(self.supported_speed), self.num_assigned_lanes))
Copy link
Collaborator

Choose a reason for hiding this comment

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

what exactly are we checking here?

Copy link
Collaborator Author

@oleksandrivantsiv oleksandrivantsiv Dec 15, 2021

Choose a reason for hiding this comment

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

BreakoutModeEntry objects are used to compare breakout modes based on their capabilities with __eq__ and __ne__ operators.
In Python when the class implements __eq__ operator it is recommended to implement __hash__ operator as well. __hash__ operator returns integer hash id of the object that can be used to put an object in a dictionary (as a key) or set. Here hash id is calculated based on capabilities that define breakout mode.

My initial implementation didn't include this method implementation. I added to fix LGTM alerts:

This pull request introduces 2 alerts when merging 04be47c into fc91dae - view on LGTM.com

new alerts:

1 for Inconsistent equality and inequality
1 for Inconsistent equality and hashing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clarification, @oleksandrivantsiv.

for supported_mode in self._properties['breakout_modes']:
if self._breakout_mode_entry == self._str_to_entries(supported_mode):
self._breakout_capabilities = self._properties['breakout_modes'][supported_mode]
break
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you use break here?
what will be case when self._breakout_mode_entry != self._str_to_entries(supported_mode)? Should we address such cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here we are trying to find whether the given breakout mode is supported. We are iterating over supported modes and checking if the given breakout mode is equal to one of them. If the breakout mode is not equal to any of the supported modes we will raise an exception with an appropriated message at line 250.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM!

raise RuntimeError("Unsupported breakout mode {}!".format(bmode))

def _re_group_to_entry(self, group):
if len(group) != 6:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make 6 as global var in the beginning of this file and use it here and also in BRKOUT_PATTERN?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a new BRKOUT_PATTERN_GROUPS=6 global variable to replace the magic number used here.
However, I didn't change the value used in BRKOUT_PATTERN because it has a different meaning.
Here be indicating how many groups should have as a result of regexp matching.
In BRKOUT_PATTERN pattern 6 indicates up to how many digits can be in each group.
It's just a coincidence that these values are the same :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aah, makes sense! 👍

2x50G ---------------> [('2', '50G', None, None, None)]
"""

groups_list = [re.match(BRKOUT_PATTERN, i).groups() for i in bmode.split("+")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

if regex does not match, should we do try-catch in that case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To raise an exception with the meaningful error message I added try-except as suggested. Thanks!

@samaity
Copy link
Collaborator

samaity commented Dec 15, 2021

@oleksandrivantsiv reviewed the code and asked few doubts.

Overall, looks good to me. Kudos to the intelligence behind the smooth parsing and analysis of supported and default modes and covering more corner cases 👍

btw a quick doubt, did you build the whole image with this PR? As I remember, there are few build test cases in sonic-utilities submodule which depend on the function you are deprecating via this PR?

@oleksandrivantsiv
Copy link
Collaborator Author

@samaity thanks a lot for your feedback!

Before raising a PR I build the whole images and run a CI. The changes listed here are fully backward compatible with what was implemented before. All configuration files written before should work without any changes

Copy link
Collaborator

@samaity samaity left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@dgsudharsan dgsudharsan added the Request for 202111 Branch For PRs being requested for 202111 branch label Dec 15, 2021
OPTIONAL_HWSKU_ATTRIBUTES = ["fec", "autoneg"]

BRKOUT_PATTERN = r'(\d{1,3})x(\d{1,3}G)(\[(\d{1,3}G,?)*\])?(\((\d{1,3})\))?'
BRKOUT_PATTERN = r'(\d{1,6})x(\d{1,6}G?)(\[(\d{1,6}G?,?)*\])?(\((\d{1,6})\))?'
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 16, 2021

Choose a reason for hiding this comment

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

G?

Why allow missing G? What is the default unit? Is there a document for the default unit? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To allow to configure speed in megabytes:

                "1x100000[50G,40000,25000,10G]": ["Eth36"],
                "2x50G": ["Eth36/1", "Eth36/2"],
                "4x25G[10000]": ["Eth36/1", "Eth36/2", "Eth36/3", "Eth36/4"],
                "2x25000(2)+1x50G(2)": ["Eth36/1", "Eth36/2", "Eth36/3"],
                "1x50000(2)+2x25G(2)": ["Eth36/1", "Eth36/2", "Eth36/3"]

@liat-grozovik
Copy link
Collaborator

@qiluo-msft any further comment? can we move forward and merge?

@qiluo-msft qiluo-msft merged commit 3af4a96 into sonic-net:master Dec 20, 2021
judyjoseph pushed a commit that referenced this pull request Dec 27, 2021
…ed breakout modes. (#9278)

Closes #7958 

#### Why I did it
The previous implementation of sonic-cfggen did a simple comparison between default breakout mode in
hwsku.json and supported modes in platform.json. To set a different default speed in hwsku.json
it was required to add one more entry to supported modes in platfrom.json file:

1x10G[100G,50G] vs 1x100G[50G,10G]

The new implementation does more intelligent parsing and analysis of supported and default modes. It
allows changing default speed without adding a new entry to platform.json.

#### How I did it
Add more intelligent parsing and analysis of supported and default modes.

#### How to verify it
Run sonic-config-engine unit tests from sonic-config-engine/tests directory
arlakshm pushed a commit that referenced this pull request Mar 24, 2022
…ed breakout modes. (#9278)

Closes #7958 

#### Why I did it
The previous implementation of sonic-cfggen did a simple comparison between default breakout mode in
hwsku.json and supported modes in platform.json. To set a different default speed in hwsku.json
it was required to add one more entry to supported modes in platfrom.json file:

1x10G[100G,50G] vs 1x100G[50G,10G]

The new implementation does more intelligent parsing and analysis of supported and default modes. It
allows changing default speed without adding a new entry to platform.json.

#### How I did it
Add more intelligent parsing and analysis of supported and default modes.

#### How to verify it
Run sonic-config-engine unit tests from sonic-config-engine/tests directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DPB] sonic-cfggen does not correctly match breakout modes with different default speed

8 participants