blob: 02e2d0e575559112081cc7e1a18ed26d00a3326f [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 Khalasi58a08dd2018-04-20 12:35:42 -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])
Kailash Khalasi95f3f022018-04-20 12:22:42 -0700276 } finally {
277 sh "make -C build clean-all || true"
278 sh "rm -rf *"
Luca Prete9081fcc2017-09-12 14:37:33 -0700279 }
280 echo "RESULT: ${currentBuild.result}"
You Wangcebbd312017-09-11 14:35:24 -0700281 }
282}
283
284/**
285 * Returns a string used to bind IPs and MAC addresses, substituting the values
286 * given.
287 *
You Wang0a414382017-10-16 10:11:48 -0700288 * @param word the word used to generate the host name
You Wangcebbd312017-09-11 14:35:24 -0700289 * @param counter the counter used to generate the host name
290 * @param mac the MAC address to substitute
291 * @param ip the IP address to substitute
292 */
You Wang0a414382017-10-16 10:11:48 -0700293def createMACIPbindingStr(word, counter, mac, ip) {
294 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
You Wangcebbd312017-09-11 14:35:24 -0700295}
296
297/**
298 * Runs a command on a remote host using sshpass.
299 *
300 * @param ip the node IP address
301 * @param user the node user name
302 * @param pass the node password
303 * @param command the command to run
You Wang0a414382017-10-16 10:11:48 -0700304 * @param sshArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700305 * @return the output of the command
306 */
You Wang0a414382017-10-16 10:11:48 -0700307def runCmd(ip, user, pass, command, sshArgs="") {
308 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
309}
310
311/**
312 * Runs a command on the head node.
313 *
314 * @param command the command to run
315 * @param sshArgs arguments for the ssh command
316 * @return the output of the command
317 */
318def runHeadNodeCmd(command, sshArgs="") {
319 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 -0700320}
321
322/**
323 * Runs a command on a fabric switch.
324 *
You Wang0a414382017-10-16 10:11:48 -0700325 * @param ip the mgmt IP of the fabric switch, reachable from the head node
326 * @param user the mgmt user name of the fabric switch
327 * @param pass the mgmt password of the fabric switch
328 * @param command the command to run on the fabric switch
329 * @param ssgArgs arguments for the ssh command
You Wangcebbd312017-09-11 14:35:24 -0700330 * @return the output of the command
331 */
You Wang0a414382017-10-16 10:11:48 -0700332def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
333 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}\"")
334}
335
336/**
337 * Runs a command on all fabric switches
338 *
339 * @param command the command to run on the fabric switches
340 * @param ssgArgs arguments for the ssh command
341 */
342def runFabricSwitchCmdAll(command, sshArgs="") {
343 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
344 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
345 "${deployment_config.fabric_switches[i].user}",
346 "${deployment_config.fabric_switches[i].pass}",
347 "${command}",
348 "${sshArgs}")
349 }
350}
351
352/**
353 * Runs a command on a compute node.
354 *
355 * @param name the name of the compute node
356 * @param command the command to run on the compute node
357 * @param ssgArgs arguments for the ssh command
358 * @return the output of the command
359 */
360def runComputeNodeCmd(name, command, sshArgs="") {
361 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}\"")
362}
363
364/**
365 * Runs a command on all compute nodes
366 *
367 * @param command the command to run on the compute nodes
368 * @param ssgArgs arguments for the ssh command
369 */
370def runComputeNodeCmdAll(command, sshArgs="") {
371 computeNamesAll = getComputeNames()
372 for (name in computeNamesAll) {
373 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
374 }
375}
376
377/**
378 * Runs an ONOS CLI command
379 *
380 * @param name the onos node name, reachable from the head node
381 * @param port the port used to login to ONOS CLI
382 * @param user the user name to login to ONOS CLI
383 * @param pass the password to login to ONOS CLI
384 * @param command the command to run in ONOS CLI
385 * @return the output of the command
386 */
387def runOnosCliCmd(name, port, user, pass, command) {
388 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}\"")
389}
390
391/**
392 * Returns a list of compute node names. When "role" is specified, returns only
393 * names of compute nodes connected to the switch
394 *
395 * @param role the switch role, i.e. "leaf-1"
396 */
397def getComputeNames(role="") {
398 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
399 computeNamesAll = "${computeNamesAll}".split()
400 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
Kailash Khalasifd360282018-04-20 09:09:54 -0700401 computeNamesAll = new JsonSlurper().parseText("${computeNamesAll}")
You Wang0a414382017-10-16 10:11:48 -0700402 if ("${role}" == "") return computeNamesAll
403 computeNames = []
404 switchMac = ""
405 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wang61b00ea2017-12-14 15:29:11 -0800406 if(deployment_config.fabric_switches[i].containsKey("role")) {
407 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
408 switchMac = "${deployment_config.fabric_switches[i].mac}"
409 }
You Wang0a414382017-10-16 10:11:48 -0700410 }
411 if ("${switchMac}" != "") {
412 switchMac = switchMac.toLowerCase().replaceAll(':','')
413 // Get fabric IPs of compute nodes connected to the switch
You Wang40f09342017-12-22 11:04:29 -0800414 try {
415 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]*\\\"'",
416 "-q").trim()
417 }catch (exception) {
418 return computeNames
419 }
You Wang0a414382017-10-16 10:11:48 -0700420 computeFabricIps = "${computeFabricIps}".split()
Kailash Khalasifd360282018-04-20 09:09:54 -0700421 computeFabricIps = new JsonSlurper().parseText("${computeFabricIps}")
You Wang0a414382017-10-16 10:11:48 -0700422 // Figure out which compute node connects to the switch
423 for (name in computeNamesAll) {
424 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*'").trim()
425 if (fabricIp in computeFabricIps) {
426 computeNames.add("${name}")
427 }
428 }
429 }
430 return computeNames
431}
432
433/**
434 * Connects all fabric switches and compute nodes to ONOS
435 */
436def connectFabricAndComputeToOnos() {
437 // Kill existing switch connections
438 runFabricSwitchCmdAll("./killit || echo no ofagentapp running")
439 // Clean stale ONOS data
440 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "wipe-out -r -j please")
441 // Connect switches to ONOS
442 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
443 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
444 "${deployment_config.fabric_switches[i].user}",
445 "${deployment_config.fabric_switches[i].pass}",
446 "./connect -bg 2>&1 > ${deployment_config.fabric_switches[i].ip}.log",
447 "-qftn")
448 }
449 // Verify ONOS has recognized the switches
450 timeout(time: 5) {
451 waitUntil {
452 try {
453 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric devices | grep available=true | wc -l\"").trim()
454 return num.toInteger() == deployment_config.fabric_switches.size()
455 } catch (exception) {
456 return false
457 }
458 }
459 }
460 // Connect compute nodes to ONOS
You Wang0a414382017-10-16 10:11:48 -0700461 runComputeNodeCmdAll("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
462 // Verify ONOS has recognized the hosts
463 timeout(time: 5) {
464 waitUntil {
465 try {
466 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 -0800467 return num.toInteger() == deployment_config.compute_nodes.size()
You Wang0a414382017-10-16 10:11:48 -0700468 } catch (exception) {
469 return false
470 }
471 }
472 }
You Wangcebbd312017-09-11 14:35:24 -0700473}