-
Notifications
You must be signed in to change notification settings - Fork 738
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
[python3 migration] Added Python3 support for new test cases #4867
[python3 migration] Added Python3 support for new test cases #4867
Conversation
ansible/library/lldp_facts.py
Outdated
@@ -258,7 +258,7 @@ def main(): | |||
|
|||
lldp_data = dict() | |||
|
|||
for intf in lldp_rem_sys.viewkeys(): | |||
for intf in lldp_rem_sys.keys(): |
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.
for loop will iter over keys by default. keys method call is redundant.
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.
Done. Thanks
tests/common/devices/sonic.py
Outdated
nexthop_ip = ipaddress.ip_address(unicode(m.group(1))) | ||
nexthop_ip = ipaddress.ip_address(m.group(1).encode().decode("utf-8")) |
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.
Here and later you can use six for porting code from py2 to py3 and wise verse. For example six.text_type to always work with unicode in both py versions and six.binary_type can be used to always work with bytes in both py versions.
Are you sure you need to do sequential call of opposite methods encode
and decode
? what is the type of m.group(1)
and how does it change after conversion?
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.
Done
@@ -26,8 +26,7 @@ def __init__(self, msg, results=None): | |||
self.results = results | |||
|
|||
def _to_string(self): | |||
return unicode(u"{}, Ansible Results =>\n{}".format(self.message, dump_ansible_results(self.results)))\ | |||
.encode('ascii', 'backslashreplace') | |||
return "{}, Ansible Results =>\n{}".format(self.message, dump_ansible_results(self.results)).encode().decode("utf-8") |
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.
What's the reason for calling encode()
followed by decode("utf-8")
here?
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.
This approach is used for backward compatibility of code between different versions of Python. Ansible returns different types of dump depending on Python versions.
@OleksandrKozodoi Thanks for the efforts of making the scripts working for python3! |
@wangxin All scripts were tested using python2 and python3 versions. All necessary dependencies for testing python2&3 compatible will be available in python venv of the sonic-mgmt docker container after merging 9277. These changes allow running tests on different versions in a single sonic-mgmt container. Thanks! |
LGTM, @OleksandrKozodoi Can you help resolve the conflicts? |
f7f8676
to
48b39b8
Compare
Signed-off-by: Oleksandr Kozodoi <[email protected]>
Signed-off-by: Oleksandr Kozodoi <[email protected]>
Signed-off-by: Oleksandr Kozodoi <[email protected]>
Signed-off-by: Oleksandr Kozodoi <[email protected]>
48b39b8
to
9252d27
Compare
Looks like this commit cause failures: TypeError: () takes exactly 2 arguments (1 given) Issue happen when run tests from folder: qos/test_qos_sai.py It's related to file: tests/common/fixtures/ptfhost_utils.py Example of python traceback:
|
|
What is the motivation for this PR? Fix the issue reported in #4867, failures: TypeError: () takes exactly 2 arguments (1 given) The fix in #5605 still uses lambda which is not easy to read and may have compatibility issue. How did you do it? Use for loop and concentrate string together and append them to a list. How did you verify/test it? run tests/test_qos_sai.py Signed-off-by: Zhaohui Sun <[email protected]>
Signed-off-by: Oleksandr Kozodoi [email protected]
Description of PR
This PR includes necessary changes from #9277 for the setup of the Python3 virtual environment in the sonic-mgmt docker container.
Summary:
How to use Python3 environment for running test cases?
Type of change
Back port request
Approach
What is the motivation for this PR?
Migration of sonic-mgmt codebase from Python 2 to Python 3
How did you do it?
Updated codebase of sonic-mgmt for supporting Python3
How did you verify/test it?
Run test cases. Tests passed.
Any platform specific information?
SONiC Software Version: SONiC.master.60600-dirty-20211221.191419
Distribution: Debian 11.2
Kernel: 5.10.0-8-2-amd64
Build commit: 67e40b553
Build date: Tue Dec 21 19:22:34 UTC 2021
ASIC: barefoot
Supported testbed topology if it's a new test case?
t0, t1
Documentation