blob: 455b0b3f99e060a8abf96bc633919295595109eb [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 Khalasifd360282018-04-20 09:09:54 -070015import groovy.json.JsonSlurper
You Wang0a414382017-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 Wang0a414382017-10-16 10:11:48 -070019deployment_config = null;
20pod_config = null;
You Wangcebbd312017-09-11 14:35:24 -070021
Kailash Khalasifd360282018-04-20 09:09:54 -070022node ('${devNodeName}') {
You Wangcebbd312017-09-11 14:35:24 -070023 timeout (time: 240) {
Kailash Khalasifd360282018-04-20 09:09:54 -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 }
30 stage ("Clean-up previous build") {
31 sh "make -C build PODCONFIG_PATH=../orchestration/profiles/automation/${deployment_config.pod_config.file_name} config"
32 sh "make -C build clean-all || true"
33 sh "rm -rf *"
34 }
Luca Prete7b4a1e82017-09-12 10:44:48 -070035 stage ('Remove old head node from known hosts') {
You Wang0a414382017-10-16 10:11:48 -070036 sh "ssh-keygen -R ${deployment_config.head.ip}"
You Wangcebbd312017-09-11 14:35:24 -070037 }
38 stage ('Checkout cord repo') {
39 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
40 }
41
Luca Prete9081fcc2017-09-12 14:37:33 -070042 try {
43 dir('build') {
You Wangcebbd312017-09-11 14:35:24 -070044 stage ("Re-deploy head node") {
45 maasOps: {
You Wang0a414382017-10-16 10:11:48 -070046 sh "maas login maas http://${deployment_config.maas.ip}/MAAS/api/2.0 ${deployment_config.maas.api_key}"
47 sh "maas maas machine release ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070048
49 timeout(time: 15) {
50 waitUntil {
51 try {
You Wang0a414382017-10-16 10:11:48 -070052 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Ready"
You Wangcebbd312017-09-11 14:35:24 -070053 return true
54 } catch (exception) {
55 return false
56 }
57 }
58 }
59
60 sh 'maas maas machines allocate'
You Wang0a414382017-10-16 10:11:48 -070061 sh "maas maas machine deploy ${deployment_config.maas.head_system_id}"
You Wangcebbd312017-09-11 14:35:24 -070062
63 timeout(time: 30) {
64 waitUntil {
65 try {
You Wang0a414382017-10-16 10:11:48 -070066 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Deployed"
You Wangcebbd312017-09-11 14:35:24 -070067 return true
68 } catch (exception) {
69 return false
70 }
71 }
72 }
73 }
74 }
75
76 stage ("Download CORD POD configuration") {
You Wang0a414382017-10-16 10:11:48 -070077 sh "cd podconfig; git clone -b ${branch} ${deployment_config.pod_config.repo_url} automation"
You Wangcebbd312017-09-11 14:35:24 -070078 }
79
80 stage ("Generate CORD configuration") {
You Wang0a414382017-10-16 10:11:48 -070081 sh "make PODCONFIG=automation/${deployment_config.pod_config.file_name} config"
You Wangcebbd312017-09-11 14:35:24 -070082 }
83
You Wang0a414382017-10-16 10:11:48 -070084 if (deployment_config.fabric_switches != null) {
Andy Bavier6c2f8042017-09-19 13:52:30 -070085 stage("Reserve IPs for fabric switches") {
You Wang0a414382017-10-16 10:11:48 -070086 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
87 def str = createMACIPbindingStr("fabric", i+1,
88 "${deployment_config.fabric_switches[i].mac}",
89 "${deployment_config.fabric_switches[i].ip}")
Andy Bavier6c2f8042017-09-19 13:52:30 -070090 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
91 }
92 }
93 }
94
You Wangcebbd312017-09-11 14:35:24 -070095 stage ("Deploy") {
Luca Prete604563f2017-10-18 11:52:01 -070096 sh "make build"
You Wangcebbd312017-09-11 14:35:24 -070097 }
98
You Wang0a414382017-10-16 10:11:48 -070099 if (deployment_config.compute_nodes != null) {
Luca Prete9b3a6672017-10-17 11:47:26 -0700100 stage ("Power cycle compute nodes") {
You Wang0a414382017-10-16 10:11:48 -0700101 for(int i=0; i < deployment_config.compute_nodes.size(); i++) {
102 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 Prete9b3a6672017-10-17 11:47:26 -0700103 }
104 }
105
106 stage ("Wait for compute nodes to get deployed") {
You Wang0a414382017-10-16 10:11:48 -0700107 sh "ssh-keygen -f /home/${deployment_config.dev_node.user}/.ssh/known_hosts -R ${deployment_config.head.ip}"
108 def cordApiKey = runHeadNodeCmd("sudo maas-region-admin apikey --username ${deployment_config.head.user}")
109 runHeadNodeCmd("maas login pod-maas http://${deployment_config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
Luca Prete416574f2017-10-24 17:22:09 -0700110 timeout(time: 90) {
Luca Prete9b3a6672017-10-17 11:47:26 -0700111 waitUntil {
112 try {
You Wang0a414382017-10-16 10:11:48 -0700113 num = runHeadNodeCmd("maas pod-maas nodes list | grep substatus_name | grep -i deployed | wc -l").trim()
114 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete9b3a6672017-10-17 11:47:26 -0700115 } catch (exception) {
116 return false
117 }
You Wangcebbd312017-09-11 14:35:24 -0700118 }
119 }
120 }
You Wangcebbd312017-09-11 14:35:24 -0700121
Luca Prete9b3a6672017-10-17 11:47:26 -0700122 stage ("Wait for compute nodes to be provisioned") {
123 timeout(time:45) {
124 waitUntil {
125 try {
You Wang0a414382017-10-16 10:11:48 -0700126 num = runHeadNodeCmd("cord prov list | grep -i node | grep -i complete | wc -l").trim()
127 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Prete9b3a6672017-10-17 11:47:26 -0700128 } catch (exception) {
129 return false
130 }
You Wangcebbd312017-09-11 14:35:24 -0700131 }
132 }
133 }
Luca Prete9b3a6672017-10-17 11:47:26 -0700134 }
You Wangcebbd312017-09-11 14:35:24 -0700135
You Wang0a414382017-10-16 10:11:48 -0700136 if (deployment_config.fabric_switches != null) {
You Wangcebbd312017-09-11 14:35:24 -0700137 stage ("Wait for fabric switches to get deployed") {
You Wang0a414382017-10-16 10:11:48 -0700138 runFabricSwitchCmdAll("sudo onl-onie-boot-mode install")
139 runFabricSwitchCmdAll("sudo reboot")
Andy Bavier6c2f8042017-09-19 13:52:30 -0700140 // Ensure that switches get provisioned after ONIE reinstall.
141 // Delete them if they were provisioned earlier. If the switches are not
142 // present in 'cord prov list', this command has no effect.
You Wang0a414382017-10-16 10:11:48 -0700143 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
144 runHeadNodeCmd("cord prov delete ${deployment_config.fabric_switches[i].mac}")
You Wangcebbd312017-09-11 14:35:24 -0700145 }
146 timeout(time: 45) {
147 waitUntil {
148 try {
You Wang0a414382017-10-16 10:11:48 -0700149 def harvestCompleted = runHeadNodeCmd("cord harvest list | grep -i fabric | wc -l").trim()
150 return harvestCompleted.toInteger() == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700151 } catch (exception) {
152 return false
153 }
154 }
155 }
156 }
157
158 stage ("Wait for fabric switches to be provisioned") {
159 timeout(time:45) {
160 waitUntil {
161 try {
162 def provCompleted = 0
You Wang0a414382017-10-16 10:11:48 -0700163 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
164 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 -0700165 provCompleted = provCompleted + count.toInteger()
166 }
You Wang0a414382017-10-16 10:11:48 -0700167 return provCompleted == deployment_config.fabric_switches.size()
You Wangcebbd312017-09-11 14:35:24 -0700168 } catch (exception) {
169 return false
170 }
171 }
172 }
173 }
Marc De Leenheer392cf452017-11-27 17:25:09 -0800174
You Wang0a414382017-10-16 10:11:48 -0700175 // Post installation configuration starts here
176 fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0]
177 xosUser = "xosadmin@opencord.org"
178 xosPass = runHeadNodeCmd("cat /opt/credentials/xosadmin@opencord.org").trim()
179 stage ("Connect fabric switches and compute nodes to ONOS") {
180 // Configure breakout ports
181 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
182 if (deployment_config.fabric_switches[i].breakout_ports != null) {
183 for(int j=0; j < deployment_config.fabric_switches[i].breakout_ports.size(); j++) {
184 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
185 "${deployment_config.fabric_switches[i].user}",
186 "${deployment_config.fabric_switches[i].pass}",
You Wang43145b32017-12-13 11:18:54 -0800187 "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 Leenheer392cf452017-11-27 17:25:09 -0800188 }
You Wang0a414382017-10-16 10:11:48 -0700189 }
190 }
191 connectFabricAndComputeToOnos()
192 }
193 stage ("Configure the compute nodes") {
194 leafSwitchNum = 0
195 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang61b00ea2017-12-14 15:29:11 -0800196 if(deployment_config.fabric_switches[i].containsKey("role")) {
You Wang8e84c6a2017-12-14 15:03:36 -0800197 if(deployment_config.fabric_switches[i].role.toLowerCase().contains("leaf")) {
198 leafSwitchNum += 1
199 }
You Wang0a414382017-10-16 10:11:48 -0700200 }
201 }
You Wang0a414382017-10-16 10:11:48 -0700202 for(int i=1; i<=leafSwitchNum; i++) {
203 // Figure out which compute node connects to which switch
204 leafName = "leaf-" + i.toString()
205 computeNames = getComputeNames(leafName)
206 echo "Compute nodes connnected to " + leafName + " switch:"
207 for(name in computeNames) { echo "${name}" }
208 index = 1
209 for(name in computeNames) {
210 if(i>1) {
211 //Update fabric IP of compute nodes
212 index += 1
213 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*/24'").trim()
214 if (fabricIp != "") {
215 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()
216 newFabricIp = "${fabricIpPrefix}." + i.toString() + "." + index.toString() + "/24"
217 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()
218 // Wait until the new fabric IP gets configured
219 timeout(time: 5) {
220 waitUntil {
221 try {
222 num = runComputeNodeCmd("${name}", "ip a | grep " + newFabricIp + " | wc -l").trim()
223 return num.toInteger() == 1
224 } catch (exception) {
225 return false
226 }
227 }
228 }
229 }
230 else echo "Cannot find fabric IP matching pattern ${fabricIpPrefix}.[1-9][0-9]*.[0-9]*"
231 }
232 //Add routes to fabric subnets
233 for(int j=1; j<=leafSwitchNum; j++) {
234 if(j!=i) {
235 runComputeNodeCmd("${name}", "sudo ip route add ${fabricIpPrefix}." + j.toString() + ".0/24 via ${fabricIpPrefix}." + i.toString() + ".254 || echo route already exists")
236 }
237 }
238 }
239 }
240 }
241 stage ("Generate and load network configuration") {
242 // Reconnect compute nodes to update the fabric IP in ONOS
243 connectFabricAndComputeToOnos()
244 // Generate network configuration
245 runHeadNodeCmd("""
246 cd /opt/cord_profile/
247 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
248 cord generate > fabric-network-cfg.json
249 """)
250 // Install httpie on the head-node
251 runHeadNodeCmd("sudo pip install httpie")
252 // Delete old ONOS netcfg
253 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
254 // Load new configuration
You Wang40f09342017-12-22 11:04:29 -0800255 runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json")
You Wang0a414382017-10-16 10:11:48 -0700256 // Restart ONOS apps
257 runHeadNodeCmd("""
You Wang0a414382017-10-16 10:11:48 -0700258 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
259 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
260 """)
Marc De Leenheer392cf452017-11-27 17:25:09 -0800261 }
You Wangcebbd312017-09-11 14:35:24 -0700262 }
You Wangcebbd312017-09-11 14:35:24 -0700263 }
Luca Prete9081fcc2017-09-12 14:37:33 -0700264
You Wang0a414382017-10-16 10:11:48 -0700265 if (deployment_config.make_release == true) {
Luca Prete9081fcc2017-09-12 14:37:33 -0700266 stage ("Trigger Build") {
267 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
268 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
269 }
270 }
271
272 currentBuild.result = 'SUCCESS'
273 } catch (err) {
274 currentBuild.result = 'FAILURE'
275 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
Luca Prete9081fcc2017-09-12 14:37:33 -0700276 }
277 echo "RESULT: ${currentBuild.result}"
You Wangcebbd312017-09-11 14:35:24 -0700278 }
279}
280
281/**
282 * Returns a string used to bind IPs and MAC addresses, substituting the values
283 * given.
284 *
You Wang0a414382017-10-16 10:11:48 -0700285 * @param word the word used to generate the host name
You Wangcebbd312017-09-11 14:35:24 -0700286 * @param counter the counter used to generate the host name
287 * @param mac the MAC address to substitute
288 * @param ip the IP address to substitute
289 */
You Wang0a414382017-10-16 10:11:48 -0700290def createMACIPbindingStr(word, counter, mac, ip) {
291 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
You Wangcebbd312017-09-11 14:35:24 -0700292}
293
294/**
295 * Runs a command on a remote host using sshpass.
296 *
297 * @param ip the node IP address
298 * @param user the node user name
299 * @param pass the node password
300 * @param command the command to run
You Wang0a414382017-10-16 10:11:48 -0700301 * @param sshArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700302 * @return the output of the command
303 */
You Wang0a414382017-10-16 10:11:48 -0700304def runCmd(ip, user, pass, command, sshArgs="") {
305 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
306}
307
308/**
309 * Runs a command on the head node.
310 *
311 * @param command the command to run
312 * @param sshArgs arguments for the ssh command
313 * @return the output of the command
314 */
315def runHeadNodeCmd(command, sshArgs="") {
316 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 -0700317}
318
319/**
320 * Runs a command on a fabric switch.
321 *
You Wang0a414382017-10-16 10:11:48 -0700322 * @param ip the mgmt IP of the fabric switch, reachable from the head node
323 * @param user the mgmt user name of the fabric switch
324 * @param pass the mgmt password of the fabric switch
325 * @param command the command to run on the fabric switch
326 * @param ssgArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700327 * @return the output of the command
328 */
You Wang0a414382017-10-16 10:11:48 -0700329def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
330 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}\"")
331}
332
333/**
334 * Runs a command on all fabric switches
335 *
336 * @param command the command to run on the fabric switches
337 * @param ssgArgs arguments for the ssh command
338 */
339def runFabricSwitchCmdAll(command, sshArgs="") {
340 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
341 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
342 "${deployment_config.fabric_switches[i].user}",
343 "${deployment_config.fabric_switches[i].pass}",
344 "${command}",
345 "${sshArgs}")
346 }
347}
348
349/**
350 * Runs a command on a compute node.
351 *
352 * @param name the name of the compute node
353 * @param command the command to run on the compute node
354 * @param ssgArgs arguments for the ssh command
355 * @return the output of the command
356 */
357def runComputeNodeCmd(name, command, sshArgs="") {
358 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}\"")
359}
360
361/**
362 * Runs a command on all compute nodes
363 *
364 * @param command the command to run on the compute nodes
365 * @param ssgArgs arguments for the ssh command
366 */
367def runComputeNodeCmdAll(command, sshArgs="") {
368 computeNamesAll = getComputeNames()
369 for (name in computeNamesAll) {
370 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
371 }
372}
373
374/**
375 * Runs an ONOS CLI command
376 *
377 * @param name the onos node name, reachable from the head node
378 * @param port the port used to login to ONOS CLI
379 * @param user the user name to login to ONOS CLI
380 * @param pass the password to login to ONOS CLI
381 * @param command the command to run in ONOS CLI
382 * @return the output of the command
383 */
384def runOnosCliCmd(name, port, user, pass, command) {
385 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}\"")
386}
387
388/**
389 * Returns a list of compute node names. When "role" is specified, returns only
390 * names of compute nodes connected to the switch
391 *
392 * @param role the switch role, i.e. "leaf-1"
393 */
394def getComputeNames(role="") {
395 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
396 computeNamesAll = "${computeNamesAll}".split()
397 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
Kailash Khalasifd360282018-04-20 09:09:54 -0700398 computeNamesAll = new JsonSlurper().parseText("${computeNamesAll}")
You Wang0a414382017-10-16 10:11:48 -0700399 if ("${role}" == "") return computeNamesAll
400 computeNames = []
401 switchMac = ""
402 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang61b00ea2017-12-14 15:29:11 -0800403 if(deployment_config.fabric_switches[i].containsKey("role")) {
404 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
405 switchMac = "${deployment_config.fabric_switches[i].mac}"
406 }
You Wang0a414382017-10-16 10:11:48 -0700407 }
408 if ("${switchMac}" != "") {
409 switchMac = switchMac.toLowerCase().replaceAll(':','')
410 // Get fabric IPs of compute nodes connected to the switch
You Wang40f09342017-12-22 11:04:29 -0800411 try {
412 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]*\\\"'",
413 "-q").trim()
414 }catch (exception) {
415 return computeNames
416 }
You Wang0a414382017-10-16 10:11:48 -0700417 computeFabricIps = "${computeFabricIps}".split()
Kailash Khalasifd360282018-04-20 09:09:54 -0700418 computeFabricIps = new JsonSlurper().parseText("${computeFabricIps}")
You Wang0a414382017-10-16 10:11:48 -0700419 // Figure out which compute node connects to the switch
420 for (name in computeNamesAll) {
421 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*'").trim()
422 if (fabricIp in computeFabricIps) {
423 computeNames.add("${name}")
424 }
425 }
426 }
427 return computeNames
428}
429
430/**
431 * Connects all fabric switches and compute nodes to ONOS
432 */
433def connectFabricAndComputeToOnos() {
434 // Kill existing switch connections
435 runFabricSwitchCmdAll("./killit || echo no ofagentapp running")
436 // Clean stale ONOS data
437 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "wipe-out -r -j please")
438 // Connect switches to ONOS
439 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
440 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
441 "${deployment_config.fabric_switches[i].user}",
442 "${deployment_config.fabric_switches[i].pass}",
443 "./connect -bg 2>&1 > ${deployment_config.fabric_switches[i].ip}.log",
444 "-qftn")
445 }
446 // Verify ONOS has recognized the switches
447 timeout(time: 5) {
448 waitUntil {
449 try {
450 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric devices | grep available=true | wc -l\"").trim()
451 return num.toInteger() == deployment_config.fabric_switches.size()
452 } catch (exception) {
453 return false
454 }
455 }
456 }
457 // Connect compute nodes to ONOS
You Wang0a414382017-10-16 10:11:48 -0700458 runComputeNodeCmdAll("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
459 // Verify ONOS has recognized the hosts
460 timeout(time: 5) {
461 waitUntil {
462 try {
463 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim()
You Wang61b00ea2017-12-14 15:29:11 -0800464 return num.toInteger() == deployment_config.compute_nodes.size()
You Wang0a414382017-10-16 10:11:48 -0700465 } catch (exception) {
466 return false
467 }
468 }
469 }
You Wangcebbd312017-09-11 14:35:24 -0700470}