blob: 6e2b04c3bbce70d72ed912863d0a17cfcc7e5bf6 [file] [log] [blame]
Suchitra Vemurif5d64222018-05-11 16:09:10 -07001// Copyright 2017-present Open Networking Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import groovy.json.JsonSlurperClassic
16
17def filename = 'manifest-${branch}.xml'
18def manifestUrl = 'https://gerrit.opencord.org/manifest'
19deployment_config = null;
20pod_config = null;
21
Kailash Khalasi1b357c02018-05-14 14:25:14 -070022node ("${devNodeName}") {
23 timeout (time: 360) {
Suchitra Vemurif5d64222018-05-11 16:09:10 -070024
25 stage ("Parse deployment configuration file") {
26 sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
27 sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
28 deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
29 pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}"
30 }
Suchitra Vemurif5d64222018-05-11 16:09:10 -070031
Suchitra Vemurif5d64222018-05-11 16:09:10 -070032 stage ('Remove old head node from known hosts') {
33 sh "ssh-keygen -R ${deployment_config.head.ip}"
34 }
35
36 stage ('Checkout cord repo') {
37 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
38 }
39
40 stage ('Copy NG40 license file') {
Kailash Khalasif1205c42018-05-14 14:59:31 -070041 sh "cp ~/ng40-license orchestration/xos_services/venb/xos/synchronizer/files/ng40-license"
Suchitra Vemurif5d64222018-05-11 16:09:10 -070042 }
43
44 try {
45 dir('build') {
46 stage ("Re-deploy head node") {
47 maasOps: {
48 sh "maas login maas http://${deployment_config.maas.ip}/MAAS/api/2.0 ${deployment_config.maas.api_key}"
49 sh "maas maas machine release ${deployment_config.maas.head_system_id}"
50
51 timeout(time: 15) {
52 waitUntil {
53 try {
54 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Ready"
55 return true
56 } catch (exception) {
57 return false
58 }
59 }
60 }
61
62 sh 'maas maas machines allocate'
63 sh "maas maas machine deploy ${deployment_config.maas.head_system_id}"
64
65 timeout(time: 30) {
66 waitUntil {
67 try {
68 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Deployed"
69 return true
70 } catch (exception) {
71 return false
72 }
73 }
74 }
75 }
76 }
77
78 stage ("Download CORD POD configuration") {
79 sh "cd ../orchestration/profiles; git clone -b ${branch} ${deployment_config.pod_config.repo_url} automation"
80 }
81
82 stage ("Generate CORD configuration") {
83 sh "make PODCONFIG_PATH=../orchestration/profiles/automation/${deployment_config.pod_config.file_name} config"
84 }
85
86 if (deployment_config.fabric_switches != null) {
87 stage("Reserve IPs for fabric switches") {
88 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
89 def str = createMACIPbindingStr("fabric", i+1,
90 "${deployment_config.fabric_switches[i].mac}",
91 "${deployment_config.fabric_switches[i].ip}")
92 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
93 }
94 }
95 }
96
97 stage ("Deploy") {
98 sh 'sed -i "s/^\\(dev_vm_cpu: \\).*/\\120/" genconfig/config.yml'
99 sh 'sed -i "s/^\\(dev_vm_mem: \\).*/\\140960/" genconfig/config.yml'
100 sh "make build"
101 }
102
103 if (deployment_config.compute_nodes != null) {
104 stage ("Power cycle compute nodes") {
105 for(int i=0; i < deployment_config.compute_nodes.size(); i++) {
106 sh "ipmitool -U ${deployment_config.compute_nodes[i].ipmi.user} -P ${deployment_config.compute_nodes[i].ipmi.pass} -H ${deployment_config.compute_nodes[i].ipmi.ip} power cycle"
107 }
108 }
109
110 stage ("Wait for compute nodes to get deployed") {
111 sh "ssh-keygen -f /home/${deployment_config.dev_node.user}/.ssh/known_hosts -R ${deployment_config.head.ip}"
112 def cordApiKey = runHeadNodeCmd("sudo maas-region-admin apikey --username ${deployment_config.head.user}")
113 runHeadNodeCmd("maas login pod-maas http://${deployment_config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
114 timeout(time: 90) {
115 waitUntil {
116 try {
117 num = runHeadNodeCmd("maas pod-maas nodes list | grep substatus_name | grep -i deployed | wc -l").trim()
118 return num.toInteger() == deployment_config.compute_nodes.size()
119 } catch (exception) {
120 return false
121 }
122 }
123 }
124 }
125
126 stage ("Wait for compute nodes to be provisioned") {
127 timeout(time:90) {
128 waitUntil {
129 try {
130 num = runHeadNodeCmd("cord prov list | grep -i node | grep -i complete | wc -l").trim()
131 return num.toInteger() == deployment_config.compute_nodes.size()
132 } catch (exception) {
133 return false
134 }
135 }
136 }
137 }
138 }
139
140 if (deployment_config.fabric_switches != null) {
141 stage ("Wait for fabric switches to get deployed") {
142 runFabricSwitchCmdAll("sudo onl-onie-boot-mode install")
143 runFabricSwitchCmdAll("sudo reboot")
144 // Ensure that switches get provisioned after ONIE reinstall.
145 // Delete them if they were provisioned earlier. If the switches are not
146 // present in 'cord prov list', this command has no effect.
147 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
148 runHeadNodeCmd("cord prov delete ${deployment_config.fabric_switches[i].mac}")
149 }
150 timeout(time: 45) {
151 waitUntil {
152 try {
153 def harvestCompleted = runHeadNodeCmd("cord harvest list | grep -i fabric | wc -l").trim()
154 return harvestCompleted.toInteger() == deployment_config.fabric_switches.size()
155 } catch (exception) {
156 return false
157 }
158 }
159 }
160 }
161
162 stage ("Wait for fabric switches to be provisioned") {
163 timeout(time:45) {
164 waitUntil {
165 try {
166 def provCompleted = 0
167 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
168 def count = runHeadNodeCmd("cord prov list | grep -i ${deployment_config.fabric_switches[i].ip} | grep -i complete | wc -l").trim()
169 provCompleted = provCompleted + count.toInteger()
170 }
171 return provCompleted == deployment_config.fabric_switches.size()
172 } catch (exception) {
173 return false
174 }
175 }
176 }
177 }
178
179 // Post installation configuration starts here
180 fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0]
181 xosUser = "xosadmin@opencord.org"
182 xosPass = runHeadNodeCmd("cat /opt/credentials/xosadmin@opencord.org").trim()
183 stage ("Connect fabric switches and compute nodes to ONOS") {
184 // Configure breakout ports
185 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
186 if (deployment_config.fabric_switches[i].breakout_ports != null) {
187 for(int j=0; j < deployment_config.fabric_switches[i].breakout_ports.size(); j++) {
188 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
189 "${deployment_config.fabric_switches[i].user}",
190 "${deployment_config.fabric_switches[i].pass}",
191 "sed -i -e 's/#port_mode_${deployment_config.fabric_switches[i].breakout_ports[j]}=/port_mode_${deployment_config.fabric_switches[i].breakout_ports[j]}=/g' /etc/accton/ofdpa.conf")
192 }
193 }
194 }
195 connectFabricAndComputeToOnos()
196 }
197 stage ("Configure the compute nodes") {
198 leafSwitchNum = 0
199 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
200 if(deployment_config.fabric_switches[i].containsKey("role")) {
201 if(deployment_config.fabric_switches[i].role.toLowerCase().contains("leaf")) {
202 leafSwitchNum += 1
203 }
204 }
205 }
206 for(int i=1; i<=leafSwitchNum; i++) {
207 // Figure out which compute node connects to which switch
208 leafName = "leaf-" + i.toString()
209 computeNames = getComputeNames(leafName)
210 echo "Compute nodes connnected to " + leafName + " switch:"
211 for(name in computeNames) { echo "${name}" }
212 index = 1
213 for(name in computeNames) {
214 if(i>1) {
215 //Update fabric IP of compute nodes
216 index += 1
217 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*/24'").trim()
218 if (fabricIp != "") {
219 nodeId = sh(returnStdout: true, script: "curl -u ${xosUser}:${xosPass} -X GET http://${deployment_config.head.ip}/xosapi/v1/core/nodes | jq '.[\"items\"][] | select(.dataPlaneIp==\"${fabricIp}\") | .id'").trim()
220 newFabricIp = "${fabricIpPrefix}." + i.toString() + "." + index.toString() + "/24"
221 out = sh(returnStdout: true, script: "curl -u ${xosUser}:${xosPass} -X PUT -d '{\"dataPlaneIp\":\"${newFabricIp}\"}' http://${deployment_config.head.ip}/xosapi/v1/core/nodes/${nodeId}").trim()
222 // Wait until the new fabric IP gets configured
223 timeout(time: 5) {
224 waitUntil {
225 try {
226 num = runComputeNodeCmd("${name}", "ip a | grep " + newFabricIp + " | wc -l").trim()
227 return num.toInteger() == 1
228 } catch (exception) {
229 return false
230 }
231 }
232 }
233 }
234 else echo "Cannot find fabric IP matching pattern ${fabricIpPrefix}.[1-9][0-9]*.[0-9]*"
235 }
236 //Add routes to fabric subnets
237 for(int j=1; j<=leafSwitchNum; j++) {
238 if(j!=i) {
239 runComputeNodeCmd("${name}", "sudo ip route add ${fabricIpPrefix}." + j.toString() + ".0/24 via ${fabricIpPrefix}." + i.toString() + ".254 || echo route already exists")
240 }
241 }
242 }
243 }
244 }
245 stage ("Generate and load network configuration") {
246 // Reconnect compute nodes to update the fabric IP in ONOS
247 connectFabricAndComputeToOnos()
248 // Generate network configuration
249 runHeadNodeCmd("""
250 cd /opt/cord_profile/
251 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
252 cord generate > fabric-network-cfg.json
253 """)
254 // Install httpie on the head-node
255 runHeadNodeCmd("sudo pip install httpie")
256 // Delete old ONOS netcfg
257 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
258 // Load new configuration
259 runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json")
260 // Restart ONOS apps
261 runHeadNodeCmd("""
262 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
263 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
264 """)
265 }
266 }
267 }
268
269 if (deployment_config.make_release == true) {
270 stage ("Trigger Build") {
271 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
272 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
273 }
274 }
275
276 currentBuild.result = 'SUCCESS'
277 } catch (err) {
278 currentBuild.result = 'FAILURE'
279 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
280 } finally {
Kailash Khalasif1205c42018-05-14 14:59:31 -0700281 sh "make -C build clean-all || true"
282 sh "rm -rf *"
Suchitra Vemurif5d64222018-05-11 16:09:10 -0700283 }
284 echo "RESULT: ${currentBuild.result}"
285 }
286}
287
288/**
289 * Returns a string used to bind IPs and MAC addresses, substituting the values
290 * given.
291 *
292 * @param word the word used to generate the host name
293 * @param counter the counter used to generate the host name
294 * @param mac the MAC address to substitute
295 * @param ip the IP address to substitute
296 */
297def createMACIPbindingStr(word, counter, mac, ip) {
298 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
299}
300
301/**
302 * Runs a command on a remote host using sshpass.
303 *
304 * @param ip the node IP address
305 * @param user the node user name
306 * @param pass the node password
307 * @param command the command to run
308 * @param sshArgs arguments for the ssh command
309 * @return the output of the command
310 */
311def runCmd(ip, user, pass, command, sshArgs="") {
312 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
313}
314
315/**
316 * Runs a command on the head node.
317 *
318 * @param command the command to run
319 * @param sshArgs arguments for the ssh command
320 * @return the output of the command
321 */
322def runHeadNodeCmd(command, sshArgs="") {
323 return sh(returnStdout: true, script: "sshpass -p ${deployment_config.head.pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${deployment_config.head.user} ${deployment_config.head.ip} \"${command}\"")
324}
325
326/**
327 * Runs a command on a fabric switch.
328 *
329 * @param ip the mgmt IP of the fabric switch, reachable from the head node
330 * @param user the mgmt user name of the fabric switch
331 * @param pass the mgmt password of the fabric switch
332 * @param command the command to run on the fabric switch
333 * @param ssgArgs arguments for the ssh command
334 * @return the output of the command
335 */
336def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
337 return sh(returnStdout: true, script: "sshpass -p ${deployment_config.head.pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${deployment_config.head.user} ${deployment_config.head.ip} \"sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} ${command}\"")
338}
339
340/**
341 * Runs a command on all fabric switches
342 *
343 * @param command the command to run on the fabric switches
344 * @param ssgArgs arguments for the ssh command
345 */
346def runFabricSwitchCmdAll(command, sshArgs="") {
347 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
348 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
349 "${deployment_config.fabric_switches[i].user}",
350 "${deployment_config.fabric_switches[i].pass}",
351 "${command}",
352 "${sshArgs}")
353 }
354}
355
356/**
357 * Runs a command on a compute node.
358 *
359 * @param name the name of the compute node
360 * @param command the command to run on the compute node
361 * @param ssgArgs arguments for the ssh command
362 * @return the output of the command
363 */
364def runComputeNodeCmd(name, command, sshArgs="") {
365 return sh(returnStdout: true, script: "sshpass -p ${deployment_config.head.pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${deployment_config.head.user} ${deployment_config.head.ip} \"ssh ${sshArgs} ubuntu@${name} ${command}\"")
366}
367
368/**
369 * Runs a command on all compute nodes
370 *
371 * @param command the command to run on the compute nodes
372 * @param ssgArgs arguments for the ssh command
373 */
374def runComputeNodeCmdAll(command, sshArgs="") {
375 computeNamesAll = getComputeNames()
376 for (name in computeNamesAll) {
377 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
378 }
379}
380
381/**
382 * Runs an ONOS CLI command
383 *
384 * @param name the onos node name, reachable from the head node
385 * @param port the port used to login to ONOS CLI
386 * @param user the user name to login to ONOS CLI
387 * @param pass the password to login to ONOS CLI
388 * @param command the command to run in ONOS CLI
389 * @return the output of the command
390 */
391def runOnosCliCmd(name, port, user, pass, command) {
392 return sh(returnStdout: true, script: "sshpass -p ${deployment_config.head.pass} ssh -oStrictHostKeyChecking=no -l ${deployment_config.head.user} ${deployment_config.head.ip} \"sshpass -p ${pass} ssh -oStrictHostKeyChecking=no -l ${user} -p ${port} ${name} ${command}\"")
393}
394
395/**
396 * Returns a list of compute node names. When "role" is specified, returns only
397 * names of compute nodes connected to the switch
398 *
399 * @param role the switch role, i.e. "leaf-1"
400 */
401def getComputeNames(role="") {
402 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
403 computeNamesAll = "${computeNamesAll}".split()
404 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
405 computeNamesAll = new JsonSlurperClassic().parseText("${computeNamesAll}")
406 if ("${role}" == "") return computeNamesAll
407 computeNames = []
408 switchMac = ""
409 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
410 if(deployment_config.fabric_switches[i].containsKey("role")) {
411 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
412 switchMac = "${deployment_config.fabric_switches[i].mac}"
413 }
414 }
415 if ("${switchMac}" != "") {
416 switchMac = switchMac.toLowerCase().replaceAll(':','')
417 // Get fabric IPs of compute nodes connected to the switch
418 try {
419 computeFabricIps = runHeadNodeCmd("sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts -j | jq '.[] | select(.location.elementId | contains(\\\"${switchMac}\\\")) | .ipAddresses' | grep -o '\\\"${fabricIpPrefix}.[1-9][0-9]*.[0-9]*\\\"'",
420 "-q").trim()
421 }catch (exception) {
422 return computeNames
423 }
424 computeFabricIps = "${computeFabricIps}".split()
425 computeFabricIps = new JsonSlurperClassic().parseText("${computeFabricIps}")
426 // Figure out which compute node connects to the switch
427 for (name in computeNamesAll) {
428 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*'").trim()
429 if (fabricIp in computeFabricIps) {
430 computeNames.add("${name}")
431 }
432 }
433 }
434 return computeNames
435}
436
437/**
438 * Connects all fabric switches and compute nodes to ONOS
439 */
440def connectFabricAndComputeToOnos() {
441 // Kill existing switch connections
442 runFabricSwitchCmdAll("./killit || echo no ofagentapp running")
443 // Clean stale ONOS data
444 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "wipe-out -r -j please")
445 // Connect switches to ONOS
446 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
447 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
448 "${deployment_config.fabric_switches[i].user}",
449 "${deployment_config.fabric_switches[i].pass}",
450 "./connect -bg 2>&1 > ${deployment_config.fabric_switches[i].ip}.log",
451 "-qftn")
452 }
453 // Verify ONOS has recognized the switches
454 timeout(time: 5) {
455 waitUntil {
456 try {
457 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric devices | grep available=true | wc -l\"").trim()
458 return num.toInteger() == deployment_config.fabric_switches.size()
459 } catch (exception) {
460 return false
461 }
462 }
463 }
464 // Connect compute nodes to ONOS
465 runComputeNodeCmdAll("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
466 // Verify ONOS has recognized the hosts
467 timeout(time: 5) {
468 waitUntil {
469 try {
470 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim()
471 return num.toInteger() >= deployment_config.compute_nodes.size()
472 } catch (exception) {
473 return false
474 }
475 }
476 }
477}