blob: a542c5d0d709bb84db220f7930a4635074e4cc8d [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
You Wangac934372017-10-16 10:11:48 -070015import groovy.json.JsonSlurperClassic
16
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
22node ('master') {
23 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
24
25 stage ("Generate and Copy Manifest file") {
26 sh returnStdout: true, script: 'repo manifest -r -o ' + filename
27 sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp'
28 }
29
30 stage ("Parse deployment configuration file") {
31 sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
32 sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
You Wangac934372017-10-16 10:11:48 -070033 deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
34 pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}"
You Wangcebbd312017-09-11 14:35:24 -070035 }
36}
37
You Wangac934372017-10-16 10:11:48 -070038node ("${deployment_config.dev_node.name}") {
You Wangcebbd312017-09-11 14:35:24 -070039 timeout (time: 240) {
Luca Prete7b4a1e82017-09-12 10:44:48 -070040 stage ('Remove old head node from known hosts') {
You Wangac934372017-10-16 10:11:48 -070041 sh "ssh-keygen -R ${deployment_config.head.ip}"
You Wangcebbd312017-09-11 14:35:24 -070042 }
43 stage ('Checkout cord repo') {
44 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
45 }
46
Luca Prete9081fcc2017-09-12 14:37:33 -070047 try {
48 dir('build') {
You Wangcebbd312017-09-11 14:35:24 -070049 stage ("Re-deploy head node") {
50 maasOps: {
You Wangac934372017-10-16 10:11:48 -070051 sh "maas login maas http://${deployment_config.maas.ip}/MAAS/api/2.0 ${deployment_config.maas.api_key}"
52 sh "maas maas machine release ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070053
54 timeout(time: 15) {
55 waitUntil {
56 try {
You Wangac934372017-10-16 10:11:48 -070057 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Ready"
You Wangcebbd312017-09-11 14:35:24 -070058 return true
59 } catch (exception) {
60 return false
61 }
62 }
63 }
64
65 sh 'maas maas machines allocate'
You Wangac934372017-10-16 10:11:48 -070066 sh "maas maas machine deploy ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070067
68 timeout(time: 30) {
69 waitUntil {
70 try {
You Wangac934372017-10-16 10:11:48 -070071 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Deployed"
You Wangcebbd312017-09-11 14:35:24 -070072 return true
73 } catch (exception) {
74 return false
75 }
76 }
77 }
78 }
79 }
80
81 stage ("Download CORD POD configuration") {
You Wangac934372017-10-16 10:11:48 -070082 sh "cd podconfig; git clone -b ${branch} ${deployment_config.pod_config.repo_url} automation"
You Wangcebbd312017-09-11 14:35:24 -070083 }
84
85 stage ("Generate CORD configuration") {
You Wangac934372017-10-16 10:11:48 -070086 sh "make PODCONFIG=automation/${deployment_config.pod_config.file_name} config"
You Wangcebbd312017-09-11 14:35:24 -070087 }
88
You Wangac934372017-10-16 10:11:48 -070089 if (deployment_config.fabric_switches != null) {
Andy Bavier6c2f8042017-09-19 13:52:30 -070090 stage("Reserve IPs for fabric switches") {
You Wangac934372017-10-16 10:11:48 -070091 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
92 def str = createMACIPbindingStr("fabric", i+1,
93 "${deployment_config.fabric_switches[i].mac}",
94 "${deployment_config.fabric_switches[i].ip}")
Andy Bavier6c2f8042017-09-19 13:52:30 -070095 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
96 }
97 }
98 }
99
You Wangcebbd312017-09-11 14:35:24 -0700100 stage ("Deploy") {
Luca Pretee92458d2017-10-18 11:52:30 -0700101 sh "make build"
You Wangcebbd312017-09-11 14:35:24 -0700102 }
103
You Wangac934372017-10-16 10:11:48 -0700104 if (deployment_config.compute_nodes != null) {
Luca Prete2339b182017-10-17 11:47:26 -0700105 stage ("Power cycle compute nodes") {
You Wangac934372017-10-16 10:11:48 -0700106 for(int i=0; i < deployment_config.compute_nodes.size(); i++) {
107 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 -0700108 }
109 }
110
111 stage ("Wait for compute nodes to get deployed") {
You Wangac934372017-10-16 10:11:48 -0700112 sh "ssh-keygen -f /home/${deployment_config.dev_node.user}/.ssh/known_hosts -R ${deployment_config.head.ip}"
113 def cordApiKey = runHeadNodeCmd("sudo maas-region-admin apikey --username ${deployment_config.head.user}")
114 runHeadNodeCmd("maas login pod-maas http://${deployment_config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
Luca Pretebe198b82017-10-24 17:22:09 -0700115 timeout(time: 90) {
Luca Prete2339b182017-10-17 11:47:26 -0700116 waitUntil {
117 try {
You Wangac934372017-10-16 10:11:48 -0700118 num = runHeadNodeCmd("maas pod-maas nodes list | grep substatus_name | grep -i deployed | wc -l").trim()
119 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete2339b182017-10-17 11:47:26 -0700120 } catch (exception) {
121 return false
122 }
You Wangcebbd312017-09-11 14:35:24 -0700123 }
124 }
125 }
You Wangcebbd312017-09-11 14:35:24 -0700126
Luca Prete2339b182017-10-17 11:47:26 -0700127 stage ("Wait for compute nodes to be provisioned") {
128 timeout(time:45) {
129 waitUntil {
130 try {
You Wangac934372017-10-16 10:11:48 -0700131 num = runHeadNodeCmd("cord prov list | grep -i node | grep -i complete | wc -l").trim()
132 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete2339b182017-10-17 11:47:26 -0700133 } catch (exception) {
134 return false
135 }
You Wangcebbd312017-09-11 14:35:24 -0700136 }
137 }
138 }
Luca Prete2339b182017-10-17 11:47:26 -0700139 }
You Wangcebbd312017-09-11 14:35:24 -0700140
You Wangac934372017-10-16 10:11:48 -0700141 if (deployment_config.fabric_switches != null) {
You Wangcebbd312017-09-11 14:35:24 -0700142 stage ("Wait for fabric switches to get deployed") {
You Wangac934372017-10-16 10:11:48 -0700143 runFabricSwitchCmdAll("sudo onl-onie-boot-mode install")
144 runFabricSwitchCmdAll("sudo reboot")
Andy Bavier6c2f8042017-09-19 13:52:30 -0700145 // Ensure that switches get provisioned after ONIE reinstall.
146 // Delete them if they were provisioned earlier. If the switches are not
147 // present in 'cord prov list', this command has no effect.
You Wangac934372017-10-16 10:11:48 -0700148 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
149 runHeadNodeCmd("cord prov delete ${deployment_config.fabric_switches[i].mac}")
You Wangcebbd312017-09-11 14:35:24 -0700150 }
151 timeout(time: 45) {
152 waitUntil {
153 try {
You Wangac934372017-10-16 10:11:48 -0700154 def harvestCompleted = runHeadNodeCmd("cord harvest list | grep -i fabric | wc -l").trim()
155 return harvestCompleted.toInteger() == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700156 } catch (exception) {
157 return false
158 }
159 }
160 }
161 }
162
163 stage ("Wait for fabric switches to be provisioned") {
164 timeout(time:45) {
165 waitUntil {
166 try {
167 def provCompleted = 0
You Wangac934372017-10-16 10:11:48 -0700168 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
169 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 -0700170 provCompleted = provCompleted + count.toInteger()
171 }
You Wangac934372017-10-16 10:11:48 -0700172 return provCompleted == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700173 } catch (exception) {
174 return false
175 }
176 }
177 }
178 }
Marc De Leenheerc7687dc2017-11-27 17:25:09 -0800179
You Wangac934372017-10-16 10:11:48 -0700180 // Post installation configuration starts here
181 fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0]
182 xosUser = "xosadmin@opencord.org"
183 xosPass = runHeadNodeCmd("cat /opt/credentials/xosadmin@opencord.org").trim()
184 stage ("Connect fabric switches and compute nodes to ONOS") {
185 // Configure breakout ports
186 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
187 if (deployment_config.fabric_switches[i].breakout_ports != null) {
188 for(int j=0; j < deployment_config.fabric_switches[i].breakout_ports.size(); j++) {
189 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
190 "${deployment_config.fabric_switches[i].user}",
191 "${deployment_config.fabric_switches[i].pass}",
You Wang59131c02017-12-13 11:18:54 -0800192 "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 -0800193 }
You Wangac934372017-10-16 10:11:48 -0700194 }
195 }
196 connectFabricAndComputeToOnos()
197 }
198 stage ("Configure the compute nodes") {
199 leafSwitchNum = 0
200 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang5c0ed0a2017-12-14 15:03:36 -0800201 if(deployment_config.fabric_switches[i].containsKey("role") {
202 if(deployment_config.fabric_switches[i].role.toLowerCase().contains("leaf")) {
203 leafSwitchNum += 1
204 }
You Wangac934372017-10-16 10:11:48 -0700205 }
206 }
207 // Configure head-node
208 // Add routes to fabric subnets
209 for(int i=2; i<=leafSwitchNum; i++) {
210 runHeadNodeCmd("sudo ip route add ${fabricIpPrefix}." + i.toString() + ".0/24 via ${fabricIpPrefix}.1.254 || echo route already exists")
211 }
212 for(int i=1; i<=leafSwitchNum; i++) {
213 // Figure out which compute node connects to which switch
214 leafName = "leaf-" + i.toString()
215 computeNames = getComputeNames(leafName)
216 echo "Compute nodes connnected to " + leafName + " switch:"
217 for(name in computeNames) { echo "${name}" }
218 index = 1
219 for(name in computeNames) {
220 if(i>1) {
221 //Update fabric IP of compute nodes
222 index += 1
223 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*/24'").trim()
224 if (fabricIp != "") {
225 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()
226 newFabricIp = "${fabricIpPrefix}." + i.toString() + "." + index.toString() + "/24"
227 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()
228 // Wait until the new fabric IP gets configured
229 timeout(time: 5) {
230 waitUntil {
231 try {
232 num = runComputeNodeCmd("${name}", "ip a | grep " + newFabricIp + " | wc -l").trim()
233 return num.toInteger() == 1
234 } catch (exception) {
235 return false
236 }
237 }
238 }
239 }
240 else echo "Cannot find fabric IP matching pattern ${fabricIpPrefix}.[1-9][0-9]*.[0-9]*"
241 }
242 //Add routes to fabric subnets
243 for(int j=1; j<=leafSwitchNum; j++) {
244 if(j!=i) {
245 runComputeNodeCmd("${name}", "sudo ip route add ${fabricIpPrefix}." + j.toString() + ".0/24 via ${fabricIpPrefix}." + i.toString() + ".254 || echo route already exists")
246 }
247 }
248 }
249 }
250 }
251 stage ("Generate and load network configuration") {
252 // Reconnect compute nodes to update the fabric IP in ONOS
253 connectFabricAndComputeToOnos()
254 // Generate network configuration
255 runHeadNodeCmd("""
256 cd /opt/cord_profile/
257 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
258 cord generate > fabric-network-cfg.json
259 """)
260 // Install httpie on the head-node
261 runHeadNodeCmd("sudo pip install httpie")
262 // Delete old ONOS netcfg
263 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
264 // Load new configuration
265 runHeadNodeCmd("""
266 cd /opt/cord_profile
267 docker-compose -p ${pod_config.cord_profile} exec -T xos_ui python /opt/xos/tosca/run.py xosadmin@opencord.org /opt/cord_profile/fabric-service.yaml
268 """)
269 // Restart ONOS apps
270 runHeadNodeCmd("""
271 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.vrouter/active; sleep 5
272 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.vrouter/active; sleep 5
273 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
274 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
275 """)
Marc De Leenheerc7687dc2017-11-27 17:25:09 -0800276 }
You Wangcebbd312017-09-11 14:35:24 -0700277 }
You Wangcebbd312017-09-11 14:35:24 -0700278 }
Luca Prete9081fcc2017-09-12 14:37:33 -0700279
You Wangac934372017-10-16 10:11:48 -0700280 if (deployment_config.make_release == true) {
Luca Prete9081fcc2017-09-12 14:37:33 -0700281 stage ("Trigger Build") {
282 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
283 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
284 }
285 }
286
287 currentBuild.result = 'SUCCESS'
288 } catch (err) {
289 currentBuild.result = 'FAILURE'
290 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
291 } finally {
292 sh "make -C build clean-all || true"
293 sh "rm -rf *"
294 }
295 echo "RESULT: ${currentBuild.result}"
You Wangcebbd312017-09-11 14:35:24 -0700296 }
297}
298
299/**
300 * Returns a string used to bind IPs and MAC addresses, substituting the values
301 * given.
302 *
You Wangac934372017-10-16 10:11:48 -0700303 * @param word the word used to generate the host name
You Wangcebbd312017-09-11 14:35:24 -0700304 * @param counter the counter used to generate the host name
305 * @param mac the MAC address to substitute
306 * @param ip the IP address to substitute
307 */
You Wangac934372017-10-16 10:11:48 -0700308def createMACIPbindingStr(word, counter, mac, ip) {
309 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
You Wangcebbd312017-09-11 14:35:24 -0700310}
311
312/**
313 * Runs a command on a remote host using sshpass.
314 *
315 * @param ip the node IP address
316 * @param user the node user name
317 * @param pass the node password
318 * @param command the command to run
You Wangac934372017-10-16 10:11:48 -0700319 * @param sshArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700320 * @return the output of the command
321 */
You Wangac934372017-10-16 10:11:48 -0700322def runCmd(ip, user, pass, command, sshArgs="") {
323 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
324}
325
326/**
327 * Runs a command on the head node.
328 *
329 * @param command the command to run
330 * @param sshArgs arguments for the ssh command
331 * @return the output of the command
332 */
333def runHeadNodeCmd(command, sshArgs="") {
334 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 -0700335}
336
337/**
338 * Runs a command on a fabric switch.
339 *
You Wangac934372017-10-16 10:11:48 -0700340 * @param ip the mgmt IP of the fabric switch, reachable from the head node
341 * @param user the mgmt user name of the fabric switch
342 * @param pass the mgmt password of the fabric switch
343 * @param command the command to run on the fabric switch
344 * @param ssgArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700345 * @return the output of the command
346 */
You Wangac934372017-10-16 10:11:48 -0700347def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
348 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}\"")
349}
350
351/**
352 * Runs a command on all fabric switches
353 *
354 * @param command the command to run on the fabric switches
355 * @param ssgArgs arguments for the ssh command
356 */
357def runFabricSwitchCmdAll(command, sshArgs="") {
358 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
359 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
360 "${deployment_config.fabric_switches[i].user}",
361 "${deployment_config.fabric_switches[i].pass}",
362 "${command}",
363 "${sshArgs}")
364 }
365}
366
367/**
368 * Runs a command on a compute node.
369 *
370 * @param name the name of the compute node
371 * @param command the command to run on the compute node
372 * @param ssgArgs arguments for the ssh command
373 * @return the output of the command
374 */
375def runComputeNodeCmd(name, command, sshArgs="") {
376 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}\"")
377}
378
379/**
380 * Runs a command on all compute nodes
381 *
382 * @param command the command to run on the compute nodes
383 * @param ssgArgs arguments for the ssh command
384 */
385def runComputeNodeCmdAll(command, sshArgs="") {
386 computeNamesAll = getComputeNames()
387 for (name in computeNamesAll) {
388 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
389 }
390}
391
392/**
393 * Runs an ONOS CLI command
394 *
395 * @param name the onos node name, reachable from the head node
396 * @param port the port used to login to ONOS CLI
397 * @param user the user name to login to ONOS CLI
398 * @param pass the password to login to ONOS CLI
399 * @param command the command to run in ONOS CLI
400 * @return the output of the command
401 */
402def runOnosCliCmd(name, port, user, pass, command) {
403 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}\"")
404}
405
406/**
407 * Returns a list of compute node names. When "role" is specified, returns only
408 * names of compute nodes connected to the switch
409 *
410 * @param role the switch role, i.e. "leaf-1"
411 */
412def getComputeNames(role="") {
413 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
414 computeNamesAll = "${computeNamesAll}".split()
415 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
416 computeNamesAll = new JsonSlurperClassic().parseText("${computeNamesAll}")
417 if ("${role}" == "") return computeNamesAll
418 computeNames = []
419 switchMac = ""
420 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
421 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
422 switchMac = "${deployment_config.fabric_switches[i].mac}"
423 }
424 if ("${switchMac}" != "") {
425 switchMac = switchMac.toLowerCase().replaceAll(':','')
426 // Get fabric IPs of compute nodes connected to the switch
427 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]*\\\"'",
428 "-q").trim()
429 computeFabricIps = "${computeFabricIps}".split()
430 computeFabricIps = new JsonSlurperClassic().parseText("${computeFabricIps}")
431 // Figure out which compute node connects to the switch
432 for (name in computeNamesAll) {
433 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*'").trim()
434 if (fabricIp in computeFabricIps) {
435 computeNames.add("${name}")
436 }
437 }
438 }
439 return computeNames
440}
441
442/**
443 * Connects all fabric switches and compute nodes to ONOS
444 */
445def connectFabricAndComputeToOnos() {
446 // Kill existing switch connections
447 runFabricSwitchCmdAll("./killit || echo no ofagentapp running")
448 // Clean stale ONOS data
449 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "wipe-out -r -j please")
450 // Connect switches to ONOS
451 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
452 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
453 "${deployment_config.fabric_switches[i].user}",
454 "${deployment_config.fabric_switches[i].pass}",
455 "./connect -bg 2>&1 > ${deployment_config.fabric_switches[i].ip}.log",
456 "-qftn")
457 }
458 // Verify ONOS has recognized the switches
459 timeout(time: 5) {
460 waitUntil {
461 try {
462 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric devices | grep available=true | wc -l\"").trim()
463 return num.toInteger() == deployment_config.fabric_switches.size()
464 } catch (exception) {
465 return false
466 }
467 }
468 }
469 // Connect compute nodes to ONOS
470 runHeadNodeCmd("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
471 runComputeNodeCmdAll("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
472 // Verify ONOS has recognized the hosts
473 timeout(time: 5) {
474 waitUntil {
475 try {
476 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim()
477 return num.toInteger() == deployment_config.compute_nodes.size() + 1
478 } catch (exception) {
479 return false
480 }
481 }
482 }
You Wangcebbd312017-09-11 14:35:24 -0700483}