-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile
148 lines (140 loc) · 8.49 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
pipeline {
agent none
environment {
// Kernel version for Ubuntu VMs
KERNEL_VERSION='5.10.130'
// Path to Ubuntu host VM image
IMAGE_FILE='/img/ubuntu20-host.qcow2'
// Location of guest patch file in kvms project
PATCH_FILE='patches/guest/0001-kvm-encrypted-memory-draft-for-arm64-development.patch'
}
stages {
stage('Clone project and build docker image') {
agent {
node {
label 'runner'
customWorkspace '/var/lib/jenkins/shared_workspace'}
}
steps {
script {
sh 'rm -f *.log'
sh 'rm -f core*.*'
sh 'git config --global user.email "[email protected]"'
sh 'git config --global user.name "Your Name"'
sh 'cp ~/.gitconfig docker/gitconfig'
sh 'cd docker && docker build --build-arg userid=$(id -u) --build-arg groupid=$(id -g) --build-arg username=$(id -un) -t kvms .'
sh 'sudo chmod 0666 /dev/dri/render*'
}
}
}
stage('Run make in container'){
agent {
docker {
customWorkspace '/var/lib/jenkins/shared_workspace'
image 'kvms:latest'
args '-v /ccache:/ccache -v ${WORKSPACE}:/hyp --env CCACHE_DIR=/ccache --env PLATFORM=virt --entrypoint='
}
}
steps {
sh 'cd /hyp && make clean || true'
sh 'cd /hyp && make KERNEL_DIR=/hyp/oss/linux tools'
sh 'cd /hyp && DEBUG=2 make KERNEL_DIR=/hyp/oss/linux'
}
}
stage('Patch kernel image'){
// run this directly in host, running nbd inside container was problematic
agent {
node {
label 'runner'
customWorkspace '/var/lib/jenkins/shared_workspace'}
}
steps {
sh 'scripts/ci-check-kernel-patch.sh -k $KERNEL_VERSION -p $(pwd)/$PATCH_FILE -i $IMAGE_FILE'
}
}
stage("Launch host and guest VMs") {
agent {
docker {
customWorkspace '/var/lib/jenkins/shared_workspace'
image 'kvms:latest'
args '-d -t -v ${WORKSPACE}:/hyp -v /img:/img --env PLATFORM=virt --env BOOTIMG=${IMAGE_FILE} --name kvms_build_container --entrypoint= --privileged'
}
}
steps {
sh 'cd /hyp && make KERNEL_DIR=/hyp/oss/linux GRAPHICS=1 run > /hyp/host.log &'
sh 'echo wait for Host VM to reach Network Online state'
sh 'timeout 240s grep -q "Network is Online" <(tail -f /hyp/host.log) || exit 1'
// host VM is now accepting connections but it is better to give it more time to finalize startup
sh 'sleep 60'
sh 'echo HOST_IP=$(grep ssh /hyp/host.log | cut -d" " -f7|cut -d":" -f1) > host_ips.sh'
sh 'cat host_ips.sh'
sh '''
source host_ips.sh
echo $HOST_IP
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "sudo systemctl stop unattended-upgrades"
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "sudo rm -rf /var/lib/apport/coredump/*"
sshpass -p ubuntu scp -P 10022 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no linux-$KERNEL_VERSION/arch/arm64/boot/Image ubuntu@$HOST_IP:~/vm/ubuntu20
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "cd vm/ubuntu20 && ulimit -c unlimited && sudo ./run-qemu6-linux.sh > guest.log" &
echo $?
'''
sh 'echo wait for Guest VM to reach Network Online state'
sh '''
source host_ips.sh
echo "giving a lot of time for guest VM to start"
sleep 480
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@\$HOST_IP -p 10022 "cat vm/ubuntu20/guest.log"
timeout 240s grep -q "Network is Online" <(sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "tail -f vm/ubuntu20/guest.log") || true
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@\$HOST_IP -p 10022 "cat vm/ubuntu20/guest.log" >>/hyp/guest_nw.log
sleep 60
'''
sh '''
source host_ips.sh
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "cat vm/ubuntu20/guest.log" >/hyp/guest.log
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "dmesg" >/hyp/host-dmesg.log
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "sudo chmod 444 /var/lib/apport/coredump/* || true"
sshpass -p ubuntu scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P10022 ubuntu@$HOST_IP:/var/lib/apport/coredump/* /hyp || true
'''
sh 'echo GUEST1_IP=$(grep ssh /hyp/guest.log | cut -d" " -f7|cut -d":" -f1) >> host_ips.sh'
sh '''
source host_ips.sh
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 ssh ubuntu@$GUEST1_IP -p 2000 "dmesg" > /hyp/guest1-dmesg.log
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 ssh ubuntu@$GUEST1_IP -p 2000 "sudo systemctl stop unattended-upgrades"
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 ssh ubuntu@$GUEST1_IP -p 2000 "ps aux" > /hyp/guest1-ps.log
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 ssh ubuntu@$GUEST1_IP -p 2000 "sudo shutdown now" || true
'''
sh 'echo wait for Guest VM to reach Power-Offstate'
sh '''
source host_ips.sh
timeout 240s grep -q "Power-Off" <(sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "tail -f vm/ubuntu20/guest.log") || exit 1
'''
sh '''
source host_ips.sh
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "ps aux"
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "cat vm/ubuntu20/guest.log" >/hyp/guest_shutdown.log
sshpass -p ubuntu ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$HOST_IP -p 10022 "sudo shutdown now" || true
'''
sh 'sleep 30'
}
post {
always {
archiveArtifacts artifacts: '*.log', followSymlinks: false, allowEmptyArchive: true
archiveArtifacts artifacts: 'core*.*', followSymlinks: false, allowEmptyArchive: true
}
success {
script {
if (env.GITHUB_PR_SOURCE_BRANCH) {
githubPRComment comment: githubPRMessage("[build passed: ${BUILD_NUMBER}](${BUILD_URL})."), statusVerifier: allowRunOnStatus("SUCCESS"), errorHandler: statusOnPublisherError("UNSTABLE")
}
}
}
failure{
script {
if (env.GITHUB_PR_SOURCE_BRANCH) {
githubPRComment comment: githubPRMessage("[build failed: ${BUILD_NUMBER}](${BUILD_URL})."), statusVerifier: allowRunOnStatus("FAILURE"), errorHandler: statusOnPublisherError("UNSTABLE")
}
}
}
}
}
}
}