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