[Python3 migrate] Fix some type upgrade issue#7399
Merged
lerry-lee merged 2 commits intosonic-net:masterfrom Feb 7, 2023
Merged
[Python3 migrate] Fix some type upgrade issue#7399lerry-lee merged 2 commits intosonic-net:masterfrom
lerry-lee merged 2 commits intosonic-net:masterfrom
Conversation
Signed-off-by: Chun'ang Li <chunangli@microsoft.com>
Signed-off-by: Chun'ang Li <chunangli@microsoft.com>
6 tasks
wangxin
approved these changes
Feb 7, 2023
kellyyeh
pushed a commit
to kellyyeh/sonic-mgmt
that referenced
this pull request
Mar 31, 2023
What is the motivation for this PR? Python3 migrate fix key error. How did you do it? Add explicit convert. How did you verify/test it? Run TC and no key error. Signed-off-by: Chun'ang Li <chunangli@microsoft.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of PR
Some test cases like
pc/test_lag_2.pyfailed in Python3 environment, caused by key error like the below:Actually, it is caused by these codes (When parsing conn_graph_facts):
In Python2 env, the

dut_host(the key in dev_conn.items()) isunicodeobject, but in Python3 isAnsileUnsafeTextobject, because Ansible marks all strings inside returned data as Unsafe.So, we convert the
AnsileUnsafeTexttostrin Py3 after got ansible return value.Other fixes:
In Python2, dict.keys()/dict.values() returns list object, but in Python3 returns an iterable but not indexable object. So that need to convert to list.
The Python "NameError name 'unicode' is not defined" occurs when using the unicode object in Python 3. To solve the error, replace all calls to unicode() with str() because unicode was renamed to str in Python 3.
Type of change
Back port request
Approach
What is the motivation for this PR?
Python3 migrate fix key error.
How did you do it?
Add explicit convert.
How did you verify/test it?
Run TC and no key error.
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation