-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Azure Pipeline for Python 2.6 & 3.4 Unit Tests (#3284)
--------- Co-authored-by: narrieta@microsoft <narrieta>
- Loading branch information
Showing
8 changed files
with
200 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# Environment to execute the WALinuxAgent unit tests for some versions of Python that have reached EOL and are no longer available | ||
# in the official repositories. | ||
# | ||
# To build the image, set the PYTHON_VERSION argument to 2.6 or 3.4: | ||
# | ||
# * docker build -t python2.6 --build-arg PYTHON_VERSION=2.6 . | ||
# * docker build -t python3.4 --build-arg PYTHON_VERSION=3.4 . | ||
# | ||
# We add a couple of convenience functions to execute the unit tests to the profiles of waagent and root; these can be useful in interactive sessions. Note | ||
# that these functions assume the root of the source code has been mounted at /home/waagent/WALinuxAgent. | ||
# | ||
# Also, we precede "mesg n" with "tty -s" in root's profile to avoid the "standard input is not a tty" message when not running the container interactively. | ||
# | ||
# Sample commands: | ||
# | ||
# * Start an interactive session: docker run --rm -it -v WALinuxAgent:/home/waagent/WALinuxAgent python2.6 bash --login | ||
# * 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 | ||
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; \ | ||
fi | ||
|
||
USER waagent:waagent | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
if [[ "$#" -ne 1 || ! "$1" =~ ^2\.6|3\.4$ ]]; then | ||
echo "Usage: execute_tests.sh 2.6|3.4" | ||
exit 1 | ||
fi | ||
|
||
EXIT_CODE=0 | ||
PYTHON_VERSION=$1 | ||
CONTAINER_IMAGE="waagenttests.azurecr.io/python$PYTHON_VERSION" | ||
CONTAINER_LOGS_DIRECTORY="/home/waagent/logs" | ||
CONTAINER_SOURCES_DIRECTORY="/home/waagent/WALinuxAgent" | ||
NOSETESTS_OPTIONS="--verbose --with-xunit" | ||
|
||
# | ||
# Give ownership of the logs directory to 'waagent' (UID 1000) | ||
# | ||
sudo chown 1000 "$LOGS_DIRECTORY" | ||
|
||
# | ||
# Give the current user access to the Docker daemon | ||
# | ||
sudo usermod -aG docker $USER | ||
newgrp docker < /dev/null | ||
|
||
# | ||
# Pull the container image and execute the tests | ||
# | ||
az acr login --name waagenttests --username "$CR_USER" --password "$CR_SECRET" | ||
|
||
docker pull "$CONTAINER_IMAGE" | ||
|
||
printf "\n***************************************** Running tests for Python $PYTHON_VERSION *****************************************\n\n" | ||
|
||
TEST_SUITE_OPTIONS="--xunit-testsuite-name='Python $PYTHON_VERSION' --xunit-file=$CONTAINER_LOGS_DIRECTORY/waagent-$PYTHON_VERSION.junit.xml" | ||
|
||
set -x | ||
docker run --rm \ | ||
--volume "$BUILD_SOURCESDIRECTORY":"$CONTAINER_SOURCES_DIRECTORY" \ | ||
--volume "$LOGS_DIRECTORY":"$CONTAINER_LOGS_DIRECTORY" \ | ||
"$CONTAINER_IMAGE" \ | ||
bash --login -c "nosetests $NOSETESTS_OPTIONS $TEST_SUITE_OPTIONS --ignore-files test_cgroupconfigurator_sudo.py $CONTAINER_SOURCES_DIRECTORY/tests" \ | ||
|| EXIT_CODE=$(($EXIT_CODE || $?)) | ||
set +x | ||
|
||
printf "\n************************************** Running tests for Python $PYTHON_VERSION [sudo] **************************************\n\n" | ||
|
||
TEST_SUITE_OPTIONS="--xunit-testsuite-name='Python $PYTHON_VERSION [sudo]' --xunit-file=$CONTAINER_LOGS_DIRECTORY/waagent-sudo-$PYTHON_VERSION.junit.xml" | ||
|
||
set -x | ||
docker run --rm \ | ||
--user root \ | ||
--volume "$BUILD_SOURCESDIRECTORY":"$CONTAINER_SOURCES_DIRECTORY" \ | ||
--volume "$LOGS_DIRECTORY":"$CONTAINER_LOGS_DIRECTORY" \ | ||
"$CONTAINER_IMAGE" \ | ||
bash --login -c "nosetests $NOSETESTS_OPTIONS $TEST_SUITE_OPTIONS $CONTAINER_SOURCES_DIRECTORY/tests/ga/test_cgroupconfigurator_sudo.py"\ | ||
|| EXIT_CODE=$(($EXIT_CODE || $?)) | ||
set +x | ||
|
||
exit "$EXIT_CODE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
parameters: | ||
- name: python_2_6 | ||
displayName: Python 2.6 | ||
type: boolean | ||
default: true | ||
- name: python_3_4 | ||
displayName: Python 3.4 | ||
type: boolean | ||
default: true | ||
|
||
pool: | ||
name: waagent-pool | ||
|
||
jobs: | ||
- job: SelectPythonVersions | ||
displayName: "Select Python versions" | ||
steps: | ||
- bash: | | ||
# Create the test matrix, which is a JSON object with the selected Python versions, e.g. { "Python_2_6":{"VERSION":"2.6"}, "Python_3_4":{"VERSION":"3.4"} } | ||
declare -a PYTHON_VERSIONS=() | ||
if [ ${{ parameters.python_2_6 }} == "True" ]; then | ||
PYTHON_VERSIONS+=('"Python_2_6":{"VERSION":"2.6"}') | ||
fi | ||
if [ ${{ parameters.python_3_4 }} == "True" ]; then | ||
PYTHON_VERSIONS+=('"Python_3_4": {"VERSION":"3.4"}') | ||
fi | ||
PYTHON_VERSIONS=$(echo ${PYTHON_VERSIONS[@]} | sed 's/ /, /' | sed 's/.*/{ \0 }/') | ||
echo "Python versions: $PYTHON_VERSIONS" | ||
echo "##vso[task.setvariable variable=PYTHON_VERSIONS;isOutput=true]$PYTHON_VERSIONS" | ||
name: "SetPythonVersions" | ||
- job: "ExecuteTests" | ||
displayName: "Execute tests" | ||
dependsOn: SelectPythonVersions | ||
timeoutInMinutes: 15 | ||
strategy: | ||
matrix: $[ dependencies.SelectPythonVersions.outputs['SetPythonVersions.PYTHON_VERSIONS'] ] | ||
steps: | ||
- task: AzureKeyVault@2 | ||
displayName: "Fetch connection info" | ||
inputs: | ||
azureSubscription: $(connection_info) | ||
KeyVaultName: 'waagenttests' | ||
SecretsFilter: 'CR-USER, CR-SECRET' | ||
|
||
- bash: | | ||
mkdir $(Agent.TempDirectory)/logs | ||
$(Build.SourcesDirectory)/tests/python_eol/execute_tests.sh $(VERSION) | ||
displayName: "Execute tests" | ||
continueOnError: true | ||
env: | ||
CR_USER: $(CR-USER) | ||
CR_SECRET: $(CR-SECRET) | ||
LOGS_DIRECTORY: $(Agent.TempDirectory)/logs | ||
- task: PublishTestResults@2 | ||
displayName: 'Publish test results' | ||
condition: always() | ||
inputs: | ||
testResultsFormat: 'JUnit' | ||
testResultsFiles: 'waagent*.junit.xml' | ||
searchFolder: $(Agent.TempDirectory)/logs | ||
failTaskOnFailedTests: true |