blob: aca370c194605697d63c4852127a09342e99a295 [file] [log] [blame]
alshabib08d0a1f2017-01-05 15:04:28 -08001def filename = 'manifest-${branch}.xml'
Luca Prete283f80a2017-05-18 15:21:24 -07002def manifestUrl = 'https://gerrit.opencord.org/manifest'
Luca Prete782d9412017-06-29 10:21:43 +02003def config = null;
alshabib4e1c96e2016-09-28 16:26:24 -07004
alshabib41f74fd2017-01-07 09:48:00 -08005node ('master') {
Luca Prete283f80a2017-05-18 15:21:24 -07006 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
alshabib41f74fd2017-01-07 09:48:00 -08007
Luca Prete283f80a2017-05-18 15:21:24 -07008 stage ("Generate and Copy Manifest file") {
9 sh returnStdout: true, script: 'repo manifest -r -o ' + filename
10 sh returnStdout: true, script: 'cp ' + filename + ' ' + env.JENKINS_HOME + '/tmp'
11 }
Luca Prete782d9412017-06-29 10:21:43 +020012
Jonathan Hart9bd4a822017-08-10 09:08:12 -070013 stage ("Parse deployment configuration file") {
Luca Prete782d9412017-06-29 10:21:43 +020014 sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
Luca Prete1125f602017-06-30 14:39:53 +020015 sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
Luca Prete782d9412017-06-29 10:21:43 +020016 config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
17 }
alshabib41f74fd2017-01-07 09:48:00 -080018}
19
Luca Prete782d9412017-06-29 10:21:43 +020020node ("${config.dev_node.name}") {
Luca Prete283f80a2017-05-18 15:21:24 -070021 timeout (time: 240) {
Luca Prete782d9412017-06-29 10:21:43 +020022 stage ('Checkout cord repo') {
23 checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true, manifestBranch: params.branch, manifestRepositoryUrl: "${manifestUrl}", quiet: true]
24 }
alshabib19302662017-01-05 14:27:41 -080025
Luca Prete00165d92017-10-05 14:36:58 -070026 try {
27 dir('build') {
Luca Prete283f80a2017-05-18 15:21:24 -070028 stage ("Re-deploy head node and Build Vagrant box") {
29 parallel(
30 maasOps: {
Luca Prete782d9412017-06-29 10:21:43 +020031 sh "maas login maas http://${config.maas.ip}/MAAS/api/2.0 ${config.maas.api_key}"
32 sh "maas maas machine release ${config.maas.head_system_id}"
alshabib19302662017-01-05 14:27:41 -080033
Luca Prete283f80a2017-05-18 15:21:24 -070034 timeout(time: 15) {
35 waitUntil {
36 try {
Luca Prete782d9412017-06-29 10:21:43 +020037 sh "maas maas machine read ${config.maas.head_system_id} | grep Ready"
Luca Prete283f80a2017-05-18 15:21:24 -070038 return true
39 } catch (exception) {
40 return false
41 }
alshabib19302662017-01-05 14:27:41 -080042 }
alshabibef069942016-09-09 17:08:36 -070043 }
alshabib4e1c96e2016-09-28 16:26:24 -070044
Luca Prete283f80a2017-05-18 15:21:24 -070045 sh 'maas maas machines allocate'
Luca Prete782d9412017-06-29 10:21:43 +020046 sh "maas maas machine deploy ${config.maas.head_system_id}"
alshabib4e1c96e2016-09-28 16:26:24 -070047
Luca Prete283f80a2017-05-18 15:21:24 -070048 timeout(time: 30) {
49 waitUntil {
50 try {
Luca Prete782d9412017-06-29 10:21:43 +020051 sh "maas maas machine read ${config.maas.head_system_id} | grep Deployed"
Luca Prete283f80a2017-05-18 15:21:24 -070052 return true
53 } catch (exception) {
54 return false
55 }
alshabib19302662017-01-05 14:27:41 -080056 }
alshabibef069942016-09-09 17:08:36 -070057 }
alshabib4e1c96e2016-09-28 16:26:24 -070058
Luca Prete283f80a2017-05-18 15:21:24 -070059 }, vagrantOps: {
60 sh 'vagrant up corddev'
61 }, failFast : true
62 )
63 }
alshabib4e1c96e2016-09-28 16:26:24 -070064
Andy Bavier0d6cd9e2017-09-25 13:47:10 -070065 if (config.fabric_switches != null) {
66 stage("Reserve IPs for fabric switches") {
67 for(int i=0; i < config.fabric_switches.size(); i++) {
68 def str = createMACIPbindingStr(i+1,
69 "${config.fabric_switches[i].mac}",
70 "${config.fabric_switches[i].ip}")
71 sh "echo $str >> maas/roles/maas/files/dhcpd.reservations"
72 }
73 }
74 }
75
Luca Prete283f80a2017-05-18 15:21:24 -070076 stage ("Fetch CORD packages") {
Luca Prete782d9412017-06-29 10:21:43 +020077 sh "vagrant ssh -c \"cd /opt/cord/build; ./gradlew fetch\" corddev"
Luca Prete283f80a2017-05-18 15:21:24 -070078 }
alshabib4e1c96e2016-09-28 16:26:24 -070079
Luca Prete283f80a2017-05-18 15:21:24 -070080 stage ("Build CORD Images") {
Luca Prete782d9412017-06-29 10:21:43 +020081 sh "vagrant ssh -c \"cd /opt/cord/build; ./gradlew buildImages\" corddev"
Luca Prete283f80a2017-05-18 15:21:24 -070082 }
alshabib61509fb2016-09-09 02:43:20 -070083
Luca Prete283f80a2017-05-18 15:21:24 -070084 stage ("Downloading CORD POD configuration") {
Luca Prete1125f602017-06-30 14:39:53 +020085 sh "vagrant ssh -c \"cd /opt/cord/build/config; git clone -b ${branch} ${config.pod_config.repo_url}\" corddev"
Luca Prete283f80a2017-05-18 15:21:24 -070086 }
Jonathan Hart1719e9a2017-03-13 21:53:47 -070087
Luca Prete283f80a2017-05-18 15:21:24 -070088 stage ("Publish to headnode") {
Luca Prete782d9412017-06-29 10:21:43 +020089 sh "vagrant ssh -c \"cd /opt/cord/build; ./gradlew -PtargetReg=${config.head.ip}:5000 -PdeployConfig=config/pod-configs/${config.pod_config.file_name} publish\" corddev"
Luca Prete283f80a2017-05-18 15:21:24 -070090 }
alshabib61509fb2016-09-09 02:43:20 -070091
Luca Prete283f80a2017-05-18 15:21:24 -070092 stage ("Deploy") {
Luca Prete782d9412017-06-29 10:21:43 +020093 sh "vagrant ssh -c \"cd /opt/cord/build; ./gradlew -PtargetReg=${config.head.ip}:5000 -PdeployConfig=config/pod-configs/${config.pod_config.file_name} deploy\" corddev"
Luca Prete283f80a2017-05-18 15:21:24 -070094 }
alshabib4e1c96e2016-09-28 16:26:24 -070095
Luca Preted4cc2d72017-10-17 11:52:18 -070096 if (config.compute_nodes != null) {
alshabib7f3be8d2016-09-27 18:04:56 -070097
Luca Preted4cc2d72017-10-17 11:52:18 -070098 stage ("Power cycle compute nodes") {
99 for(int i=0; i < config.compute_nodes.size(); i++) {
100 sh "ipmitool -U ${config.compute_nodes[i].ipmi.user} -P ${config.compute_nodes[i].ipmi.pass} -H ${config.compute_nodes[i].ipmi.ip} power cycle"
101 }
102 }
103
104 stage ("Wait for compute nodes to get deployed") {
105 sh "ssh-keygen -f /home/${config.dev_node.user}/.ssh/known_hosts -R ${config.head.ip}"
106 def cordApiKey = runCmd("${config.head.ip}",
107 "${config.head.user}",
108 "${config.head.pass}",
109 "sudo maas-region-admin apikey --username ${config.head.user}")
110 runCmd("${config.head.ip}",
111 "${config.head.user}",
112 "${config.head.pass}",
113 "maas login pod-maas http://${config.head.ip}/MAAS/api/1.0 ${cordApiKey}")
114 timeout(time: 45) {
115 waitUntil {
116 try {
117 num = runCmd("${config.head.ip}",
118 "${config.head.user}",
119 "${config.head.pass}",
120 "maas pod-maas nodes list | grep -i deployed | wc -l").trim()
121 return num.toInteger() == config.compute_nodes.size()
122 } catch (exception) {
123 return false
124 }
Luca Prete283f80a2017-05-18 15:21:24 -0700125 }
alshabib19302662017-01-05 14:27:41 -0800126 }
alshabib4e1c96e2016-09-28 16:26:24 -0700127 }
alshabib4e1c96e2016-09-28 16:26:24 -0700128
Luca Preted4cc2d72017-10-17 11:52:18 -0700129 stage ("Wait for compute nodes to be provisioned") {
130 timeout(time:45) {
131 waitUntil {
132 try {
133 num = runCmd("${config.head.ip}",
134 "${config.head.user}",
135 "${config.head.pass}",
136 "cord prov list '|' grep -i node '|' grep -i complete '|' wc -l").trim()
137 return num.toInteger() == config.compute_nodes.size()
138 } catch (exception) {
139 return false
140 }
Luca Prete283f80a2017-05-18 15:21:24 -0700141 }
alshabib19302662017-01-05 14:27:41 -0800142 }
alshabib7f3be8d2016-09-27 18:04:56 -0700143 }
Luca Preted4cc2d72017-10-17 11:52:18 -0700144
alshabib7f3be8d2016-09-27 18:04:56 -0700145 }
alshabib19302662017-01-05 14:27:41 -0800146
Luca Prete782d9412017-06-29 10:21:43 +0200147 if (config.fabric_switches != null) {
Luca Prete607c2d52017-05-24 09:56:06 -0700148 stage ("Wait for fabric switches to get deployed") {
Luca Prete782d9412017-06-29 10:21:43 +0200149 for(int i=0; i < config.fabric_switches.size(); i++) {
150 runFabricCmd("${config.head.ip}",
151 "${config.head.user}",
152 "${config.head.pass}",
153 "${config.fabric_switches[i].ip}",
154 "${config.fabric_switches[i].user}",
155 "${config.fabric_switches[i].pass}",
156 "sudo onl-onie-boot-mode install")
157
158 runFabricCmd("${config.head.ip}",
159 "${config.head.user}",
160 "${config.head.pass}",
161 "${config.fabric_switches[i].ip}",
162 "${config.fabric_switches[i].user}",
163 "${config.fabric_switches[i].pass}",
164 "sudo reboot")
Luca Prete607c2d52017-05-24 09:56:06 -0700165 }
166 timeout(time: 45) {
167 waitUntil {
168 try {
Luca Prete782d9412017-06-29 10:21:43 +0200169 def harvestCompleted = runCmd("${config.head.ip}",
170 "${config.head.user}",
171 "${config.head.pass}",
172 "cord harvest list '|' grep -i fabric '|' wc -l").trim()
Luca Prete512389a2017-07-07 12:33:29 +0200173 return harvestCompleted.toInteger() == config.fabric_switches.size()
Luca Prete607c2d52017-05-24 09:56:06 -0700174 } catch (exception) {
175 return false
176 }
177 }
178 }
179 }
180
181 stage ("Wait for fabric switches to be provisioned") {
182 timeout(time:45) {
183 waitUntil {
184 try {
185 def provCompleted = 0
Luca Prete782d9412017-06-29 10:21:43 +0200186 for(int i=0; i < config.fabric_switches.size(); i++) {
187 def count = runCmd("${config.head.ip}",
188 "${config.head.user}",
189 "${config.head.pass}",
190 "cord prov list '|' grep -i ${config.fabric_switches[i].ip} '|' grep -i complete '|' wc -l").trim()
Luca Prete607c2d52017-05-24 09:56:06 -0700191 provCompleted = provCompleted + count.toInteger()
Luca Prete607c2d52017-05-24 09:56:06 -0700192 }
Luca Prete782d9412017-06-29 10:21:43 +0200193 return provCompleted == config.fabric_switches.size()
Luca Prete607c2d52017-05-24 09:56:06 -0700194 } catch (exception) {
195 return false
196 }
197 }
198 }
199 }
200 }
alshabib7f3be8d2016-09-27 18:04:56 -0700201 }
Luca Prete00165d92017-10-05 14:36:58 -0700202 if (config.make_release == true) {
203 stage ("Trigger Build") {
204 url = 'https://jenkins.opencord.org/job/release-build/job/' + params.branch + '/build'
205 httpRequest authentication: 'auto-release', httpMode: 'POST', url: url, validResponseCodes: '201'
206 }
207 }
208
209 currentBuild.result = 'SUCCESS'
210 } catch (err) {
211 currentBuild.result = 'FAILURE'
212 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
213 } finally {
214 sh 'cd build && vagrant destroy -f corddev'
215 sh 'rm -rf *'
216 }
217
218 echo "RESULT: ${currentBuild.result}"
alshabib19302662017-01-05 14:27:41 -0800219 }
alshabib152823c2016-09-07 23:49:12 -0700220}
Luca Prete283f80a2017-05-18 15:21:24 -0700221
222/**
Luca Prete283f80a2017-05-18 15:21:24 -0700223 * Returns a string used to bind IPs and MAC addresses, substituting the values
224 * given.
225 *
Luca Prete607c2d52017-05-24 09:56:06 -0700226 * @param counter the counter used to generate the host name
227 * @param mac the MAC address to substitute
228 * @param ip the IP address to substitute
Luca Prete283f80a2017-05-18 15:21:24 -0700229 */
Luca Prete607c2d52017-05-24 09:56:06 -0700230def createMACIPbindingStr(counter, mac, ip) {
Luca Prete6e7f5ab2017-10-03 14:42:31 -0700231 return """host fabric${counter} {'\n'hardware ethernet ${mac}';''\n'fixed-address ${ip}';''\n'}"""
Luca Prete283f80a2017-05-18 15:21:24 -0700232}
233
234/**
Luca Prete782d9412017-06-29 10:21:43 +0200235 * Runs a command on a remote host using sshpass.
Luca Prete283f80a2017-05-18 15:21:24 -0700236 *
Luca Prete782d9412017-06-29 10:21:43 +0200237 * @param ip the node IP address
238 * @param user the node user name
239 * @param pass the node password
240 * @param command the command to run
Luca Prete607c2d52017-05-24 09:56:06 -0700241 * @return the output of the command
Luca Prete283f80a2017-05-18 15:21:24 -0700242 */
Luca Prete782d9412017-06-29 10:21:43 +0200243def runCmd(ip, user, pass, command) {
Luca Prete512389a2017-07-07 12:33:29 +0200244 return sh(returnStdout: true, script: "sshpass -p ${pass} ssh -oStrictHostKeyChecking=no -l ${user} ${ip} ${command}")
Luca Prete283f80a2017-05-18 15:21:24 -0700245}
Luca Prete607c2d52017-05-24 09:56:06 -0700246
247/**
248 * Runs a command on a fabric switch.
249 *
Luca Prete782d9412017-06-29 10:21:43 +0200250 * @param headIp the head node IP address
251 * @param headUser the head node user name
252 * @param headPass the head node password
Luca Prete607c2d52017-05-24 09:56:06 -0700253 * @param ip the mgmt IP of the fabric switch, reachable from the head node
Luca Prete782d9412017-06-29 10:21:43 +0200254 * @param user the mgmt user name of the fabric switch
255 * @param pass the mgmt password of the fabric switch
256 * @param command the command to run on the fabric switch
Luca Prete607c2d52017-05-24 09:56:06 -0700257 * @return the output of the command
258 */
Luca Preted642a592017-06-30 11:11:35 +0200259def runFabricCmd(headIp, headUser, headPass, ip, user, pass, command) {
Luca Prete512389a2017-07-07 12:33:29 +0200260 return sh(returnStdout: true, script: "sshpass -p ${headPass} ssh -oStrictHostKeyChecking=no -l ${headUser} ${headIp} \"sshpass -p ${pass} ssh -oStrictHostKeyChecking=no -l ${user} ${ip} ${command}\"")
Jonathan Hart9bd4a822017-08-10 09:08:12 -0700261}