forked from opencord/cord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.newBuildSystem
276 lines (251 loc) · 13.2 KB
/
Jenkinsfile.newBuildSystem
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// Copyright 2017-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
def filename = 'manifest-${branch}.xml'
def manifestUrl = 'https://gerrit.opencord.org/manifest'
def config = null;
node ('master') {
checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
stage ("Generate and Copy Manifest file") {
sh returnStdout: true, script: 'repo manifest -r -o ' + filename
sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp'
}
stage ("Parse deployment configuration file") {
sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
}
}
node ("${config.dev_node.name}") {
timeout (time: 240) {
stage ('Checkout cord repo') {
checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
}
dir('build') {
try {
stage ("Re-deploy head node") {
maasOps: {
sh "maas login maas http://${config.maas.ip}/MAAS/api/2.0 ${config.maas.api_key}"
sh "maas maas machine release ${config.maas.head_system_id}"
timeout(time: 15) {
waitUntil {
try {
sh "maas maas machine read ${config.maas.head_system_id} | grep Ready"
return true
} catch (exception) {
return false
}
}
}
sh 'maas maas machines allocate'
sh "maas maas machine deploy ${config.maas.head_system_id}"
timeout(time: 30) {
waitUntil {
try {
sh "maas maas machine read ${config.maas.head_system_id} | grep Deployed"
return true
} catch (exception) {
return false
}
}
}
}
}
stage ("Download CORD POD configuration") {
sh "cd podconfig; git clone -b ${branch} ${config.pod_config.repo_url} automation"
}
stage ("Generate CORD configuration") {
sh "make PODCONFIG=automation/${config.pod_config.file_name} config"
}
stage ("Deploy") {
sh "VAGRANT_PROVIDER=virtualbox make build"
}
stage ("Power cycle compute nodes") {
for(int i=0; i < config.compute_nodes.size(); i++) {
sh "ipmitool -U ${config.compute_nodes[i].ipmi.user} -P ${config.compute_nodes[i].ipmi.pass} -H ${config.compute_nodes[i].ipmi.ip} power cycle"
}
}
stage ("Wait for compute nodes to get deployed") {
sh "ssh-keygen -f /home/${config.dev_node.user}/.ssh/known_hosts -R ${config.head.ip}"
def cordApiKey = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"sudo maas-region-admin apikey --username ${config.head.user}")
runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"maas login pod-maas http://${config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
timeout(time: 45) {
waitUntil {
try {
num = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"maas pod-maas nodes list | grep -i deployed | wc -l").trim()
return num.toInteger() == config.compute_nodes.size()
} catch (exception) {
return false
}
}
}
}
stage ("Wait for computes nodes to be provisioned") {
ip = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"docker inspect --format '{{.NetworkSettings.Networks.maas_default.IPAddress}}' provisioner").trim()
timeout(time:45) {
waitUntil {
try {
out = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"curl -sS http://$ip:4243/provision/ | jq -c \".[] | select(.status | contains(${config.compute_nodes.size()}))\"".trim())
return out != ""
} catch (exception) {
return false
}
}
}
}
if (config.fabric_switches != null) {
stage("Reserve IPs for fabric switches and restart maas-dhcp service") {
for(int i=0; i < config.fabric_switches.size(); i++) {
def append = "";
if (i!=0) {
append = "-a";
}
def str = createMACIPbindingStr(i+1,
"${config.fabric_switches[i].mac}",
"${config.fabric_switches[i].ip}")
runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"echo -e $str '|' sudo tee $append /etc/dhcp/dhcpd.reservations > /dev/null")
}
runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"sudo restart maas-dhcpd")
runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"cord harvest go")
}
stage ("Wait for fabric switches to get deployed") {
for(int i=0; i < config.fabric_switches.size(); i++) {
runFabricCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"${config.fabric_switches[i].ip}",
"${config.fabric_switches[i].user}",
"${config.fabric_switches[i].pass}",
"sudo onl-onie-boot-mode install")
runFabricCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"${config.fabric_switches[i].ip}",
"${config.fabric_switches[i].user}",
"${config.fabric_switches[i].pass}",
"sudo reboot")
}
timeout(time: 45) {
waitUntil {
try {
def harvestCompleted = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"cord harvest list '|' grep -i fabric '|' wc -l").trim()
return harvestCompleted.toInteger() == config.fabric_switches.size()
} catch (exception) {
return false
}
}
}
}
stage ("Wait for fabric switches to be provisioned") {
timeout(time:45) {
waitUntil {
try {
def provCompleted = 0
for(int i=0; i < config.fabric_switches.size(); i++) {
def count = runCmd("${config.head.ip}",
"${config.head.user}",
"${config.head.pass}",
"cord prov list '|' grep -i ${config.fabric_switches[i].ip} '|' grep -i complete '|' wc -l").trim()
provCompleted = provCompleted + count.toInteger()
}
return provCompleted == config.fabric_switches.size()
} catch (exception) {
return false
}
}
}
}
}
if (config.make_release == true) {
stage ("Trigger Build") {
url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
}
}
currentBuild.result = 'SUCCESS'
} catch (err) {
currentBuild.result = 'FAILURE'
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
} finally {
sh 'vagrant destroy -f corddev'
sh 'rm -rf podconfig/automation'
}
echo "RESULT: ${currentBuild.result}"
}
}
}
/**
* Returns a string used to bind IPs and MAC addresses, substituting the values
* given.
*
* @param counter the counter used to generate the host name
* @param mac the MAC address to substitute
* @param ip the IP address to substitute
*/
def createMACIPbindingStr(counter, mac, ip) {
return """\\'host fabric${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}\\'"""
}
/**
* Runs a command on a remote host using sshpass.
*
* @param ip the node IP address
* @param user the node user name
* @param pass the node password
* @param command the command to run
* @return the output of the command
*/
def runCmd(ip, user, pass, command) {
return sh(returnStdout: true, script: "sshpass -p ${pass} ssh -oStrictHostKeyChecking=no -l ${user} ${ip} ${command}")
}
/**
* Runs a command on a fabric switch.
*
* @param headIp the head node IP address
* @param headUser the head node user name
* @param headPass the head node password
* @param ip the mgmt IP of the fabric switch, reachable from the head node
* @param user the mgmt user name of the fabric switch
* @param pass the mgmt password of the fabric switch
* @param command the command to run on the fabric switch
* @return the output of the command
*/
def runFabricCmd(headIp, headUser, headPass, ip, user, pass, command) {
return sh(returnStdout: true, script: "sshpass -p ${headPass} ssh -oStrictHostKeyChecking=no -l ${headUser} ${headIp} \"sshpass -p ${pass} ssh -oStrictHostKeyChecking=no -l ${user} ${ip} ${command}\"")
}