Skip to content
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

Collect test artifacts as a separate step in the test pipeline #2848

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests_e2e/pipeline/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ parameters:
- failed
- no

- name: collect_lisa_logs
displayName: Collect LISA logs
type: boolean
default: true

- name: keep_environment
displayName: Keep the test VMs (do not delete them)
type: string
Expand Down Expand Up @@ -117,6 +122,11 @@ jobs:
TEST_SUITES: ${{ parameters.test_suites }}
VM_SIZE: ${{ parameters.vm_size }}

- bash: $(Build.SourcesDirectory)/tests_e2e/pipeline/scripts/collect_artifacts.sh
displayName: "Collect test artifacts"
env:
COLLECT_LISA_LOGS: ${{ parameters.collect_lisa_logs }}

- publish: $(Build.ArtifactStagingDirectory)
artifact: 'artifacts'
displayName: 'Publish test artifacts'
Expand Down
69 changes: 69 additions & 0 deletions tests_e2e/pipeline/scripts/collect_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
#
# Moves the relevant logs to the staging directory
#
set -euxo pipefail

#
# The execute_test.sh script gives ownership of the log directory to the 'waagent' user in
# the Docker container; re-take ownership
#
sudo find "$LOGS_DIRECTORY" -exec chown "$USER" {} \;

#
# Move the logs for failed tests to a temporary location
#
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp
for log in $(grep -l MARKER-LOG-WITH-ERRORS "$LOGS_DIRECTORY"/*.log); do
mv "$log" "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp
done

#
# Move the environment logs to "environment_logs"
#
if ls "$LOGS_DIRECTORY"/env-*.log > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/environment_logs
mv "$LOGS_DIRECTORY"/env-*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/environment_logs
fi

#
# Move the rest of the logs to "test_logs"
#
if ls "$LOGS_DIRECTORY"/*.log > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/test_logs
mv "$LOGS_DIRECTORY"/*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/test_logs
fi

#
# Move the logs for failed tests to the main directory
#
if ls "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp/*.log > /dev/null 2>&1; then
mv "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp/*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"
fi
rmdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp

#
# Move the logs collected from the test VMs to vm_logs
#
if ls "$LOGS_DIRECTORY"/*.tgz > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/vm_logs
mv "$LOGS_DIRECTORY"/*.tgz "$BUILD_ARTIFACTSTAGINGDIRECTORY"/vm_logs
fi

#
# Move the main LISA log and the JUnit report to "runbook_logs"
#
# Note that files created by LISA are under .../lisa/<date>/<unique_name>"
#
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs
mv "$LOGS_DIRECTORY"/lisa/*/*/lisa-*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs
mv "$LOGS_DIRECTORY"/lisa/*/*/agent.junit.xml "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs

#
# Move the rest of the LISA logs to "lisa_logs"
#
if [[ ${COLLECT_LISA_LOGS,,} == 'true' ]]; then # case-insensitive comparison
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa_logs
mv "$LOGS_DIRECTORY"/lisa/*/*/* "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa_logs
fi

49 changes: 2 additions & 47 deletions tests_e2e/pipeline/scripts/execute_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ chmod a+w "$BUILD_SOURCESDIRECTORY"
# Create the directory where the Docker container will create the test logs and give ownership to 'waagent'
#
LOGS_DIRECTORY="$HOME/logs"
echo "##vso[task.setvariable variable=logs_directory]$LOGS_DIRECTORY"
mkdir "$LOGS_DIRECTORY"
sudo chown "$WAAGENT_UID" "$LOGS_DIRECTORY"

Expand Down Expand Up @@ -54,10 +55,6 @@ if [[ $VM_SIZE == "-" ]]; then
VM_SIZE=""
fi

# A test failure will cause automation to exit with an error code and we don't want this script to stop so we force the command
# to succeed and capture the exit code to return it at the end of the script.
echo "exit 0" > /tmp/exit.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the time outs not captured here in exit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azure pipelines kills the process after 60 min so the code to collect logs is not executed. the PR moves that code to a different step, which will be executed after this one is killed


docker run --rm \
--volume "$BUILD_SOURCESDIRECTORY:/home/waagent/WALinuxAgent" \
--volume "$HOME"/ssh:/home/waagent/.ssh \
Expand All @@ -80,46 +77,4 @@ docker run --rm \
-v image:\"$IMAGE\" \
-v location:\"$LOCATION\" \
-v vm_size:\"$VM_SIZE\" \
$TEST_SUITES" \
|| echo "exit $?" > /tmp/exit.sh

#
# Re-take ownership of the logs directory
#
sudo find "$LOGS_DIRECTORY" -exec chown "$USER" {} \;

#
# Move the relevant logs to the staging directory
#
# Move the logs for failed tests to a temporary location
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp
for log in $(grep -l MARKER-LOG-WITH-ERRORS "$LOGS_DIRECTORY"/*.log); do
mv "$log" "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp
done
# Move the environment logs to "environment_logs"
if ls "$LOGS_DIRECTORY"/env-*.log > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/environment_logs
mv "$LOGS_DIRECTORY"/env-*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/environment_logs
fi
# Move the rest of the logs to "test_logs"
if ls "$LOGS_DIRECTORY"/*.log > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/test_logs
mv "$LOGS_DIRECTORY"/*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/test_logs
fi
# Move the logs for failed tests to the main directory
if ls "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp/*.log > /dev/null 2>&1; then
mv "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp/*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"
fi
rmdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/tmp
# Move the logs collected from the test VMs to vm_logs
if ls "$LOGS_DIRECTORY"/*.tgz > /dev/null 2>&1; then
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/vm_logs
mv "$LOGS_DIRECTORY"/*.tgz "$BUILD_ARTIFACTSTAGINGDIRECTORY"/vm_logs
fi
# Files created by LISA are under .../lisa/<date>/<unique_name>"
mkdir "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs
mv "$LOGS_DIRECTORY"/lisa/*/*/lisa-*.log "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs
mv "$LOGS_DIRECTORY"/lisa/*/*/agent.junit.xml "$BUILD_ARTIFACTSTAGINGDIRECTORY"/runbook_logs

cat /tmp/exit.sh
bash /tmp/exit.sh
$TEST_SUITES"