You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | pod_config = null |
| 16 | deployment_config = null |
| 17 | |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 18 | node ("${devNodeName}") { |
| 19 | |
| 20 | stage ("Parse deployment configuration file") { |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 21 | sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}' |
| 22 | sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}' |
| 23 | deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}" |
| 24 | pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}" |
| 25 | } |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 26 | stage('Prerequisites') { |
| 27 | runHeadNodeCmd(""" |
| 28 | cd /opt/cord/test/cord-tester/src/test/setup |
| 29 | sudo ./prerequisites.sh --cord |
| 30 | """) |
| 31 | } |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 32 | stage('Bring up Cord-Test Container') { |
| 33 | runHeadNodeCmd(""" |
| 34 | cd /opt/cord/test/cord-tester/src/test/setup |
| 35 | sudo ./cord-test.py setup -m manifest-onf-cord.json |
| 36 | """) |
| 37 | } |
You Wang | 9d616dd | 2018-01-22 14:10:28 -0800 | [diff] [blame] | 38 | stage('Configure Fabric for E2E testing') { |
| 39 | //FIXME: this only works for PODs with 2 leaf switches |
| 40 | fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0] |
| 41 | runHeadNodeCmd("sudo ip route add ${fabricIpPrefix}.2.0/24 via ${fabricIpPrefix}.1.254 || echo route already exists") |
| 42 | runHeadNodeCmd("sudo route add -net 10.7.1.0/24 gw 10.6.1.254 || echo route already exists") |
| 43 | runHeadNodeCmd("sudo route add -net 10.8.1.0/24 gw 10.6.1.254 || echo route already exists") |
| 44 | runHeadNodeCmd("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn") |
| 45 | runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "route-add 0.0.0.0/0 ${fabricIpPrefix}.1.1") |
| 46 | // Verify ONOS has recognized the hosts |
| 47 | timeout(time: 5) { |
| 48 | waitUntil { |
| 49 | try { |
| 50 | num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim() |
| 51 | return num.toInteger() == deployment_config.compute_nodes.size() + 1 |
| 52 | } catch (exception) { |
| 53 | return false |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | // Generate network configuration |
| 58 | runHeadNodeCmd(""" |
| 59 | cd /opt/cord_profile/ |
| 60 | cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S) |
| 61 | cord generate > fabric-network-cfg.json |
| 62 | """) |
You Wang | c18aa9f | 2018-02-06 15:58:04 -0800 | [diff] [blame] | 63 | // Install httpie on the head-node |
| 64 | runHeadNodeCmd("sudo pip install httpie") |
You Wang | 9d616dd | 2018-01-22 14:10:28 -0800 | [diff] [blame] | 65 | // Delete old ONOS netcfg |
| 66 | runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/") |
| 67 | // Load new configuration |
| 68 | runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json") |
| 69 | // Restart ONOS apps |
| 70 | runHeadNodeCmd(""" |
| 71 | http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5 |
| 72 | http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5 |
| 73 | """) |
| 74 | } |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 75 | stage('Verify Collect Diag') { |
| 76 | timeout(10) { |
| 77 | try { |
| 78 | runHeadNodeCmd(""" |
| 79 | rm -rf ~/diag-* |
| 80 | cd /opt/cord/build; make collect-diag |
| 81 | cd /opt/cord/test/cord-tester/src/test/diag/ |
| 82 | rm -r Log/ || true |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 83 | rm -r TestDoc/ || true |
| 84 | mkdir TestDoc || true |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 85 | export SERVER_IP=localhost |
| 86 | export SERVER_PORT=9101 |
| 87 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 88 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 89 | pybot -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T verifyCollectDiag.robot |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 90 | python -m robot.testdoc verifyCollectDiag.robot TestDoc/verifyCollectDiag.html |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 91 | """) |
| 92 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 93 | } |
| 94 | } |
| 95 | stage('Sanity Test') { |
| 96 | timeout(10) { |
| 97 | try { |
| 98 | runHeadNodeCmd(""" |
| 99 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 100 | rm -r Log/ || true |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 101 | rm -r TestDoc/ || true |
| 102 | mkdir TestDoc |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 103 | """) |
| 104 | if (deployment_config.fabric_switches != null) { |
| 105 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 106 | export SERVER_IP=localhost |
| 107 | export SERVER_PORT=9101 |
| 108 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 109 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 110 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 111 | pybot --exclude notready -v FABRIC:on -v PUBLIC_IFACE:${pod_config.external_iface} -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T SanityPhyPOD.robot |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 112 | python -m robot.testdoc SanityPhyPOD.robot TestDoc/SanityPhyPOD.html |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 113 | """) |
| 114 | } |
| 115 | else { |
| 116 | // Exclude fabric related tests |
| 117 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 118 | export SERVER_IP=localhost |
| 119 | export SERVER_PORT=9101 |
| 120 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 121 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 122 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 123 | pybot --exclude notready --exclude fabric -v FABRIC:off -v PUBLIC_IFACE:${pod_config.external_iface} -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T SanityPhyPOD.robot |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 124 | python -m robot.testdoc SanityPhyPOD.robot TestDoc/SanityPhyPOD.html |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 125 | """) |
| 126 | } |
| 127 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 128 | } |
| 129 | } |
| 130 | stage('XOS API Tests') { |
| 131 | timeout(10) { |
| 132 | try { |
| 133 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 134 | export SERVER_IP=localhost |
| 135 | export SERVER_PORT=9101 |
| 136 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 137 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 138 | all_passed=true |
| 139 | cd /opt/cord/test/cord-tester/src/test/cord-api/ |
| 140 | rm -r Log/ || true |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 141 | rm -r TestDoc/ || true |
| 142 | mkdir TestDoc || true |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 143 | pybot -d Log -T Tests/Ch_defaultImagesCheck.txt || all_passed=false |
| 144 | pybot -d Log -T -v PROFILE:${pod_config.cord_profile} Tests/Ch_DefaultServiceCheck.txt || all_passed=false |
| 145 | pybot -d Log -T Tests/Ch_SubscriberTest.txt || all_passed=false |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 146 | pybot -d Log -T Tests/Ch_ServiceTest.txt || all_passed=false |
| 147 | pybot -d Log -T Tests/Ch_UsersTest.txt || all_passed=false |
| 148 | pybot -d Log -T Tests/Ch_DeploymentTest.txt || all_passed=false |
| 149 | pybot -d Log -T Tests/Ch_NodeTest.txt || all_passed=false |
| 150 | pybot -d Log -T Tests/Ch_SliceTest.txt || all_passed=false |
| 151 | pybot -d Log -T Tests/Ch_SanityInstance.txt || all_passed=false |
| 152 | pybot -d Log -T Tests/Ch_SanityFlavors.txt || all_passed=false |
| 153 | pybot -d Log -T Tests/Ch_SiteTest.txt || all_passed=false |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 154 | python -m robot.testdoc Tests/Ch_*.txt TestDoc/XOSApiTests.html |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 155 | if [ "\\\$all_passed" = true ]; then exit 0; else exit 1; fi |
| 156 | """) |
| 157 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 158 | } |
| 159 | } |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 160 | stage('Dataplane Test') { |
Kailash Khalasi | e168882 | 2018-02-10 12:26:39 -0800 | [diff] [blame] | 161 | timeout(30) { |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 162 | try { |
| 163 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 164 | export SERVER_IP=localhost |
| 165 | export SERVER_PORT=9101 |
| 166 | export XOS_USER=xosadmin@opencord.org |
| 167 | export XOS_PASSWD=\$(cat /opt/credentials/xosadmin@opencord.org) |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 168 | cd /opt/cord/test/cord-tester/src/test/vsg/ |
| 169 | rm -r Log/ || true |
Kailash Khalasi | 3d1c4d7 | 2018-01-30 12:10:28 -0800 | [diff] [blame] | 170 | rm -r TestDoc/ || true |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 171 | mkdir TestDoc |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 172 | """) |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 173 | if (deployment_config.pod_config.file_name != 'calix-pod1.yml') { |
| 174 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 175 | export SERVER_IP=localhost |
| 176 | export SERVER_PORT=9101 |
| 177 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 178 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 179 | cd /opt/cord/test/cord-tester/src/test/vsg/ |
| 180 | pybot -L TRACE -v pod:${deployment_config.pod_config.file_name} -d Log -T vsg_dataplane_test.robot |
| 181 | python -m robot.testdoc vsg_dataplane_test.robot TestDoc/vsg_dataplane_test.html |
| 182 | """) |
| 183 | } |
| 184 | else { |
| 185 | runHeadNodeCmd(""" |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 186 | export SERVER_IP=localhost |
| 187 | export SERVER_PORT=9101 |
| 188 | export XOS_USER=xosadmin@opencord.org |
Kailash Khalasi | a0d4900 | 2018-04-18 15:00:47 -0700 | [diff] [blame] | 189 | export XOS_PASSWD=\\\$(cat /opt/credentials/xosadmin@opencord.org) |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 190 | cd /opt/cord/test/cord-tester/src/test/vsg/ |
| 191 | pybot -L TRACE -v pod:${deployment_config.pod_config.file_name} -e dataplane -d Log -T vsg_dataplane_test.robot |
| 192 | python -m robot.testdoc vsg_dataplane_test.robot TestDoc/vsg_dataplane_test.html |
| 193 | """) |
| 194 | } |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 195 | } catch(error) { currentBuild.result = 'FAILURE' } |
Kailash Khalasi | 29ffe5e | 2018-02-09 13:34:31 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 198 | stage('Publish') { |
| 199 | try { |
| 200 | sh """ |
Kailash Khalasi | 9b31109 | 2018-02-08 11:26:37 -0800 | [diff] [blame] | 201 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs; |
| 202 | mkdir RobotLogs/TestDoc || true |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 203 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/Log/* ./RobotLogs || true |
| 204 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/Log/* ./RobotLogs || true |
| 205 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/Log/* ./RobotLogs || true |
Kailash Khalasi | ecf3014 | 2018-01-24 15:16:45 -0800 | [diff] [blame] | 206 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/vsg/Log/* ./RobotLogs || true |
Kailash Khalasi | 9b31109 | 2018-02-08 11:26:37 -0800 | [diff] [blame] | 207 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/TestDoc/* ./RobotLogs/TestDoc || true |
| 208 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/TestDoc/* ./RobotLogs/TestDoc || true |
| 209 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/TestDoc/* ./RobotLogs/TestDoc || true |
| 210 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/vsg/TestDoc/* ./RobotLogs/TestDoc || true |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 211 | """ |
| 212 | step([$class: 'RobotPublisher', |
| 213 | disableArchiveOutput: false, |
| 214 | logFileName: 'RobotLogs/log*.html', |
Kailash Khalasi | 9b31109 | 2018-02-08 11:26:37 -0800 | [diff] [blame] | 215 | otherFiles: 'RobotLogs/TestDoc/*.html', |
You Wang | 4eefdc8 | 2017-11-17 13:58:55 -0800 | [diff] [blame] | 216 | outputFileName: 'RobotLogs/output*.xml', |
| 217 | outputPath: '.', |
| 218 | passThreshold: 100, |
| 219 | reportFileName: 'RobotLogs/report*.html', |
| 220 | unstableThreshold: 0]) |
| 221 | } catch(error) {} |
| 222 | } |
| 223 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false]) |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Runs a command on the head node. |
| 228 | * |
| 229 | * @param command the command to run |
| 230 | * @param sshArgs arguments for the ssh command |
| 231 | * @return the output of the command |
| 232 | */ |
| 233 | def runHeadNodeCmd(command, sshArgs="") { |
| 234 | 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}\"") |
| 235 | } |
You Wang | 9d616dd | 2018-01-22 14:10:28 -0800 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * Runs an ONOS CLI command |
| 239 | * |
| 240 | * @param name the onos node name, reachable from the head node |
| 241 | * @param port the port used to login to ONOS CLI |
| 242 | * @param user the user name to login to ONOS CLI |
| 243 | * @param pass the password to login to ONOS CLI |
| 244 | * @param command the command to run in ONOS CLI |
| 245 | * @return the output of the command |
| 246 | */ |
| 247 | def runOnosCliCmd(name, port, user, pass, command) { |
| 248 | 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}\"") |
| 249 | } |