Python 2&3 compatibility
Since Python 2 is approaching its end of life, Server Automation infrastructure has to be updated to Python 3. Future Server Automation versions will run on Python 3. This document is an overview of the preparation needed for the next versions of Server Automation which will run on Python 3.
Existing SA releases will not get updated to Python 3 , the below packages will only add support for running Python 2&3 compatible code and to start customer content python codebase migration process from Python 2 to Python 3.
This Python code migration must be carried out before upgrading to versions newer than SA 2018.08.
How to get SA ready for porting Python2 code to Python3
To enable the python 2 & 3 compatibility on your SA cores/satellites/agents you need to install the below packages:
- SRVA_00265 - server automation 2018.08.002 rollup
- SRVA_00266 - server automation 2018.08.002 Agents
- SRVA_00267 - server automation 2018.08.002 HPSAPython
- SRVA_00261 – server automation 10.60.012 rollup
- SRVA_00263 - server automation 10.60.012 Agents
- SRVA_00263 - server automation 10.60.012 HPSApython
- SRVA_00271 - server automation 10.51.011 rollup
- SRVA_00269 - server automation 10.51.011 Agents
- SRVA_00270 - server automation 10.51.011 HPSAPython
- NA- server automation 10.23.015 rollup
- NA - server automation 10.23.015 Agents
- NA - server automation 10.23.015 HPSAPython
- A support case has to be opened to request a new set of Agents which are required for 2020 and newer Security and Compliance content from marketplace.
To install the server automation rollup follow the installation instructions from the patch.sh.txt. The agents have the installation instructions in the AGENT_README.txt and the HPSAPython package can be installed following the instructions from the README.txt.
How to port your python scripts
You have a choice between two tools in porting your code automatically: Futurize and Modernize. Which tool you choose will depend on how much like Python 3 you want your code to be.
Futurize does its best to make Python 3 idioms and practices exist in Python 2, e.g. backporting the bytes type from Python 3 so that you have semantic parity between the major versions of Python.
Modernize, on the other hand, is more conservative and targets a Python 2/3 subset of Python, directly relying on ‘six’ to help provide compatibility.
As Python 3 is the future, it might be best to consider Futurize to begin adjusting to any new practices that Python 3 introduces which you are not accustomed to yet. Regardless of which tool you choose, they will update your code to run under Python 3 while staying compatible with the version of Python 2 you started with. Depending on how conservative you want to be, you may want to run the tool over your test suite first and visually inspect the diff to make sure the transformation is accurate. After you have transformed your test suite and verified that all the tests still pass as expected, then you can transform your application code knowing that any tests which fail is a translation failure. Unfortunately the tools can’t automate everything to make your code work under Python 3 and so there are a handful of things you will need to update manually to get full Python 3 support (which of these steps are necessary vary between the tools).
A detailed description that should be followed for this process can be found in the official documentation. For each tool there is an official documentation that must be consulted and followed.
The needed libraries are delivered and available in the python delivered with SA. The versions of the libraries are future-0.17.1 for futurize and six-1.11.0 for modernize. These versions have to be used during the code porting.
We strongly recommend to do the code porting in test environments first. Neither of the two solutions offer a direct or clean code porting process, there will be issues you have to solve manually.
Note: New content should be developed with Python 3 compatibility in mind.
Python 2&3 official documentation - https://docs.python.org/3/howto/pyporting.html