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

[sonic-utilities][sonic-py-common] Move logic to get port config file path to sonic-py-common and update sonic-utilities to comply #5264

Merged
merged 18 commits into from
Sep 4, 2020

Conversation

vdahiya12
Copy link
Contributor

This PR addresses fixes in sonic-py-common to imitate the behavior inside
sonic-cfggen. Essentially this is a fix for accessing the port-config file.
First check if there is a platform.json file for config generation
and then for legacy port_config.ini.
Also updating the sub-module sonic-utilities.

sonic-utilities update submodule includes all these PR's

Fix pfcwd stats crash with invalid queue name (#1077)
[show][bgp]Display the Total number of neighbors in the show ip bgp(v6) summary. (#1079)
[config] Update SONiC Environment Vars When Loading Minigraph (#1073)
Multi asic platform changes for interface, portchannel commands (#878)
Update Command-Reference.md (#1075)
[filter-fdb] Fix Filter FDB With IPv6 Present in Config DB (#1059)
[config] Remove _get_breakout_cfg_file_name helper function (#1069)
[SHOW][BGP] support show ip(v6) bgp summary for multi asic platform (#1064)
[fanshow] Display other fan status, such as Updating (#1014)
Add ip_prefix len based on proxy_arp status (#1046)
Enable the platform specific ssd firmware upgrade during reboot (#954)
[show][cli[show interface portchannel support for Multi ASIC (#1005)
support show interface commands for multi ASIC platforms (#1006)

Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com

Fix pfcwd stats crash with invalid queue name (sonic-net#1077)
[show][bgp]Display the Total number of neighbors in the show ip bgp(v6) summary. (sonic-net#1079)
[config] Update SONiC Environment Vars When Loading Minigraph (sonic-net#1073)
Multi asic platform changes for interface, portchannel commands (sonic-net#878)
Update Command-Reference.md (sonic-net#1075)
[filter-fdb] Fix Filter FDB With IPv6 Present in Config DB (sonic-net#1059)
[config] Remove _get_breakout_cfg_file_name helper function (sonic-net#1069)
[SHOW][BGP] support show ip(v6) bgp summary for multi asic platform (sonic-net#1064)
[fanshow] Display other fan status, such as Updating (sonic-net#1014)
Add ip_prefix len based on proxy_arp status (sonic-net#1046)
Enable the platform specific ssd firmware upgrade during reboot (sonic-net#954)
[show][cli[show interface portchannel support for Multi ASIC (sonic-net#1005)
support show interface commands for multi ASIC platforms (sonic-net#1006)

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
fix the build

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
src/sonic-py-common/sonic_py_common/device_info.py Outdated Show resolved Hide resolved
src/sonic-py-common/sonic_py_common/device_info.py Outdated Show resolved Hide resolved
port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))
if asic:
port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI))
port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))
Copy link
Contributor

Choose a reason for hiding this comment

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

line 199 and 202 are appending the same file. The list from the sonic-config-engine is:

    port_config_candidates.append(os.path.join(HWSKU_ROOT_PATH, PORT_CONFIG_INI))
    if hwsku:
        if platform:
            if asic:
                port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI))
            port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI))
        port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI))
        port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI))

    elif platform and not hwsku:
        port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, PORT_CONFIG_INI))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. the second is no longer needed.

Copy link
Contributor

@jleveque jleveque Aug 27, 2020

Choose a reason for hiding this comment

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

Question is, why were we checking for port_config.ini in this order?

  1. /usr/share/sonic/hwsku/
  2. /usr/share/sonic/device/<platform>/<hwsku>/<ASIC>/
  3. /usr/share/sonic/device/<platform>/<hwsku>/
  4. /usr/share/sonic/<platform>/

@samaity, @SuvarnaMeenakshi: Can you help answer this? Determining whether we are running inside a container versus in the host OS should now be handled by get_paths_to_platform_and_hwsku_dirs(). What is the new proper order with which to look for the port_config.ini file?

Before the addition of multi-ASIC functionality, the port_config.ini file was always located under the HwSKU directory, which, in the host OS was at /usr/share/sonic/device/<platform>/<hwsku>/ and in the containers was mounted at /usr/share/sonic/hwsku/. Why did we start checking the <platform> directory? Is there now a case where port_config.ini will reside directly under the platform directory? That has never been the case as far as I'm aware.

I believe the proper method for finding the port_config.ini file now that we have multi-ASIC functionality should be as simple as this:

# This function will return `/usr/share/sonic/hwsku/` as hwsku_path if run inside a container
# or `/usr/share/sonic/device/<platform>/<hwsku>/` if run in the host OS
(platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs()

if asic:
    port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI))
else:
    port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))

Please correct me if I am wrong.

fix builds

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Copy link
Contributor

@jleveque jleveque left a comment

Choose a reason for hiding this comment

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

As discussed, please also remove the get_port_config_file_name() function from portconfig.py as you had done in #5253, and close that PR as it will be redundant to this one.

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12
Copy link
Contributor Author

As discussed, please also remove the get_port_config_file_name() function from portconfig.py as you had done in #5253, and close that PR as it will be redundant to this one.

fixed

Comment on lines 199 to 202
port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))
if asic:
port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI))
port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI))
Copy link
Contributor

@jleveque jleveque Aug 28, 2020

Choose a reason for hiding this comment

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

I believe we should be able to simplify this as follows, but will wait for input from @samaity and @SuvarnaMeenakshi in case recent changes have altered this:

    if asic:
        port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI))
    else:
        port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the above suggested simplification looks good. If asic is defined, then platform/hwsku/port_config.ini will not be present as per current design.
In the previous code, I do not see port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI)). being directly used, and is used only if hwsku is not defined. Any reason for removing that check?

Copy link
Contributor

@jleveque jleveque Aug 29, 2020

Choose a reason for hiding this comment

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

Yes, the above suggested simplification looks good. If asic is defined, then platform/hwsku/port_config.ini will not be present as per current design.

Great. Thanks for the confirmation!

In the previous code, I do not see port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI)). being directly used, and is used only if hwsku is not defined. Any reason for removing that check?

