sonic-buildimage/azure-pipelines.yml
Guohan Lu fb0b999361 [ci]: append job.attempt in memdump/log artifacts
azure pipepline does not allow upload same artifacts again.
thus, use job.attempt to uniquely name the test artifacts

Signed-off-by: Guohan Lu <lguohan@gmail.com>
2021-01-28 01:05:44 -08:00

218 lines
7.7 KiB
YAML

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
branches:
include:
- master
- 202012
pr:
- master
name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
resources:
repositories:
- repository: sonic-mgmt
type: github
name: Azure/sonic-mgmt
endpoint: build
stages:
- stage: Build
pool: sonicbld
jobs:
- job:
displayName: "broadcom"
timeoutInMinutes: 600
steps:
- checkout: self
submodules: recursive
displayName: 'Checkout code'
- script: |
sudo modprobe overlay
CACHE_OPTIONS="SONIC_DPKG_CACHE_METHOD=rcache SONIC_DPKG_CACHE_SOURCE=/nfs/dpkg_cache/broadcom"
ENABLE_DOCKER_BASE_PULL=y make configure PLATFORM=broadcom
trap "sudo rm -rf fsroot" EXIT
make USERNAME=admin SONIC_BUILD_JOBS=$(nproc) $CACHE_OPTIONS target/sonic-broadcom.bin && \
ENABLE_SYNCD_RPC=y make USERNAME=admin SONIC_BUILD_JOBS=$(nproc) $CACHE_OPTIONS target/docker-syncd-brcm-rpc.gz
displayName: 'Build sonic image'
- publish: $(System.DefaultWorkingDirectory)/
artifact: sonic-buildimage.broadcom
displayName: "Archive sonic image"
- job:
displayName: "mellanox"
timeoutInMinutes: 600
steps:
- checkout: self
submodules: recursive
displayName: 'Checkout code'
- script: |
sudo modprobe overlay
CACHE_OPTIONS="SONIC_DPKG_CACHE_METHOD=rcache SONIC_DPKG_CACHE_SOURCE=/nfs/dpkg_cache/mellanox"
ENABLE_DOCKER_BASE_PULL=y make configure PLATFORM=mellanox
trap "sudo rm -rf fsroot" EXIT
make USERNAME=admin SONIC_BUILD_JOBS=$(nproc) $CACHE_OPTIONS target/sonic-mellanox.bin && \
ENABLE_SYNCD_RPC=y make USERNAME=admin SONIC_BUILD_JOBS=$(nproc) $CACHE_OPTIONS target/docker-syncd-mlnx-rpc.gz
displayName: 'Build sonic image'
- publish: $(System.DefaultWorkingDirectory)/
artifact: sonic-buildimage.mellanox
displayName: "Archive sonic image"
- job:
displayName: "kvm"
timeoutInMinutes: 600
steps:
- checkout: self
submodules: recursive
displayName: 'Checkout code'
- script: |
echo $(Build.BuildNumber)
sudo modprobe overlay
CACHE_OPTIONS="SONIC_DPKG_CACHE_METHOD=rcache SONIC_DPKG_CACHE_SOURCE=/nfs/dpkg_cache/vs"
ENABLE_DOCKER_BASE_PULL=y make configure PLATFORM=vs
trap "sudo rm -rf fsroot" EXIT
make USERNAME=admin SONIC_BUILD_JOBS=$(nproc) $CACHE_OPTIONS \
target/docker-sonic-vs.gz target/sonic-vs.img.gz target/docker-ptf.gz
displayName: 'Build sonic image'
- publish: $(System.DefaultWorkingDirectory)/
artifact: sonic-buildimage.kvm
displayName: "Archive sonic image"
- stage: Test
pool: sonictest
variables:
- name: dut
value: vlab-01
- name: tbname
value: vms-kvm-t0
- name: inventory
value: veos_vtb
- name: testbed_file
value: vtestbed.csv
- name: ptf_name
value: ptf_vms6-1
jobs:
- job:
displayName: "vstest"
timeoutInMinutes: 60
steps:
- checkout: self
submodules: recursive
displayName: 'Checkout code'
- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: build
pipeline: 9
artifacts: sonic-swss-common.amd64.ubuntu20_04
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/master'
displayName: "Download sonic swss common deb packages"
- task: DownloadPipelineArtifact@2
inputs:
artifact: sonic-buildimage.kvm
displayName: "Download sonic-buildimage.kvm artifact"
- script: |
set -x
sudo dpkg -i --force-confask,confnew ../sonic-swss-common.amd64.ubuntu20_04/libswsscommon_1.0.0_amd64.deb
sudo dpkg -i ../sonic-swss-common.amd64.ubuntu20_04/python3-swsscommon_1.0.0_amd64.deb
sudo docker load -i ../target/docker-sonic-vs.gz
docker tag docker-sonic-vs:latest docker-sonic-vs:$(Build.BuildNumber)
username=$(id -un)
trap "docker ps; docker images; ip netns list; \
docker rmi docker-sonic-vs:$(Build.BuildNumber); \
ip netns list | grep -E [-]srv[0-9]+ | awk '{print $1}' | xargs -I {} sudo ip netns delete {}; \
sudo chown -R ${username}.${username} .; \
sudo chown -R ${username}.${username} $(System.DefaultWorkingDirectory)" EXIT
pushd platform/vs/tests
sudo py.test -v --junitxml=tr.xml --imgname=docker-sonic-vs:$(Build.BuildNumber)
displayName: "Run vs tests"
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/tr.xml'
testRunTitle: vstest
- job:
displayName: "kvmtest"
timeoutInMinutes: 240
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: sonic-buildimage.kvm
displayName: "Download sonic-buildimage.kvm artifact"
- script: |
set -x
sudo mkdir -p /data/sonic-vm/images
sudo cp -v ../target/sonic-vs.img.gz /data/sonic-vm/images/sonic-vs.img.gz
sudo gzip -fd /data/sonic-vm/images/sonic-vs.img.gz
username=$(id -un)
sudo chown -R $username.$username /data/sonic-vm
pushd /data/sonic-mgmt
git remote update
git reset --hard origin/master
sed -i s/use_own_value/${username}/ ansible/veos_vtb
echo aaa > ansible/password.txt
docker exec sonic-mgmt bash -c "pushd /data/sonic-mgmt/ansible;./testbed-cli.sh -d /data/sonic-vm -m $(inventory) -t $(testbed_file) -k ceos refresh-dut $(tbname) password.txt" && sleep 180
displayName: "Setup T0 testbed"
- script: |
pwd
username=$(id -un)
rm -rf $(Build.ArtifactStagingDirectory)/*
docker exec sonic-mgmt bash -c "/data/sonic-mgmt/tests/kvmtest.sh -en $(tbname) $(dut)"
# save dut state if test fails
if [ $? != 0 ]; then
virsh_version=$(virsh --version)
if [ $virsh_version == "6.0.0" ]; then
mkdir -p $(Build.ArtifactStagingDirectory)/kvmdump
virsh -c qemu:///system list
virsh -c qemu:///system save $(dut) $(Build.ArtifactStagingDirectory)/kvmdump/$(dut).memdmp
virsh -c qemu:///system dumpxml $(dut) > $(Build.ArtifactStagingDirectory)/kvmdump/$(dut).xml
img=$(virsh -c qemu:///system domblklist $(dut) | grep vda | awk '{print $2}')
cp $img $(Build.ArtifactStagingDirectory)/kvmdump/$(dut).img
virsh -c qemu:///system undefine $(dut)
fi
docker commit $(ptf_name) docker-ptf:$(Build.BuildNumber)
docker save docker-ptf:$(Build.BuildNumber) | gzip -c > $(Build.ArtifactStagingDirectory)/kvmdump/docker-ptf-dump.gz
docker rmi docker-ptf:$(Build.BuildNumber)
cp -r /data/sonic-mgmt/tests/logs $(Build.ArtifactStagingDirectory)/
sudo chown -R $username.$username $(Build.ArtifactStagingDirectory)
exit 2
else
cp -r /data/sonic-mgmt/tests/logs $(Build.ArtifactStagingDirectory)/
fi
displayName: "Run T0 tests"
- publish: $(Build.ArtifactStagingDirectory)/kvmdump
artifact: sonic-buildimage.kvmtest.memdump@$(System.JobAttempt)
displayName: "Archive sonic kvm memdump"
condition: failed()
- publish: $(Build.ArtifactStagingDirectory)/logs
artifact: sonic-buildimage.kvmtest.log@$(System.JobAttempt)
displayName: "Archive sonic kvm logs"
condition: succeededOrFailed()
- task: PublishTestResults@2
inputs:
testResultsFiles: '$(Build.ArtifactStagingDirectory)/logs/**/*.xml'
testRunTitle: kvmtest
condition: succeededOrFailed()