Update ptf_runner to detect PTF image type and test#13644
Update ptf_runner to detect PTF image type and test#13644wangxin merged 20 commits intosonic-net:masterfrom
Conversation
- Modify http_api to work with Flask in Py3 environment - Modify exabgp configuration to be compatible with v4 - All PTF test scripts are Py3 compatible the 'py3' directory is no longer required and hence removed. - PTF path on PTF container is /usr/local/bin/ptf - Remove Python 3 virtual environment path /root/env-python3 and use Python 3 from global environment /usr/bin - Remove is_python3 from ptf_runner and update all callers
|
The pre-commit check detected issues in the files touched by this pull request. Detailed pre-commit check results: To run the pre-commit checks locally, you can follow below steps:
|
…; Modify ptf_runner to check environment and invoke appropriate ptf binary
|
These build failures have been fixed in the PR #14001 |
| http_api_py = '''\ | ||
| from flask import Flask, request | ||
| import sys | ||
| import six |
There was a problem hiding this comment.
Duplicated import six here.
There was a problem hiding this comment.
This import here is part of http_api_py which is the HTTP API processor generated as /usr/share/exabgp/http_api.py on the PTF container and is not for the exabgp.py.
ansible/library/exabgp.py
Outdated
| } | ||
| ''' | ||
|
|
||
| # exabgp v3 configuration file format |
There was a problem hiding this comment.
exabgp v4 means IPv4. So, the v3 here is misleading.
There was a problem hiding this comment.
I think the file here was referring to ExaBGP v3 in the context of version 3. And v4 is for ExaBGP v4 which supported Python 3. I can probably modify the variable name to indicate release v4 instead of just v4.
There was a problem hiding this comment.
Modified variable names to disambiguate.
ansible/library/exabgp.py
Outdated
| } | ||
| ''' | ||
|
|
||
| # exabgp v4 for py3 uses a different configuration file |
There was a problem hiding this comment.
exabgp v4 is kind of misleading as well.
There was a problem hiding this comment.
Modified variable names to disambiguate.
| [program:icmp_responder] | ||
| command=/root/env-python3/bin/python /opt/icmp_responder.py {{ icmp_responder_args }} | ||
| process_name=icmp_responder | ||
| environment=PATH="/root/env-python3/bin" |
There was a problem hiding this comment.
Why remove this line and keep /root/env-python3/bin/python in line 2? If the purpose is to use whatever default python binary, then line 2 should be updated as well. Eventually /root/env-python3 may be removed in "py3only" ptf image.
There was a problem hiding this comment.
The environment is not required for the script to run. To keep backporting simpler I have done away from modifying the path to invoke Python 3. This PR enables that sonic-net/sonic-buildimage#19813. Can you please review this too.
| logger.info('Test file path {}, in py3: {}'.format(test_fpath, in_py3)) | ||
| is_python3 = is_py3_compat(test_fpath) | ||
|
|
||
| ptf_cmd = None |
There was a problem hiding this comment.
Probably add some comments here to better explain the logic here.
The expectation of PTF image is either "mixed" or "py3only". "mixed" means that global python is python2. Python3 and dependent package is installed in /root/env-python3. "py3only" means that there is no python2. The global python is python3 and it has all required dependent packages.
For "mixed" ptf image, use python3 version ptf command to run python3 compatible ptf scripts. Use python2 version ptf command to run legacy python2 PTF scripts.
For "py3only" ptf image, always use the global python3 ptf command to run PTF scripts. Raise exception if ptf script is not python3 compatible.
There was a problem hiding this comment.
I have added the comment.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
The PR makes the following changes with backward compatibility (with older branches to allow backporting) - Enhances ptf_runner function to detect the python environment and set ptf binary path accordingly. Removes use of is_python3 Adds exabgp v4 config and uses six to keep the calls to Py2 and Py3 to support back-porting. The PR makes backward compatible changes to support - Python 2 only Python 2 + Python 3 (mixed environments with python3 virtualenv) Python 3 only environments What is the motivation for this PR? As Python 2 has reached EOL it is important to migrate all the PTF test scripts running in Python 2 to 3. How did you do it? Create a Python 3 only PTF image buildable with sonic-buildimage - Completed Migrate individual PTF test scripts to Python 3 - Completed (several PRs) Update test scripts to run in the Python 3 only environment - This PR How did you verify/test it? By running individual PTF tests on S6100 and Cisco 8111 devices. Any platform specific information? These changes are not platform specific.
The PR makes the following changes with backward compatibility (with older branches to allow backporting) - Enhances ptf_runner function to detect the python environment and set ptf binary path accordingly. Removes use of is_python3 Adds exabgp v4 config and uses six to keep the calls to Py2 and Py3 to support back-porting. The PR makes backward compatible changes to support - Python 2 only Python 2 + Python 3 (mixed environments with python3 virtualenv) Python 3 only environments What is the motivation for this PR? As Python 2 has reached EOL it is important to migrate all the PTF test scripts running in Python 2 to 3. How did you do it? Create a Python 3 only PTF image buildable with sonic-buildimage - Completed Migrate individual PTF test scripts to Python 3 - Completed (several PRs) Update test scripts to run in the Python 3 only environment - This PR How did you verify/test it? By running individual PTF tests on S6100 and Cisco 8111 devices. Any platform specific information? These changes are not platform specific.
The PR makes the following changes with backward compatibility (with older branches to allow backporting) -
ptf_runnerfunction to detect the python environment and setptfbinary path accordingly.is_python3The PR makes backward compatible changes to support -
Summary:
Fixes # Not applicable
Type of change
Back port request
Approach
What is the motivation for this PR?
As Python 2 has reached EOL it is important to migrate all the PTF test scripts running in Python 2 to 3.
How did you do it?
How did you verify/test it?
By running individual PTF tests on S6100 and Cisco 8111 devices.
Any platform specific information?
These changes are not platform specific.
Supported testbed topology if it's a new test case?
Not applicable