[sonic-config-engine]: Improve comparison between default and supported breakout modes.#9278
[sonic-config-engine]: Improve comparison between default and supported breakout modes.#9278qiluo-msft merged 4 commits intosonic-net:masterfrom oleksandrivantsiv:master
Conversation
…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.
|
@praveen-li @zhenggen-xu Can you please review? |
|
@samaity Please review. |
|
@samaity Can you please review this? |
checking now! |
|
/azp run |
|
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. |
|
@samaity kindly reminder. can you please provide your inputs? |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@oleksandrivantsiv could you please check the lgtm issue so we can now mege now that all approved the change? |
|
This pull request introduces 2 alerts when merging 04be47c into fc91dae - view on LGTM.com new alerts:
|
|
@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)) |
There was a problem hiding this comment.
what exactly are we checking here?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| raise RuntimeError("Unsupported breakout mode {}!".format(bmode)) | ||
|
|
||
| def _re_group_to_entry(self, group): | ||
| if len(group) != 6: |
There was a problem hiding this comment.
can we make 6 as global var in the beginning of this file and use it here and also in BRKOUT_PATTERN?
There was a problem hiding this comment.
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 :)
| 2x50G ---------------> [('2', '50G', None, None, None)] | ||
| """ | ||
|
|
||
| groups_list = [re.match(BRKOUT_PATTERN, i).groups() for i in bmode.split("+")] |
There was a problem hiding this comment.
if regex does not match, should we do try-catch in that case?
There was a problem hiding this comment.
To raise an exception with the meaningful error message I added try-except as suggested. Thanks!
|
@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 |
|
@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 |
| 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})\))?' |
There was a problem hiding this comment.
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"]
|
@qiluo-msft any further comment? can we move forward and merge? |
…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
…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
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:
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)
Description for the changelog
A picture of a cute animal (not mandatory but encouraged)