Skip to content

Commit

Permalink
Improvements in Pipeline parameters (#2748)
Browse files Browse the repository at this point in the history
* Improvements in Pipeline parameters

* remove extra space

* fix jq

---------

Co-authored-by: narrieta <narrieta>
  • Loading branch information
narrieta committed Feb 6, 2023
1 parent ce369ac commit 36a5ec1
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 131 deletions.
1 change: 1 addition & 0 deletions tests_e2e/orchestrator/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ RUN \
# \
echo 'export PYTHONPATH="$HOME/WALinuxAgent"' >> $HOME/.bash_profile && \
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $HOME/.bash_profile && \
echo 'cd $HOME' >> $HOME/.bash_profile && \
:

49 changes: 24 additions & 25 deletions tests_e2e/orchestrator/runbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ extension:
- "./lib"

variable:
#
# These variables define runbook parameters; they are handled by LISA.
#
- name: subscription_id
value: ""
- name: keep_environment
value: "no"
- name: wait_delete
value: false
- name: user
value: "waagent"
- name: identity_file
Expand All @@ -22,9 +21,28 @@ variable:
- name: admin_password
value: ""
is_secret: true
- name: keep_environment
value: "no"
#
# These variables define parameters for the AgentTestSuite; see the test wiki for details.
#
# The test suites to execute
- name: test_suites
value: "agent_bvt"
is_case_visible: true

# Whether to collect logs from the test VM
- name: collect_logs
value: "failed"
is_case_visible: true

# Whether to skip setup of the test VM
- name: skip_setup
value: false
is_case_visible: true

#
# Set these to use an SSH proxy
# Set these to use an SSH proxy when executing the runbook
#
- name: proxy
value: False
Expand All @@ -48,25 +66,6 @@ variable:
- name: default_location
value: "westus2"

#
# These variables define parameters for the AgentTestSuite; see the test wiki for details
#
# The test suites to execute
- name: test_suites
value: "agent_bvt"
is_case_visible: true

# Whether to collect logs from the test VM
- name: collect_logs
value: "failed"
is_case_visible: true

# Whether to skip setup of the test VM
- name: skip_setup
value: false
is_case_visible: true


platform:
- type: azure
admin_username: $(user)
Expand All @@ -76,7 +75,7 @@ platform:
azure:
deploy: True
subscription_id: $(subscription_id)
wait_delete: $(wait_delete)
wait_delete: false
requirement:
core_count:
min: 2
Expand Down
83 changes: 0 additions & 83 deletions tests_e2e/orchestrator/scripts/run-scenarios

This file was deleted.

56 changes: 56 additions & 0 deletions tests_e2e/pipeline/pipeline-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Pipeline for cleaning up any remaining Resource Groups generated by the Azure.WALinuxAgent pipeline.
#
# Runs every 3 hours and deletes any resource groups that are more than a day old and contain string "lisa-WALinuxAgent-"
#
schedules:
- cron: "0 */3 * * *" # Run every 3 hours
displayName: cleanup build
branches:
include:
- develop
always: true

# no PR triggers
pr: none

pool:
vmImage: ubuntu-latest

variables:
- name: azureConnection
value: 'azuremanagement'
- name: rgPrefix
value: 'lisa-WALinuxAgent-'

steps:

- task: AzureKeyVault@2
displayName: "Fetch secrets from KV"
inputs:
azureSubscription: '$(azureConnection)'
KeyVaultName: 'dcrV2SPs'
SecretsFilter: '*'
RunAsPreJob: true

- task: AzureCLI@2
inputs:
azureSubscription: '$(azureConnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -euxo pipefail
date=`date --utc +%Y-%m-%d'T'%H:%M:%S.%N'Z' -d "1 day ago"`
# Using the Azure REST GET resourceGroups API call as we can add the createdTime to the results.
# This feature is not available via the az-cli commands directly so we have to use the Azure REST APIs

az rest --method GET \
--url "https://management.azure.com/subscriptions/$(SUBSCRIPTION-ID)/resourcegroups" \
--url-parameters api-version=2021-04-01 \$expand=createdTime \
--output json \
--query value \
| jq --arg date "$date" '.[] | select (.createdTime < $date).name' \
| grep "$(rgPrefix)" \
| xargs -l -t -r az group delete --no-wait -y -n \
|| echo "No resource groups found to delete"
16 changes: 10 additions & 6 deletions tests_e2e/pipeline/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ parameters:
- failed
- no

- name: skip_setup
displayName: Skip setup of the test VMs
type: boolean
default: false
- name: keep_environment
displayName: Keep the test VMs (do not delete them)
type: string
default: no
values:
- always
- failed
- no

variables:
- name: azureConnection
Expand All @@ -26,8 +30,8 @@ variables:
value: ${{ parameters.test_suites }}
- name: collect_logs
value: ${{ parameters.collect_logs }}
- name: skip_setup
value: ${{ parameters.skip_setup }}
- name: keep_environment
value: ${{ parameters.keep_environment }}

trigger:
- develop
Expand Down
60 changes: 43 additions & 17 deletions tests_e2e/pipeline/scripts/execute_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,62 @@

set -euxo pipefail

#
# Set the correct mode for the private SSH key and generate the public key.
#
cd "$HOME"
mkdir ssh
cp "$DOWNLOADSSHKEY_SECUREFILEPATH" ssh
chmod 700 ssh/id_rsa
ssh-keygen -y -f ssh/id_rsa > ssh/id_rsa.pub

#
# Change the ownership of the "ssh" directory we just created, as well as the sources and staging directories.
# Make waagent (UID 1000 in the container) the owner of both locations, so that it can write to them.
# This is needed because building the agent package writes the egg info to the source code directory, and
# tests write their logs to the staging directory.
#
sudo find ssh -exec chown 1000 {} \;
sudo chown 1000 "$BUILD_SOURCESDIRECTORY"
sudo chown 1000 "$BUILD_ARTIFACTSTAGINGDIRECTORY"

#
# Pull the container image used to execute the tests
#
az login --service-principal --username "$AZURE_CLIENT_ID" --password "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID" > /dev/null

az acr login --name waagenttests

docker pull waagenttests.azurecr.io/waagenttests:latest

# Building the agent package writes the egg info to the source code directory, and test write their logs to the staging directory.
# Make waagent (UID 1000 in the container) the owner of both locations, so that it can write to them.
sudo chown 1000 "$BUILD_SOURCESDIRECTORY"
sudo chown 1000 "$BUILD_ARTIFACTSTAGINGDIRECTORY"

# 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

docker run --rm \
--volume "$BUILD_SOURCESDIRECTORY:/home/waagent/WALinuxAgent" \
--volume "$DOWNLOADSSHKEY_SECUREFILEPATH:/home/waagent/id_rsa" \
--volume "$BUILD_ARTIFACTSTAGINGDIRECTORY:/home/waagent/logs" \
--env SUBSCRIPTION_ID \
--env AZURE_CLIENT_ID \
--env AZURE_CLIENT_SECRET \
--env AZURE_TENANT_ID \
waagenttests.azurecr.io/waagenttests \
bash --login -c \
"\$HOME/WALinuxAgent/tests_e2e/orchestrator/scripts/run-scenarios -t $TEST_SUITES -l $COLLECT_LOGS -k $SKIP_SETUP" \
--volume "$BUILD_SOURCESDIRECTORY:/home/waagent/WALinuxAgent" \
--volume "$HOME"/ssh:/home/waagent/.ssh \
--volume "$BUILD_ARTIFACTSTAGINGDIRECTORY":/home/waagent/logs \
--env AZURE_CLIENT_ID \
--env AZURE_CLIENT_SECRET \
--env AZURE_TENANT_ID \
waagenttests.azurecr.io/waagenttests \
bash --login -c \
"lisa \
--runbook \$HOME/WALinuxAgent/tests_e2e/orchestrator/runbook.yml \
--log_path \$HOME/logs/lisa \
--working_path \$HOME/logs/lisa \
-v subscription_id:$SUBSCRIPTION_ID \
-v identity_file:\$HOME/.ssh/id_rsa \
-v test_suites:\"$TEST_SUITES\" \
-v collect_logs:\"$COLLECT_LOGS\" \
-v keep_environment:\"$KEEP_ENVIRONMENT\"" \
|| echo "exit $?" > /tmp/exit.sh

# Retake ownership of the source and staging directory (note that the former does not need to be done recursively)
#
# Retake ownership of the source and staging directories (note that the former does not need to be done recursively; also, we don't need to
# retake ownership of the ssh directory)
#
sudo chown "$USER" "$BUILD_SOURCESDIRECTORY"
sudo find "$BUILD_ARTIFACTSTAGINGDIRECTORY" -exec chown "$USER" {} \;

Expand All @@ -51,4 +77,4 @@ mv "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-
rm -r "$BUILD_ARTIFACTSTAGINGDIRECTORY"/lisa/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]

cat /tmp/exit.sh
bash /tmp/exit.sh
bash /tmp/exit.sh

0 comments on commit 36a5ec1

Please sign in to comment.