blob: 6480dd13ef16ea0b43b0739b68b15a60b4d9eeaa [file] [log] [blame]
Luca Pretee2d51fd2017-08-31 16:19:21 -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 Wang1abf2bf2017-12-12 15:21:07 -080015import groovy.json.JsonSlurperClassic
16
Luca Pretee2d51fd2017-08-31 16:19:21 -070017def filename = 'manifest-${branch}.xml'
18def manifestUrl = 'https://gerrit.opencord.org/manifest'
You Wang1abf2bf2017-12-12 15:21:07 -080019deployment_config = null;
20pod_config = null;
Luca Pretee2d51fd2017-08-31 16:19:21 -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 Wang1abf2bf2017-12-12 15:21:07 -080033 deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
34 pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}"
Luca Pretee2d51fd2017-08-31 16:19:21 -070035 }
36}
37
You Wang1abf2bf2017-12-12 15:21:07 -080038node ("${deployment_config.dev_node.name}") {
Luca Pretee2d51fd2017-08-31 16:19:21 -070039 timeout (time: 240) {
Luca Prete225d9652017-09-12 10:44:48 -070040 stage ('Remove old head node from known hosts') {
You Wang1abf2bf2017-12-12 15:21:07 -080041 sh "ssh-keygen -R ${deployment_config.head.ip}"
You Wangf9cb2f32017-09-11 13:26:42 -070042 }
Luca Pretee2d51fd2017-08-31 16:19:21 -070043 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 Pretefcbc54b2017-09-12 14:37:33 -070047 try {
48 dir('build') {
Luca Pretee2d51fd2017-08-31 16:19:21 -070049 stage ("Re-deploy head node") {
50 maasOps: {
You Wang1abf2bf2017-12-12 15:21:07 -080051 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}"
Luca Pretee2d51fd2017-08-31 16:19:21 -070053
54 timeout(time: 15) {
55 waitUntil {
56 try {
You Wang1abf2bf2017-12-12 15:21:07 -080057 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Ready"
Luca Pretee2d51fd2017-08-31 16:19:21 -070058 return true
59 } catch (exception) {
60 return false
61 }
62 }
63 }
64
65 sh 'maas maas machines allocate'
You Wang1abf2bf2017-12-12 15:21:07 -080066 sh "maas maas machine deploy ${deployment_config.maas.head_system_id}"
Luca Pretee2d51fd2017-08-31 16:19:21 -070067
68 timeout(time: 30) {
69 waitUntil {
70 try {
You Wang1abf2bf2017-12-12 15:21:07 -080071 sh "maas maas machine read ${deployment_config.maas.head_system_id} | grep Deployed"
Luca Pretee2d51fd2017-08-31 16:19:21 -070072 return true
73 } catch (exception) {
74 return false
75 }
76 }
77 }
78 }
79 }
80
81 stage ("Download CORD POD configuration") {
You Wange6fbdae2018-01-02 11:35:10 -080082 sh "cd ../orchestration/profiles; git clone -b ${branch} ${deployment_config.pod_config.repo_url} automation"
Luca Pretee2d51fd2017-08-31 16:19:21 -070083 }
84
85 stage ("Generate CORD configuration") {
You Wange6fbdae2018-01-02 11:35:10 -080086 sh "make USECASE=${pod_config.cord_profile} PODCONFIG_D=../orchestration/profiles PODCONFIG=automation/${deployment_config.pod_config.file_name} config"
Luca Pretee2d51fd2017-08-31 16:19:21 -070087 }
88
You Wang1abf2bf2017-12-12 15:21:07 -080089 if (deployment_config.fabric_switches != null) {
Andy Bavier700f2662017-09-19 13:52:30 -070090 stage("Reserve IPs for fabric switches") {
You Wang1abf2bf2017-12-12 15:21:07 -080091 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 Bavier700f2662017-09-19 13:52:30 -070095 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
96 }
97 }
98 }
99
Luca Pretee2d51fd2017-08-31 16:19:21 -0700100 stage ("Deploy") {
Luca Prete614d6702017-10-18 11:52:55 -0700101 sh "make build"
Luca Pretee2d51fd2017-08-31 16:19:21 -0700102 }
103
You Wang1abf2bf2017-12-12 15:21:07 -0800104 if (deployment_config.compute_nodes != null) {
Luca Pretee2095272017-10-17 11:47:26 -0700105 stage ("Power cycle compute nodes") {
You Wang1abf2bf2017-12-12 15:21:07 -0800106 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 Pretee2095272017-10-17 11:47:26 -0700108 }
109 }
110
111 stage ("Wait for compute nodes to get deployed") {
You Wang1abf2bf2017-12-12 15:21:07 -0800112 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 Prete49c818c2017-10-24 17:22:09 -0700115 timeout(time: 90) {
Luca Pretee2095272017-10-17 11:47:26 -0700116 waitUntil {
117 try {
You Wang1abf2bf2017-12-12 15:21:07 -0800118 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 Pretee2095272017-10-17 11:47:26 -0700120 } catch (exception) {
121 return false
122 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700123 }
124 }
125 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700126
Luca Pretee2095272017-10-17 11:47:26 -0700127 stage ("Wait for compute nodes to be provisioned") {
128 timeout(time:45) {
129 waitUntil {
130 try {
You Wang1abf2bf2017-12-12 15:21:07 -0800131 num = runHeadNodeCmd("cord prov list | grep -i node | grep -i complete | wc -l").trim()
132 return num.toInteger() == deployment_config.compute_nodes.size()
Luca Pretee2095272017-10-17 11:47:26 -0700133 } catch (exception) {
134 return false
135 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700136 }
137 }
138 }
Luca Pretee2095272017-10-17 11:47:26 -0700139 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700140
You Wang1abf2bf2017-12-12 15:21:07 -0800141 if (deployment_config.fabric_switches != null) {
Luca Pretee2d51fd2017-08-31 16:19:21 -0700142 stage ("Wait for fabric switches to get deployed") {
You Wang1abf2bf2017-12-12 15:21:07 -0800143 runFabricSwitchCmdAll("sudo onl-onie-boot-mode install")
144 runFabricSwitchCmdAll("sudo reboot")
Andy Bavier700f2662017-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 Wang1abf2bf2017-12-12 15:21:07 -0800148 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
149 runHeadNodeCmd("cord prov delete ${deployment_config.fabric_switches[i].mac}")
Luca Pretee2d51fd2017-08-31 16:19:21 -0700150 }
151 timeout(time: 45) {
152 waitUntil {
153 try {
You Wang1abf2bf2017-12-12 15:21:07 -0800154 def harvestCompleted = runHeadNodeCmd("cord harvest list | grep -i fabric | wc -l").trim()
155 return harvestCompleted.toInteger() == deployment_config.fabric_switches.size()
Luca Pretee2d51fd2017-08-31 16:19:21 -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 Wang1abf2bf2017-12-12 15:21:07 -0800168 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()
Luca Pretee2d51fd2017-08-31 16:19:21 -0700170 provCompleted = provCompleted + count.toInteger()
171 }
You Wang1abf2bf2017-12-12 15:21:07 -0800172 return provCompleted == deployment_config.fabric_switches.size()
Luca Pretee2d51fd2017-08-31 16:19:21 -0700173 } catch (exception) {
174 return false
175 }
176 }
177 }
178 }
Marc De Leenheer672afa82017-11-27 17:25:09 -0800179
You Wang1abf2bf2017-12-12 15:21:07 -0800180 // 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 Wangd1d67aa2017-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 Leenheer672afa82017-11-27 17:25:09 -0800193 }
You Wang1abf2bf2017-12-12 15:21:07 -0800194 }
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 Wangd37a1732017-12-14 15:29:11 -0800201 if(deployment_config.fabric_switches[i].containsKey("role")) {
You Wangdd8793e2017-12-14 15:03:36 -0800202 if(deployment_config.fabric_switches[i].role.toLowerCase().contains("leaf")) {
203 leafSwitchNum += 1
204 }
You Wang1abf2bf2017-12-12 15:21:07 -0800205 }
206 }
You Wang1abf2bf2017-12-12 15:21:07 -0800207 for(int i=1; i<=leafSwitchNum; i++) {
208 // Figure out which compute node connects to which switch
209 leafName = "leaf-" + i.toString()
210 computeNames = getComputeNames(leafName)
211 echo "Compute nodes connnected to " + leafName + " switch:"
212 for(name in computeNames) { echo "${name}" }
213 index = 1
214 for(name in computeNames) {
215 if(i>1) {
216 //Update fabric IP of compute nodes
217 index += 1
218 fabricIp = runComputeNodeCmd("${name}", "ip a | grep -o '${fabricIpPrefix}.[1-9][0-9]*.[0-9]*/24'").trim()
219 if (fabricIp != "") {
220 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()
221 newFabricIp = "${fabricIpPrefix}." + i.toString() + "." + index.toString() + "/24"
222 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()
223 // Wait until the new fabric IP gets configured
224 timeout(time: 5) {
225 waitUntil {
226 try {
227 num = runComputeNodeCmd("${name}", "ip a | grep " + newFabricIp + " | wc -l").trim()
228 return num.toInteger() == 1
229 } catch (exception) {
230 return false
231 }
232 }
233 }
234 }
235 else echo "Cannot find fabric IP matching pattern ${fabricIpPrefix}.[1-9][0-9]*.[0-9]*"
236 }
237 //Add routes to fabric subnets
238 for(int j=1; j<=leafSwitchNum; j++) {
239 if(j!=i) {
240 runComputeNodeCmd("${name}", "sudo ip route add ${fabricIpPrefix}." + j.toString() + ".0/24 via ${fabricIpPrefix}." + i.toString() + ".254 || echo route already exists")
241 }
242 }
243 }
244 }
245 }
246 stage ("Generate and load network configuration") {
247 // Reconnect compute nodes to update the fabric IP in ONOS
248 connectFabricAndComputeToOnos()
249 // Generate network configuration
250 runHeadNodeCmd("""
251 cd /opt/cord_profile/
252 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
253 cord generate > fabric-network-cfg.json
254 """)
255 // Install httpie on the head-node
256 runHeadNodeCmd("sudo pip install httpie")
257 // Delete old ONOS netcfg
258 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
259 // Load new configuration
260 runHeadNodeCmd("""
261 cd /opt/cord_profile
262 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
263 """)
264 // Restart ONOS apps
265 runHeadNodeCmd("""
You Wang1abf2bf2017-12-12 15:21:07 -0800266 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
267 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
268 """)
Marc De Leenheer672afa82017-11-27 17:25:09 -0800269 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700270 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700271 }
Luca Pretefcbc54b2017-09-12 14:37:33 -0700272
You Wang1abf2bf2017-12-12 15:21:07 -0800273 if (deployment_config.make_release == true) {
Luca Pretefcbc54b2017-09-12 14:37:33 -0700274 stage ("Trigger Build") {
275 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
276 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
277 }
278 }
279
280 currentBuild.result = 'SUCCESS'
281 } catch (err) {
282 currentBuild.result = 'FAILURE'
283 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
284 } finally {
285 sh "make -C build clean-all || true"
286 sh "rm -rf *"
287 }
288 echo "RESULT: ${currentBuild.result}"
Luca Pretee2d51fd2017-08-31 16:19:21 -0700289 }
290}
291
292/**
293 * Returns a string used to bind IPs and MAC addresses, substituting the values
294 * given.
295 *
You Wang1abf2bf2017-12-12 15:21:07 -0800296 * @param word the word used to generate the host name
Luca Pretee2d51fd2017-08-31 16:19:21 -0700297 * @param counter the counter used to generate the host name
298 * @param mac the MAC address to substitute
299 * @param ip the IP address to substitute
300 */
You Wang1abf2bf2017-12-12 15:21:07 -0800301def createMACIPbindingStr(word, counter, mac, ip) {
302 return """host ${word}-${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
Luca Pretee2d51fd2017-08-31 16:19:21 -0700303}
304
305/**
306 * Runs a command on a remote host using sshpass.
307 *
308 * @param ip the node IP address
309 * @param user the node user name
310 * @param pass the node password
311 * @param command the command to run
You Wang1abf2bf2017-12-12 15:21:07 -0800312 * @param sshArgs arguments for the ssh command
Luca Pretee2d51fd2017-08-31 16:19:21 -0700313 * @return the output of the command
314 */
You Wang1abf2bf2017-12-12 15:21:07 -0800315def runCmd(ip, user, pass, command, sshArgs="") {
316 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh ${sshArgs} -oStrictHostKeyChecking=no -l ${user} ${ip} \"${command}\"")
317}
318
319/**
320 * Runs a command on the head node.
321 *
322 * @param command the command to run
323 * @param sshArgs arguments for the ssh command
324 * @return the output of the command
325 */
326def runHeadNodeCmd(command, sshArgs="") {
327 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}\"")
Luca Pretee2d51fd2017-08-31 16:19:21 -0700328}
329
330/**
331 * Runs a command on a fabric switch.
332 *
You Wang1abf2bf2017-12-12 15:21:07 -0800333 * @param ip the mgmt IP of the fabric switch, reachable from the head node
334 * @param user the mgmt user name of the fabric switch
335 * @param pass the mgmt password of the fabric switch
336 * @param command the command to run on the fabric switch
337 * @param ssgArgs arguments for the ssh command
Luca Pretee2d51fd2017-08-31 16:19:21 -0700338 * @return the output of the command
339 */
You Wang1abf2bf2017-12-12 15:21:07 -0800340def runFabricSwitchCmd(ip, user, pass, command, sshArgs="") {
341 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}\"")
342}
343
344/**
345 * Runs a command on all fabric switches
346 *
347 * @param command the command to run on the fabric switches
348 * @param ssgArgs arguments for the ssh command
349 */
350def runFabricSwitchCmdAll(command, sshArgs="") {
351 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
352 runFabricSwitchCmd("${deployment_config.fabric_switches[i].ip}",
353 "${deployment_config.fabric_switches[i].user}",
354 "${deployment_config.fabric_switches[i].pass}",
355 "${command}",
356 "${sshArgs}")
357 }
358}
359
360/**
361 * Runs a command on a compute node.
362 *
363 * @param name the name of the compute node
364 * @param command the command to run on the compute node
365 * @param ssgArgs arguments for the ssh command
366 * @return the output of the command
367 */
368def runComputeNodeCmd(name, command, sshArgs="") {
369 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}\"")
370}
371
372/**
373 * Runs a command on all compute nodes
374 *
375 * @param command the command to run on the compute nodes
376 * @param ssgArgs arguments for the ssh command
377 */
378def runComputeNodeCmdAll(command, sshArgs="") {
379 computeNamesAll = getComputeNames()
380 for (name in computeNamesAll) {
381 runComputeNodeCmd("${name}", "${command}", "${sshArgs}")
382 }
383}
384
385/**
386 * Runs an ONOS CLI command
387 *
388 * @param name the onos node name, reachable from the head node
389 * @param port the port used to login to ONOS CLI
390 * @param user the user name to login to ONOS CLI
391 * @param pass the password to login to ONOS CLI
392 * @param command the command to run in ONOS CLI
393 * @return the output of the command
394 */
395def runOnosCliCmd(name, port, user, pass, command) {
396 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}\"")
397}
398
399/**
400 * Returns a list of compute node names. When "role" is specified, returns only
401 * names of compute nodes connected to the switch
402 *
403 * @param role the switch role, i.e. "leaf-1"
404 */
405def getComputeNames(role="") {
406 computeNamesAll = runHeadNodeCmd("cord prov list | grep node | awk '{print \\\$2}' | sed -e \\\"s/.*/'&'/\\\"").trim()
407 computeNamesAll = "${computeNamesAll}".split()
408 computeNamesAll = "${computeNamesAll}".replaceAll("'", "\"")
409 computeNamesAll = new JsonSlurperClassic().parseText("${computeNamesAll}")
410 if ("${role}" == "") return computeNamesAll
411 computeNames = []
412 switchMac = ""
413 for(int i=0; i < deployment_config.fabric_switches.size(); i++) {
You Wangd37a1732017-12-14 15:29:11 -0800414 if(deployment_config.fabric_switches[i].containsKey("role")) {
415 if ("${deployment_config.fabric_switches[i].role}" == "${role}")
416 switchMac = "${deployment_config.fabric_switches[i].mac}"
417 }
You Wang1abf2bf2017-12-12 15:21:07 -0800418 }
419 if ("${switchMac}" != "") {
420 switchMac = switchMac.toLowerCase().replaceAll(':','')
421 // Get fabric IPs of compute nodes connected to the switch
422 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]*\\\"'",
423 "-q").trim()
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
You Wang1abf2bf2017-12-12 15:21:07 -0800465 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()
You Wangd37a1732017-12-14 15:29:11 -0800471 return num.toInteger() == deployment_config.compute_nodes.size()
You Wang1abf2bf2017-12-12 15:21:07 -0800472 } catch (exception) {
473 return false
474 }
475 }
476 }
Luca Pretee2d51fd2017-08-31 16:19:21 -0700477}