blob: 538cd56bf070e6991662482b375520d4a4ac68b5 [file] [log] [blame]
You Wangcebbd312017-09-11 14:35:24 -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
Kailash Khalasi7d14e392018-05-08 12:03:23 -070015import groovy.json.JsonSlurper
You Wangac934372017-10-16 10:11:48 -070016
You Wangcebbd312017-09-11 14:35:24 -070017def filename = 'manifest-${branch}.xml'
18def manifestUrl = 'https://gerrit.opencord.org/manifest'
You Wangac934372017-10-16 10:11:48 -070019deployment_config = null;
20pod_config = null;
You Wangcebbd312017-09-11 14:35:24 -070021
Kailash Khalasi3f6415f2018-04-23 10:49:45 -070022node ("${devNodeName}") {
You Wangcebbd312017-09-11 14:35:24 -070023 timeout (time: 240) {
Kailash Khalasi3f6415f2018-04-23 10:49:45 -070024 stage ("Parse deployment configuration file") {
25 sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
26 sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
27 deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
28 pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}"
29 }
Luca Prete7b4a1e82017-09-12 10:44:48 -070030 stage ('Remove old head node from known hosts') {
You Wangac934372017-10-16 10:11:48 -070031 sh "ssh-keygen -R ${deployment_config.head.ip}"
You Wangcebbd312017-09-11 14:35:24 -070032 }
33 stage ('Checkout cord repo') {
34 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
35 }
36
Luca Prete9081fcc2017-09-12 14:37:33 -070037 try {
38 dir('build') {
You Wangcebbd312017-09-11 14:35:24 -070039 stage ("Re-deploy head node") {
40 maasOps: {
You Wangac934372017-10-16 10:11:48 -070041 sh "maas login maas http://${deployment_config.maas.ip}/MAAS/api/2.0 ${deployment_config.maas.api_key}"
42 sh "maas maas machine release ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070043
44 timeout(time: 15) {
45 waitUntil {
46 try {
You Wangac934372017-10-16 10:11:48 -070047 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Ready"
You Wangcebbd312017-09-11 14:35:24 -070048 return true
49 } catch (exception) {
50 return false
51 }
52 }
53 }
54
55 sh 'maas maas machines allocate'
You Wangac934372017-10-16 10:11:48 -070056 sh "maas maas machine deploy ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070057
58 timeout(time: 30) {
59 waitUntil {
60 try {
You Wangac934372017-10-16 10:11:48 -070061 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Deployed"
You Wangcebbd312017-09-11 14:35:24 -070062 return true
63 } catch (exception) {
64 return false
65 }
66 }
67 }
68 }
69 }
70
71 stage ("Download CORD POD configuration") {
You Wangac934372017-10-16 10:11:48 -070072 sh "cd podconfig; git clone -b ${branch} ${deployment_config.pod_config.repo_url} automation"
You Wangcebbd312017-09-11 14:35:24 -070073 }
74
75 stage ("Generate CORD configuration") {
You Wangac934372017-10-16 10:11:48 -070076 sh "make PODCONFIG=automation/${deployment_config.pod_config.file_name} config"
You Wangcebbd312017-09-11 14:35:24 -070077 }
78
You Wangac934372017-10-16 10:11:48 -070079 if (deployment_config.fabric_switches != null) {
Andy Bavier6c2f8042017-09-19 13:52:30 -070080 stage("Reserve IPs for fabric switches") {
You Wangac934372017-10-16 10:11:48 -070081 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
82 def str = createMACIPbindingStr("fabric", i+1,
83 "${deployment_config.fabric_switches[i].mac}",
84 "${deployment_config.fabric_switches[i].ip}")
Andy Bavier6c2f8042017-09-19 13:52:30 -070085 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
86 }
87 }
88 }
89
You Wangcebbd312017-09-11 14:35:24 -070090 stage ("Deploy") {
Luca Pretee92458d2017-10-18 11:52:30 -070091 sh "make build"
You Wangcebbd312017-09-11 14:35:24 -070092 }
93
You Wangac934372017-10-16 10:11:48 -070094 if (deployment_config.compute_nodes != null) {
Luca Prete2339b182017-10-17 11:47:26 -070095 stage ("Power cycle compute nodes") {
You Wangac934372017-10-16 10:11:48 -070096 for(int i=0; i < deployment_config.compute_nodes.size(); i++) {
97 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"
Luca Prete2339b182017-10-17 11:47:26 -070098 }
99 }
100
101 stage ("Wait for compute nodes to get deployed") {
You Wangac934372017-10-16 10:11:48 -0700102 sh "ssh-keygen -f /home/${deployment_config.dev_node.user}/.ssh/known_hosts -R ${deployment_config.head.ip}"
103 def cordApiKey = runHeadNodeCmd("sudo maas-region-admin apikey --username ${deployment_config.head.user}")
104 runHeadNodeCmd("maas login pod-maas http://${deployment_config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
Luca Pretebe198b82017-10-24 17:22:09 -0700105 timeout(time: 90) {
Luca Prete2339b182017-10-17 11:47:26 -0700106 waitUntil {
107 try {
You Wangac934372017-10-16 10:11:48 -0700108 num = runHeadNodeCmd("maas pod-maas nodes list | grep substatus_name | grep -i deployed | wc -l").trim()
109 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete2339b182017-10-17 11:47:26 -0700110 } catch (exception) {
111 return false
112 }
You Wangcebbd312017-09-11 14:35:24 -0700113 }
114 }
115 }
You Wangcebbd312017-09-11 14:35:24 -0700116
Luca Prete2339b182017-10-17 11:47:26 -0700117 stage ("Wait for compute nodes to be provisioned") {
118 timeout(time:45) {
119 waitUntil {
120 try {
You Wangac934372017-10-16 10:11:48 -0700121 num = runHeadNodeCmd("cord prov list | grep -i node | grep -i complete | wc -l").trim()
122 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete2339b182017-10-17 11:47:26 -0700123 } catch (exception) {
124 return false
125 }
You Wangcebbd312017-09-11 14:35:24 -0700126 }
127 }
128 }
Luca Prete2339b182017-10-17 11:47:26 -0700129 }
You Wangcebbd312017-09-11 14:35:24 -0700130
You Wangac934372017-10-16 10:11:48 -0700131 if (deployment_config.fabric_switches != null) {
You Wangcebbd312017-09-11 14:35:24 -0700132 stage ("Wait for fabric switches to get deployed") {
You Wangac934372017-10-16 10:11:48 -0700133 runFabricSwitchCmdAll("sudo onl-onie-boot-mode install")
134 runFabricSwitchCmdAll("sudo reboot")
Andy Bavier6c2f8042017-09-19 13:52:30 -0700135 // Ensure that switches get provisioned after ONIE reinstall.
136 // Delete them if they were provisioned earlier. If the switches are not
137 // present in 'cord prov list', this command has no effect.
You Wangac934372017-10-16 10:11:48 -0700138 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
139 runHeadNodeCmd("cord prov delete ${deployment_config.fabric_switches[i].mac}")
You Wangcebbd312017-09-11 14:35:24 -0700140 }
141 timeout(time: 45) {
142 waitUntil {
143 try {
You Wangac934372017-10-16 10:11:48 -0700144 def harvestCompleted = runHeadNodeCmd("cord harvest list | grep -i fabric | wc -l").trim()
145 return harvestCompleted.toInteger() == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700146 } catch (exception) {
147 return false
148 }
149 }
150 }
151 }
152
153 stage ("Wait for fabric switches to be provisioned") {
154 timeout(time:45) {
155 waitUntil {
156 try {
157 def provCompleted = 0
You Wangac934372017-10-16 10:11:48 -0700158 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
159 def count = runHeadNodeCmd("cord prov list | grep -i ${deployment_config.fabric_switches[i].ip} | grep -i complete | wc -l").trim()
You Wangcebbd312017-09-11 14:35:24 -0700160 provCompleted = provCompleted + count.toInteger()
161 }
You Wangac934372017-10-16 10:11:48 -0700162 return provCompleted == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700163 } catch (exception) {
164 return false
165 }
166 }
167 }
168 }
Marc De Leenheerc7687dc2017-11-27 17:25:09 -0800169
You Wangac934372017-10-16 10:11:48 -0700170 // Post installation configuration starts here
171 fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0]
172 xosUser = "xosadmin@opencord.org"
173 xosPass = runHeadNodeCmd("cat /opt/credentials/xosadmin@opencord.org").trim()
174 stage ("Connect fabric switches and compute nodes to ONOS") {
175 // Configure breakout ports
176 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
177 if (deployment_config.fabric_switches[i].breakout_ports != null) {
178 for(int j=0; j < deployment_config.fabric_switches[i].breakout_ports.size(); j++) {
179 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
180 "${deployment_config.fabric_switches[i].user}",
181 "${deployment_config.fabric_switches[i].pass}",
You Wang59131c02017-12-13 11:18:54 -0800182 "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")
Marc De Leenheerc7687dc2017-11-27 17:25:09 -0800183 }
You Wangac934372017-10-16 10:11:48 -0700184 }
185 }
186 connectFabricAndComputeToOnos()
187 }
188 stage ("Configure the compute nodes") {
189 leafSwitchNum = 0
190 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang7f751c92017-12-14 15:29:11 -0800191 if(deployment_config.fabric_switches[i].containsKey("role")) {
You Wang5c0ed0a2017-12-14 15:03:36 -0800192 if(deployment_config.fabric_switches[i].role.toLowerCase().contains("leaf")) {
193 leafSwitchNum += 1
194 }
You Wangac934372017-10-16 10:11:48 -0700195 }
196 }
You Wangac934372017-10-16 10:11:48 -0700197 for(int i=1; i<=leafSwitchNum; i++) {
198 // Figure out which compute node connects to which switch
199 leafName = "leaf-" + i.toString()
200 computeNames = getComputeNames(leafName)
201 echo "Compute nodes connnected to " + leafName + " switch:"
202 for(name in computeNames) { echo "${name}" }
203 index = 1
204 for(name in computeNames) {
205 if(i>1) {
206 //Update fabric IP of compute nodes
207 index += 1
208 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*/24'").trim()
209 if (fabricIp != "") {
210 tagId = sh(returnStdout: true, script: "curl -u ${xosUser}:${xosPass} -X GET http://${deployment_config.head.ip}/xosapi/v1/core/tags | jq '.[\"items\"][] | select(.value==\"${fabricIp}\") | .id'").trim()
211 newFabricIp = "${fabricIpPrefix}." + i.toString() + "." + index.toString() + "/24"
212 out = sh(returnStdout: true, script: "curl -u ${xosUser}:${xosPass} -X PUT -d '{\"value\":\"${newFabricIp}\"}' http://${deployment_config.head.ip}/xosapi/v1/core/tags/${tagId}").trim()
213 // Wait until the new fabric IP gets configured
214 timeout(time: 5) {
215 waitUntil {
216 try {
217 num = runComputeNodeCmd("${name}", "ip a | grep " + newFabricIp + " | wc -l").trim()
218 return num.toInteger() == 1
219 } catch (exception) {
220 return false
221 }
222 }
223 }
224 }
225 else echo "Cannot find fabric IP matching pattern ${fabricIpPrefix}.[1-9][0-9]*.[0-9]*"
226 }
227 //Add routes to fabric subnets
228 for(int j=1; j<=leafSwitchNum; j++) {
229 if(j!=i) {
230 runComputeNodeCmd("${name}", "sudo ip route add ${fabricIpPrefix}." + j.toString() + ".0/24 via ${fabricIpPrefix}." + i.toString() + ".254 || echo route already exists")
231 }
232 }
233 }
234 }
235 }
236 stage ("Generate and load network configuration") {
237 // Reconnect compute nodes to update the fabric IP in ONOS
238 connectFabricAndComputeToOnos()
239 // Generate network configuration
240 runHeadNodeCmd("""
241 cd /opt/cord_profile/
242 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
243 cord generate > fabric-network-cfg.json
244 """)
245 // Install httpie on the head-node
246 runHeadNodeCmd("sudo pip install httpie")
247 // Delete old ONOS netcfg
248 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
249 // Load new configuration
You Wang487d6272017-12-22 11:04:29 -0800250 runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json")
You Wangac934372017-10-16 10:11:48 -0700251 // Restart ONOS apps
252 runHeadNodeCmd("""
You Wangac934372017-10-16 10:11:48 -0700253 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
254 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
255 """)
Marc De Leenheerc7687dc2017-11-27 17:25:09 -0800256 }
You Wangcebbd312017-09-11 14:35:24 -0700257 }
You Wangcebbd312017-09-11 14:35:24 -0700258 }
Luca Prete9081fcc2017-09-12 14:37:33 -0700259
You Wangac934372017-10-16 10:11:48 -0700260 if (deployment_config.make_release == true) {
Luca Prete9081fcc2017-09-12 14:37:33 -0700261 stage ("Trigger Build") {
262 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
263 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
264 }
265 }
266
267 currentBuild.result = 'SUCCESS'
268 } catch (err) {
269 currentBuild.result = 'FAILURE'
270 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
271 } finally {
272 sh "make -C build clean-all || true"
273 sh "rm -rf *"
274 }
275 echo "RESULT: ${currentBuild.result}"
You Wangcebbd312017-09-11 14:35:24 -0700276 }
277}
278
279/**
280 * Returns a string used to bind IPs and MAC addresses, substituting the values
281 * given.
282 *
You Wangac934372017-10-16 10:11:48 -0700283 * @param word the word used to generate the host name
You Wangcebbd312017-09-11 14:35:24 -0700284 * @param counter the counter used to generate the host name
285 * @param mac the MAC address to substitute
286 * @param ip the IP address to substitute
287 */
You Wangac934372017-10-16 10:11:48 -0700288def createMACIPbindingStr(word, counter, mac, ip) {
289 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
You Wangcebbd312017-09-11 14:35:24 -0700290}
291
292/**
293 * Runs a command on a remote host using sshpass.
294 *
295 * @param ip the node IP address
296 * @param user the node user name
297 * @param pass the node password
298 * @param command the command to run
You Wangac934372017-10-16 10:11:48 -0700299 * @param sshArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700300 * @return the output of the command
301 */
You Wangac934372017-10-16 10:11:48 -0700302def runCmd(ip, user, pass, command, sshArgs="") {
303 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
304}
305
306/**
307 * Runs a command on the head node.
308 *
309 * @param command the command to run
310 * @param sshArgs arguments for the ssh command
311 * @return the output of the command
312 */
313def runHeadNodeCmd(command, sshArgs="") {
314 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}\"")
You Wangcebbd312017-09-11 14:35:24 -0700315}
316
317/**
318 * Runs a command on a fabric switch.
319 *
You Wangac934372017-10-16 10:11:48 -0700320 * @param ip the mgmt IP of the fabric switch, reachable from the head node
321 * @param user the mgmt user name of the fabric switch
322 * @param pass the mgmt password of the fabric switch
323 * @param command the command to run on the fabric switch
324 * @param ssgArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700325 * @return the output of the command
326 */
You Wangac934372017-10-16 10:11:48 -0700327def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
328 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}\"")
329}
330
331/**
332 * Runs a command on all fabric switches
333 *
334 * @param command the command to run on the fabric switches
335 * @param ssgArgs arguments for the ssh command
336 */
337def runFabricSwitchCmdAll(command, sshArgs="") {
338 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
339 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
340 "${deployment_config.fabric_switches[i].user}",
341 "${deployment_config.fabric_switches[i].pass}",
342 "${command}",
343 "${sshArgs}")
344 }
345}
346
347/**
348 * Runs a command on a compute node.
349 *
350 * @param name the name of the compute node
351 * @param command the command to run on the compute node
352 * @param ssgArgs arguments for the ssh command
353 * @return the output of the command
354 */
355def runComputeNodeCmd(name, command, sshArgs="") {
356 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}\"")
357}
358
359/**
360 * Runs a command on all compute nodes
361 *
362 * @param command the command to run on the compute nodes
363 * @param ssgArgs arguments for the ssh command
364 */
365def runComputeNodeCmdAll(command, sshArgs="") {
366 computeNamesAll = getComputeNames()
367 for (name in computeNamesAll) {
368 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
369 }
370}
371
372/**
373 * Runs an ONOS CLI command
374 *
375 * @param name the onos node name, reachable from the head node
376 * @param port the port used to login to ONOS CLI
377 * @param user the user name to login to ONOS CLI
378 * @param pass the password to login to ONOS CLI
379 * @param command the command to run in ONOS CLI
380 * @return the output of the command
381 */
382def runOnosCliCmd(name, port, user, pass, command) {
383 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}\"")
384}
385
386/**
387 * Returns a list of compute node names. When "role" is specified, returns only
388 * names of compute nodes connected to the switch
389 *
390 * @param role the switch role, i.e. "leaf-1"
391 */
392def getComputeNames(role="") {
393 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
394 computeNamesAll = "${computeNamesAll}".split()
395 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
Kailash Khalasi7d14e392018-05-08 12:03:23 -0700396 computeNamesAll = new JsonSlurper().parseText("${computeNamesAll}")
You Wangac934372017-10-16 10:11:48 -0700397 if ("${role}" == "") return computeNamesAll
398 computeNames = []
399 switchMac = ""
400 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang7f751c92017-12-14 15:29:11 -0800401 if(deployment_config.fabric_switches[i].containsKey("role")) {
402 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
403 switchMac = "${deployment_config.fabric_switches[i].mac}"
404 }
You Wangac934372017-10-16 10:11:48 -0700405 }
406 if ("${switchMac}" != "") {
407 switchMac = switchMac.toLowerCase().replaceAll(':','')
408 // Get fabric IPs of compute nodes connected to the switch
You Wang487d6272017-12-22 11:04:29 -0800409 try {
410 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]*\\\"'",
411 "-q").trim()
412 }catch (exception) {
413 return computeNames
414 }
You Wangac934372017-10-16 10:11:48 -0700415 computeFabricIps = "${computeFabricIps}".split()
Kailash Khalasi7d14e392018-05-08 12:03:23 -0700416 computeFabricIps = new JsonSlurper().parseText("${computeFabricIps}")
You Wangac934372017-10-16 10:11:48 -0700417 // Figure out which compute node connects to the switch
418 for (name in computeNamesAll) {
419 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*'").trim()
420 if (fabricIp in computeFabricIps) {
421 computeNames.add("${name}")
422 }
423 }
424 }
425 return computeNames
426}
427
428/**
429 * Connects all fabric switches and compute nodes to ONOS
430 */
431def connectFabricAndComputeToOnos() {
432 // Kill existing switch connections
433 runFabricSwitchCmdAll("./killit || echo no ofagentapp running")
434 // Clean stale ONOS data
435 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "wipe-out -r -j please")
436 // Connect switches to ONOS
437 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
438 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
439 "${deployment_config.fabric_switches[i].user}",
440 "${deployment_config.fabric_switches[i].pass}",
441 "./connect -bg 2>&1 > ${deployment_config.fabric_switches[i].ip}.log",
442 "-qftn")
443 }
444 // Verify ONOS has recognized the switches
445 timeout(time: 5) {
446 waitUntil {
447 try {
448 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric devices | grep available=true | wc -l\"").trim()
449 return num.toInteger() == deployment_config.fabric_switches.size()
450 } catch (exception) {
451 return false
452 }
453 }
454 }
455 // Connect compute nodes to ONOS
You Wangac934372017-10-16 10:11:48 -0700456 runComputeNodeCmdAll("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
457 // Verify ONOS has recognized the hosts
458 timeout(time: 5) {
459 waitUntil {
460 try {
461 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim()
You Wang7f751c92017-12-14 15:29:11 -0800462 return num.toInteger() == deployment_config.compute_nodes.size()
You Wangac934372017-10-16 10:11:48 -0700463 } catch (exception) {
464 return false
465 }
466 }
467 }
You Wangcebbd312017-09-11 14:35:24 -0700468}
Kailash Khalasi7d14e392018-05-08 12:03:23 -0700469