-
Notifications
You must be signed in to change notification settings - Fork 375
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
Enable unit tests for Python 2.6 & 3.4 on Github Actions #3296
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,8 +411,12 @@ def emulate_assertListEqual(self, seq1, seq2, msg=None, seq_type=None): | |
diffMsg = '\n' + '\n'.join( | ||
difflib.ndiff(pprint.pformat(seq1).splitlines(), | ||
pprint.pformat(seq2).splitlines())) | ||
standardMsg = self._truncateMessage(standardMsg, diffMsg) | ||
msg = self._formatMessage(msg, standardMsg) | ||
# _truncateMessage and _formatMessage are not defined on Python 2.6; output the entire diff in that case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue has always been here. The only reason I noticed it is because a test that uses assertListEqual failed for an unrelated issue and this code raised an exception. |
||
if sys.version_info < (2, 7): | ||
msg = standardMsg + "\n****************************************\n" + diffMsg | ||
else: | ||
standardMsg = self._truncateMessage(standardMsg, diffMsg) | ||
msg = self._formatMessage(msg, standardMsg) | ||
self.fail(msg) | ||
|
||
def emulate_assertIsInstance(self, obj, object_type, msg=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,41 +18,104 @@ | |
# * Run unit tests: docker run --rm -v WALinuxAgent:/home/waagent/WALinuxAgent python2.6 bash --login -c run-tests | ||
# * Run tests that require root: docker run --user root --rm -v WALinuxAgent:/home/waagent/WALinuxAgent python2.6 bash --login -c run-sudo-tests | ||
# | ||
FROM ubuntu:16.04 | ||
FROM mcr.microsoft.com/mirror/docker/library/ubuntu:24.04 | ||
ARG PYTHON_VERSION | ||
LABEL description="Test environment for WALinuxAgent" | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
RUN \ | ||
apt-get update && \ | ||
apt-get -y install curl bzip2 sudo && \ | ||
groupadd waagent && \ | ||
useradd --shell /bin/bash --create-home -g waagent waagent && \ | ||
curl -sSf --retry 5 -o /tmp/python-${PYTHON_VERSION}.tar.bz2 https://dcrdata.blob.core.windows.net/python/python-${PYTHON_VERSION}.tar.bz2 && \ | ||
tar xjf /tmp/python-${PYTHON_VERSION}.tar.bz2 --directory / && \ | ||
rm -f /tmp/python-${PYTHON_VERSION}.tar.bz2 && \ | ||
echo $'\ | ||
\n\ | ||
cd /home/waagent \n\ | ||
source /home/waagent/virtualenv/python'${PYTHON_VERSION}/bin/activate$' \n\ | ||
function run-tests { \n\ | ||
nosetests --verbose --ignore-files test_cgroupconfigurator_sudo.py /home/waagent/WALinuxAgent/tests \n\ | ||
} \n\ | ||
function run-sudo-tests { \n\ | ||
nosetests --verbose /home/waagent/WALinuxAgent/tests/ga/test_cgroupconfigurator_sudo.py \n\ | ||
} \n\ | ||
' | tee -a /home/waagent/.profile >> ~/.profile && \ | ||
sed -i 's/mesg n || true/tty -s \&\& mesg n/' ~/.profile && \ | ||
: | ||
|
||
# | ||
# TODO: Some unit tests create helper scripts that use 'python3' as shebang; we should probably port them to Bash, but installing Python 3 as a workaround for now. | ||
# | ||
RUN \ | ||
if [[ "${PYTHON_VERSION}" == "2.6" ]]; then \ | ||
apt-get -y install python3; \ | ||
RUN <<.. | ||
# | ||
# Install the Python venv | ||
# | ||
apt-get update | ||
apt-get -y install curl bzip2 sudo | ||
groupadd waagent | ||
useradd --shell /bin/bash --create-home -g waagent waagent | ||
curl -sSf --retry 5 -o /tmp/python-${PYTHON_VERSION}.tar.bz2 https://dcrdata.blob.core.windows.net/python/python-${PYTHON_VERSION}.tar.bz2 | ||
tar xjf /tmp/python-${PYTHON_VERSION}.tar.bz2 --directory / | ||
chown -R waagent:waagent /home/waagent # The UID:GID in the tarball may not match those of the user, so we need to fix that. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ubuntu 24 has a new user, ubuntu, with PID 1000 so now the PID in the tarball does not match waagent's (which now gets 1001) |
||
rm -f /tmp/python-${PYTHON_VERSION}.tar.bz2 | ||
|
||
# | ||
# Add the convenience functions to the profiles of waagent and root | ||
# | ||
(cat << ... | ||
cd /home/waagent | ||
source /home/waagent/virtualenv/python${PYTHON_VERSION}/bin/activate | ||
function run-tests { | ||
nosetests --verbose --ignore-files test_cgroupconfigurator_sudo.py /home/waagent/WALinuxAgent/tests | ||
} | ||
function run-sudo-tests { | ||
nosetests --verbose /home/waagent/WALinuxAgent/tests/ga/test_cgroupconfigurator_sudo.py | ||
} | ||
... | ||
) | tee -a /home/waagent/.profile >> ~/.profile | ||
sed -i 's/mesg n || true/tty -s \&\& mesg n/' ~/.profile | ||
|
||
# | ||
# TODO: Some unit tests create helper scripts that use 'python3' as shebang; we should probably port them to Bash, but installing Python 3 as a workaround for now. | ||
# | ||
if [[ "${PYTHON_VERSION}" == "2.6" ]]; then | ||
apt-get -y install python3 | ||
fi | ||
# | ||
# The python 2.6 and 3.4 virtual environments have hard dependencies on some of the shared libraries in Open SSL 1.0 (e.g libssl.so.1.0.0), which is not available beyond Ubuntu 16. | ||
# Modules like hashlib and ssl will fail to import on more recent versions of Ubuntu. The Agent uses classes HTTPSConnection and HTTPS, which depend on the ssl module. Those classes | ||
# are added conditionally on the import of ssl on httplib.py and http/client.py with code similar to: | ||
# | ||
# try: | ||
# import ssl | ||
# except ImportError: | ||
# pass | ||
# else: | ||
# class HTTPSConnection(HTTPConnection):... | ||
# class HTTPS(HTTP):... | ||
# def FakeSocket (sock, sslobj):... | ||
# | ||
# Since the import fails, the classes will be undefined. To work around that, we define dummy items that raise NotImplementedError. The unit tests mock those classes anyway, so the | ||
# actual implementation does not really matter. | ||
# | ||
if [[ "${PYTHON_VERSION}" == "2.6" ]]; then | ||
cat >> /opt/python/2.6.9/lib/python2.6/httplib.py << ... | ||
# Added by WALinuxAgent dev team to work around the lack of OpenSSL 1.0 shared libraries | ||
class HTTPSConnection(HTTPConnection): | ||
default_port = HTTPS_PORT | ||
|
||
def __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): | ||
raise NotImplementedError() | ||
|
||
def connect(self): | ||
raise NotImplementedError() | ||
|
||
__all__.append("HTTPSConnection") | ||
|
||
class HTTPS(HTTP): | ||
_connection_class = HTTPSConnection | ||
|
||
def __init__(self, host='', port=None, key_file=None, cert_file=None, strict=None): | ||
raise NotImplementedError() | ||
|
||
def FakeSocket (sock, sslobj): | ||
raise NotImplementedError() | ||
... | ||
|
||
elif [[ "${PYTHON_VERSION}" == "3.4" ]]; then | ||
cat >> /opt/python/3.4.8/lib/python3.4/http/client.py << ... | ||
# Added by WALinuxAgent dev team to work around the lack of OpenSSL 1.0 shared libraries | ||
class HTTPSConnection(HTTPConnection): | ||
default_port = HTTPS_PORT | ||
|
||
def __init__(self, host, port=None, key_file=None, cert_file=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None, *, context=None, check_hostname=None): | ||
raise NotImplementedError() | ||
|
||
def connect(self): | ||
raise NotImplementedError() | ||
|
||
__all__.append("HTTPSConnection") | ||
... | ||
fi | ||
.. | ||
|
||
USER waagent:waagent | ||
|
||
|
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.
hash_strings was being used only by the Monitor thread. It has a dependency on hashlib/OpenSSL. The Monitor thread does not really need a cryptographic hash, so I replaced it with Python's own hash function.