-
Notifications
You must be signed in to change notification settings - Fork 812
Replace py-swsssdk with swsscommon #5926
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
Merged
liuh-80
merged 4 commits into
sonic-net:master
from
liuh-80:dev/liuh/update-to-swsscommon
Jul 13, 2022
+28
−8
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,8 +114,16 @@ def get_ifindex(duthost, port): | |
|
||
def get_port_index(duthost, port): | ||
py_version = 'python' if '201911' in duthost.os_version else 'python3' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
cmd = "{} -c \"from swsssdk import port_util; print(port_util.get_index_from_str(\'{}\'))\"" | ||
index = duthost.shell(cmd.format(py_version, port))['stdout'] | ||
|
||
# if sonic_py_common.port_util exist, use port_util from sonic_py_common. | ||
util_lib = "swsssdk" | ||
cmd = "{} -c \"import pkgutil; print(pkgutil.find_loader(\'sonic_py_common.port_util\'))\"".format(py_version) | ||
class_exist = duthost.shell(cmd)['stdout'] | ||
if class_exist != "None": | ||
util_lib = "sonic_py_common" | ||
|
||
cmd = "{} -c \"from {} import port_util; print(port_util.get_index_from_str(\'{}\'))\"" | ||
index = duthost.shell(cmd.format(py_version, util_lib, port))['stdout'] | ||
return index | ||
|
||
# ---------------------------------------------------------------------------------- | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it compatible to old images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code change may break on old device, I will test with 2018 image on by devbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Manually test on 201911 and latest master branch. this script and related UT does not run on 201811 version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sonic-mgmt master branch will not be used to test 201811 and older branch images. If this is the truth, then it is good enough, and no need to improve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix is necessary because SonicDBConfig.load_sonic_global_db_config() added on 2021, so on 2019 swsscommon exist but we still need use swsssdk.