Skip to content

Fix compatibility issue between python2 and python3 in null_route test#6701

Merged
xwjiang-ms merged 1 commit intosonic-net:masterfrom
xwjiang-ms:pre-commit-fix-acl
Nov 2, 2022
Merged

Fix compatibility issue between python2 and python3 in null_route test#6701
xwjiang-ms merged 1 commit intosonic-net:masterfrom
xwjiang-ms:pre-commit-fix-acl

Conversation

@xwjiang-ms
Copy link
Contributor

@xwjiang-ms xwjiang-ms commented Nov 2, 2022

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205

Approach

What is the motivation for this PR?

I fixed style issues in null_route test, but imported a compatibility issue.
In python3, str type contains unicode characters, but if we use str in python2 instead of unicode, will cause AddressValueError. Python2 can only recognize unicode IPv4/v6 address
Relate PR: #6679

How did you do it?

Use string.encode().decode() instead of str() or unicode(), and in python2, we will get unicode IPv4/v6 address, in python3, we will get IPv4/v6 address string

How did you verify/test it?

Run acl/null_route/test_null_route_helper.py test

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

What is the motivation for this PR?
I fixed style issues in `null_route` test, but imported a compatibility
issue.
In python3, str type contains unicode characters, but if we use str in
python2 instead of unicode, will cause AddressValueError, python2 can
only recognize unicode IPv4/v6 address

How did you do it?
Use string.encode().decode() instead of str() or unicode(), and in
python2, we will get unicode IPv4/v6 address, in python3, we will get
IPv4/v6 address string

How did you verify/test it?
Run `acl/null_route/test_null_route_helper.py` test

Any platform specific information?
Supported testbed topology if it's a new test case?
@xwjiang-ms xwjiang-ms merged commit 29c30ab into sonic-net:master Nov 2, 2022
@xwjiang-ms xwjiang-ms deleted the pre-commit-fix-acl branch November 2, 2022 04:43
wangxin pushed a commit that referenced this pull request Dec 19, 2022
…est (#6701)

What is the motivation for this PR?
I fixed style issues in `null_route` test, but imported a compatibility
issue.
In python3, str type contains unicode characters, but if we use str in
python2 instead of unicode, will cause AddressValueError, python2 can
only recognize unicode IPv4/v6 address

How did you do it?
Use string.encode().decode() instead of str() or unicode(), and in
python2, we will get unicode IPv4/v6 address, in python3, we will get
IPv4/v6 address string

How did you verify/test it?
Run `acl/null_route/test_null_route_helper.py` test

Any platform specific information?
Supported testbed topology if it's a new test case?
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.

2 participants