[test][bionic] Force python3 and utf-8 encoding
bionic's /usr/bin/python is python2. Encoding and python2/python3 is.... complicated.
Those tests already run on py3 which is the default for Ubuntu Focal and Fedora 34.
This change symlinks /usr/local/bin/python to python3 within the Bionic container
and changes all tools to use "#!/usr/bin/env python" shebang instead of "#!/usr/bin/python"
which allows to use the default python set by the environment.
To add insult to injury. Python 3.6 still needs a bit of help to default to UTF-8
which can be achieved with the env var `PYTHONIOENCODING` to `utf-8`.
Since python 3.7, [UTF-8 mode is enabled by default when the locale is C or POSIX](https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep540).
Some more details about this problem can be found here: https://vstinner.github.io/posix-locale.html#misconfigured-locales-in-docker-images
Illustration:
```
root@bionic:/# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
root@bionic:/# python2
Python 2.7.17 (default, Jul 1 2022, 15:56:32)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("%s" % u'\xb7')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 0: ordinal not in range(128)
>>>
root@bionic:/# python3
Python 3.6.9 (default, Jun 29 2022, 11:45:57)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("%s" % u'\xb7')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\xb7' in position 0: ordinal not in range(128)
>>>
root@bionic:/# PYTHONIOENCODING=utf-8 python3
Python 3.6.9 (default, Jun 29 2022, 11:45:57)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("%s" % u'\xb7')
·
```
On Focal:
```
root@focal:/# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
root@focal:/# python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("%s" % u'\xb7')
·
```
diff --git a/tools/opensnoop.py b/tools/opensnoop.py
index 0b48c81..679b8fe 100755
--- a/tools/opensnoop.py
+++ b/tools/opensnoop.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
# @lint-avoid-python-3-compatibility-imports
#
# opensnoop Trace open() syscalls.