-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
235 lines (208 loc) · 11.1 KB
/
Jenkinsfile
File metadata and controls
235 lines (208 loc) · 11.1 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def waitingIP(String vm_name) {
println ("Waiting IP...")
for (i=0; i<12; i++) {
def vm_ip = sh(returnStdout: true,
script: "virsh --quiet domifaddr ${vm_name} | grep vnet | awk '{print \$4}' | sed 's/\\/..//g'").trim()
if (vm_ip) {
println("vm_ip: ${vm_ip} // waiting time ${i}0s")
return vm_ip
}
sleep 10
}
error('Time out wating IP')
}
def sshCall(String command){
sh "ssh root@${VM_IP} ${command}"
}
def getLog(String pod, String namespace) {
def logs = sh(returnStdout: true,
script: "ssh root@${VM_IP} kubectl logs ${pod} --namespace ${namespace}")
if (pod.contains('rally')) {
println "Got log from rally pod."
log_with_title = "[RALLY-RESULT from ${pod}]\n${logs}\n"
}
println log_with_title
return log_with_title
}
def collectLog(String namespace="openstack", String keyword="", String extparam="") {
def pods = sh(returnStdout: true,
script: "ssh root@${VM_IP} kubectl get pods -n ${namespace} --show-all | grep ${keyword}")
if (pods) {
pod_list = pods.tokenize('\n')
for (line in pod_list) {
pod_name = line.split(' ')[0]
if (pod_name) {
println "${pod_name} found. Getting log from the pod.."
log_str = getLog(pod_name, namespace)
}
}
}
}
pipeline {
agent { node 'slave-vm' }
options {
timeout(time: 1000, unit: 'MINUTES')
timestamps()
}
environment {
VM_NAME = 'TACO'
VM_IP = ''
ERROR_RES = ''
RES = ''
}
stages {
stage('Create VM') {
steps {
script {
sh """cp /var/lib/libvirt/images/backup.qcow2 /var/lib/libvirt/images/${VM_NAME}.qcow2
virt-install \
--channel unix,mode=bind,target_type=virtio,name=org.qemu.guest_agent.0 \
--cpu host \
--disk path=/var/lib/libvirt/images/${VM_NAME}.qcow2,format=qcow2,device=disk,bus=virtio,size=40 \
--graphics none \
--memory 16384 \
--name ${VM_NAME} \
--network default,model=virtio \
--noautoconsole \
--os-type linux \
--os-variant ubuntu16.04 \
--vcpus 6 \
--import
"""
VM_IP = waitingIP(VM_NAME)
println ("VM_IP: ${VM_IP} success")
def regHost = sh(returnStdout: true,
script: "cat ~/reg_ip")
sshCall("\"echo \'${regHost}\' >> /etc/hosts\"")
sshCall("cat /etc/hosts")
}
}
}
stage('Init') {
steps {
//sshCall("echo \"nameserver 8.8.8.8\" >> /etc/resolvconf/resolv.conf.d/head && resolvconf -u")
sshCall("git clone https://github.com/sktelecom-oslab/taco-scripts.git")
}
}
stage('Run 010.sh _ init env') {
steps {
sshCall("apt-get install -y python-subprocess32")
sshCall("taco-scripts/010-init-env.sh")
}
}
stage('Run 020.sh _ install k8s') {
steps {
//sshCall("echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf")
sshCall("taco-scripts/020-install-k8s.sh")
}
}
stage('Run 030.sh _ intall armada') {
steps {
sshCall("taco-scripts/030-install-armada.sh")
}
}
stage('Run 040.sh _ deploy openstack') {
steps {
sshCall("taco-scripts/040-deploy-openstack.sh")
}
}
stage('Run 041.sh _ deploy monitoring') {
steps {
sshCall("taco-scripts/041-deploy-mon.sh")
}
}
stage('Run 050.sh _ create os resources') {
steps {
sshCall("taco-scripts/050-create-os-resources.sh")
}
}
/*
stage('Test os') {
steps {
script{
//def res = sshisError("kubectl get po --all-namespaces | grep -Ev 'Running|STATUS' || true")
def res = sshisError("kubectl get po --all-namespaces | grep -v Running")
if (res) {
ERROR_RES = res + "\n\n" + sshisError("kubectl get po --all-namespaces | awk '\$5>0'")
//error("K8s Error: some pods is wrong ")
}
try {
sshCall("\". ~/taco-scripts/adminrc && openstack service list > os_list\"")
sshCall("\". ~/taco-scripts/adminrc && openstack network list >> os_list\"")
sshCall("\". ~/taco-scripts/adminrc && openstack server list >> os_list\"")
sshCall("cat os_list")
RES = sh(returnStdout: true,
script: "ssh root@${VM_IP} cat os_list").trim()
} catch (Exception e) {
sh "pwd"
error("Openstack Error: ${e}")
}
}
}
}
*/
stage ('Run Rally') {
steps {
script {
def cirros_ID = sh(returnStdout: true,
script: "ssh root@${VM_IP} \". ~/taco-scripts/adminrc && openstack image list | grep Cirros | awk '{print \\\$2}'\"")
sshCall("\". ~/taco-scripts/adminrc && openstack image set --public ${cirros_ID}\"")
sh "scp -r ~/workspace/TACO_pipe/* root@${VM_IP}:~/"
sshCall("""\" cp ~/workspace/rally_values.yaml openstack-helm/rally/values.yaml
cd openstack-helm
sed -i \'s/http:\\/\\/localhost:8879\\/charts/file:\\/\\/..\\/..\\/openstack-helm-infra\\/helm-toolkit/g\' rally/requirements.yaml
sed -i \'s/rally-manage/rally/g\' rally/templates/bin/_manage-db.sh.tpl
sed -i \'s/ceph/general/g\' ~/workspace/values-overrides.yaml
helm dep up rally
helm install ./rally --name=openstack-rally --namespace=openstack -f ~/workspace/values-overrides.yaml -f ~/workspace/integration.yaml
\"""")
sleep 10
println("Waiting for rally task")
def rallyStatus=false
for (i=0;i <240;i++){
def rallyCheck = sh(returnStdout: true,
script: "ssh root@${VM_IP} kubectl get po -n openstack")
println rallyCheck
if (rallyCheck.contains("rally-run-task")){
println("Waiting for rally task to be finished for ${i}0s..")
} else {
println("Rally task is completed in ${i}0s.")
rallyStatus=true
break;
}
sleep 10
}
collectLog('openstack', 'rally-run-task')
if (rallyStatus==false) {
error("Timed out waiting for rally task to finish.")
}
}
}
}
}
post {
always {
script {
sshCall("pwd")
sshCall("ls -al")
sh """virsh destroy ${VM_NAME} && virsh undefine ${VM_NAME}
rm -rf /var/lib/libvirt/images/${VM_NAME}.qcow2
"""
}
}
success {
slackSend (
color: '#ACFA58',
message: "VM COMPLETED: job '${env.JOB_NAME} [${env.BUILD_NUMBER}]] (${env.BUILD_URL})"
)
//slackSend (message: "```[Completed create OS VM]\n${RES}```")
}
failure {
slackSend (
color: '#FA5882',
message: "VM FAILED: job '${env.JOB_NAME} [${env.BUILD_NUMBER}]] (${env.BUILD_URL})"
)
//slackSend (message: "```[Error pods]\n${ERROR_RES}```")
}
}
}