Skip to content

[sonic-py-common] Added an API to get file path containing SONiC version#6309

Merged
smaheshm merged 2 commits intosonic-net:masterfrom
smaheshm:devinfo
Jan 3, 2021
Merged

[sonic-py-common] Added an API to get file path containing SONiC version#6309
smaheshm merged 2 commits intosonic-net:masterfrom
smaheshm:devinfo

Conversation

@smaheshm
Copy link
Contributor

@smaheshm smaheshm commented Dec 28, 2020

- Why I did it

Added an API to get the file path containing SONiC version so that the API can be mocked during unit tests.

- How I did it

Added the API.

- How to verify it

Manual verification.

Last login: Mon Dec 28 18:32:34 2020 from 100.127.20.23
admin@str-s6000-acs-9:~$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sonic_py_common import device_info                                                                                                                                           
>>> device_info.get_sonic_version_file()
'/etc/sonic/sonic_version.yml'
>>> 

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

  • 201811
  • 201911
  • 202006

- Description for the changelog

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

@smaheshm smaheshm requested a review from judyjoseph December 28, 2020 18:58
@jleveque
Copy link
Contributor

The new get_sonic_version_file() function isn't called anywhere. How do we benefit from mocking it in unit tests?

@smaheshm
Copy link
Contributor Author

The new get_sonic_version_file() function isn't called anywhere. How do we benefit from mocking it in unit tests?

It will be used in 'sonic-utilities/config'.

sonic-net/sonic-utilities#1266

checkout config/main.py.

@smaheshm
Copy link
Contributor Author

retest mellanox please

@smaheshm
Copy link
Contributor Author

retest vsimage please

@smaheshm
Copy link
Contributor Author

retest mellanox please


def get_sonic_version_file():
if not os.path.isfile(SONIC_VERSION_YAML_PATH):
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Does all the current callers of this API, handle a return value of "None" ? If this is a mandatory file, we could raise an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is only one caller (sonic-net/sonic-utilities#1266). I'd say let's leave it to the caller to decide. Python will raise exception anyway.

@smaheshm
Copy link
Contributor Author

retest mellanox please

@smaheshm smaheshm merged commit c6253f6 into sonic-net:master Jan 3, 2021
lguohan pushed a commit that referenced this pull request Jan 3, 2021
…ion (#6309)

* [sonic-py-common] add an API to get file path containing SONiC version so that the API can be mocked for unit tests.
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.

4 participants