Because port_config.ini has never resided directly under the <platform> directory (unless something changed recently), as it has always been hardware SKU-specific. That's one of the reasons I'm asking these questions. I don't believe that is a valid check, and I want to confirm that it can be removed. @samaity: It appears you added this directory as a candidate. What was your reasoning?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jleveque , As I have understood till now and also during platform.json file porting, the order was like below.

/usr/share/sonic/hwsku/
/usr/share/sonic/device/<platform>/<hwsku>/
/usr/share/sonic/platform/<hwsku>/
/usr/share/sonic/<hwsku>/

So, I followed the same, but yeah, I guess, I mistakenly added the directory. I don't think it's needed for port_config.ini. however, platform.json will be under the platform directory. So we are safe with the changes.

Copy link
Contributor

@jleveque jleveque Sep 2, 2020

Choose a reason for hiding this comment

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

So to finalize/summarize for posterity, platform.json will always be found under:

  • /usr/share/sonic/device/<platform>/ in the host OS
  • /usr/share/sonic/platform/ inside a container

And port_config.ini will always be found under:

  • /usr/share/sonic/device/<platform>/<hwsku>/<ASIC index>/ in the host OS of a multi-ASIC switch
  • /usr/share/sonic/device/<platform>/<hwsku>/ in the host OS of a single-ASIC switch
  • /usr/share/sonic/hwsku/<ASIC index>/ (also /usr/share/sonic/platform/<hwsku>/<ASIC index>/) in a container on a multi-ASIC switch
  • /usr/share/sonic/hwsku/ (also /usr/share/sonic/platform/<hwsku>/) in a container on a single-ASIC switch

@SuvarnaMeenakshi, @samaity: Correct?

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12
Copy link
Contributor Author

retest this please

@jleveque
Copy link
Contributor

jleveque commented Sep 1, 2020

@vdahiya12: The PR builds are now failing because the sonic-config-engine unit tests do not run on any platform, therefore sonic-py-common.get_platform() returns None. Any unit test which calls get_platform() or another sonic-py-common function which calls get_platform() (e.g., get_paths_to_platform_and_hwsku_dirs() or get_port_config_file_name()) should mock those function(s), as they are part of a separate package, it is not testing them directly. Can you please add the appropriate mocks to the sonic-config-engine tests in the PR to allow the unit tests to pass?

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12
Copy link
Contributor Author

Retest vsimage please

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
jleveque
jleveque previously approved these changes Sep 2, 2020
@vdahiya12
Copy link
Contributor Author

Retest vsimage please

@jleveque jleveque changed the title [sonic-utilities][sonic-py-common] update sonic-utilities submodule with fix in get_path_to_port_config_file() inside sonic-py-coomon [sonic-utilities][sonic-py-common] Move logic to get port config file path to sonic-py-common and update sonic-utilities to comply Sep 3, 2020
@vdahiya12
Copy link
Contributor Author

Retest vsimage please

2 similar comments
@vdahiya12
Copy link
Contributor Author

Retest vsimage please

@vdahiya12
Copy link
Contributor Author

Retest vsimage please

@sonic-net sonic-net deleted a comment from arlakshm Sep 3, 2020
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
src/sonic-config-engine/portconfig.py Show resolved Hide resolved
src/sonic-config-engine/sonic-cfggen Show resolved Hide resolved
src/sonic-py-common/sonic_py_common/device_info.py Outdated Show resolved Hide resolved
src/sonic-py-common/sonic_py_common/device_info.py Outdated Show resolved Hide resolved
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12 vdahiya12 merged commit 679d8df into sonic-net:master Sep 4, 2020
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
… path to sonic-py-common and update sonic-utilities to comply (sonic-net#5264)

* [sonic-utilities]update submodule with fix

This PR addresses fixes in sonic-py-common to imitate the behavior inside
sonic-cfggen. Essentially this is a fix for accessing the port-config file.
First check if there is a platform.json file for config generation
and then for legacy port_config.ini.
Also updating the sub-module sonic-utilities.

Fix pfcwd stats crash with invalid queue name (sonic-net#1077)
[show][bgp]Display the Total number of neighbors in the show ip bgp(v6) summary. (sonic-net#1079)
[config] Update SONiC Environment Vars When Loading Minigraph (sonic-net#1073)
Multi asic platform changes for interface, portchannel commands (sonic-net#878)
Update Command-Reference.md (sonic-net#1075)
[filter-fdb] Fix Filter FDB With IPv6 Present in Config DB (sonic-net#1059)
[config] Remove _get_breakout_cfg_file_name helper function (sonic-net#1069)
[SHOW][BGP] support show ip(v6) bgp summary for multi asic platform (sonic-net#1064)
[fanshow] Display other fan status, such as Updating (sonic-net#1014)
Add ip_prefix len based on proxy_arp status (sonic-net#1046)
Enable the platform specific ssd firmware upgrade during reboot (sonic-net#954)
[show][cli[show interface portchannel support for Multi ASIC (sonic-net#1005)
support show interface commands for multi ASIC platforms (sonic-net#1006)

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
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.

5 participants