| // Copyright 2017-present Open Networking Foundation |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| pod_config = null |
| deployment_config = null |
| |
| node ('master') { |
| stage ("Parse configuration file") { |
| sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}' |
| sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}' |
| deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}" |
| pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}" |
| } |
| } |
| |
| node ("${deployment_config.dev_node.name}") { |
| stage('Prerequisites') { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/setup |
| sudo ./prerequisites.sh --cord |
| """) |
| } |
| stage('Bring up Cord-Test Container') { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/setup |
| sudo ./cord-test.py setup -m manifest-onf-cord.json |
| """) |
| } |
| stage('Configure Fabric for E2E testing') { |
| //FIXME: this only works for PODs with 2 leaf switches |
| fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0] |
| runHeadNodeCmd("sudo ip route add ${fabricIpPrefix}.2.0/24 via ${fabricIpPrefix}.1.254 || echo route already exists") |
| runHeadNodeCmd("sudo route add -net 10.7.1.0/24 gw 10.6.1.254 || echo route already exists") |
| runHeadNodeCmd("sudo route add -net 10.8.1.0/24 gw 10.6.1.254 || echo route already exists") |
| runHeadNodeCmd("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn") |
| runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "route-add 0.0.0.0/0 ${fabricIpPrefix}.1.1") |
| // Verify ONOS has recognized the hosts |
| timeout(time: 5) { |
| waitUntil { |
| try { |
| num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim() |
| return num.toInteger() == deployment_config.compute_nodes.size() + 1 |
| } catch (exception) { |
| return false |
| } |
| } |
| } |
| // Generate network configuration |
| runHeadNodeCmd(""" |
| cd /opt/cord_profile/ |
| cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S) |
| cord generate > fabric-network-cfg.json |
| """) |
| // Install httpie on the head-node |
| runHeadNodeCmd("sudo pip install httpie") |
| // Delete old ONOS netcfg |
| runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/") |
| // Load new configuration |
| runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json") |
| // Restart ONOS apps |
| runHeadNodeCmd(""" |
| http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5 |
| http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5 |
| """) |
| } |
| stage('Verify Collect Diag') { |
| timeout(10) { |
| try { |
| runHeadNodeCmd(""" |
| rm -rf ~/diag-* |
| cd /opt/cord/build; make collect-diag |
| cd /opt/cord/test/cord-tester/src/test/diag/ |
| rm -r Log/ || true |
| rm -r TestDoc/ || true |
| mkdir TestDoc || true |
| pybot -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T verifyCollectDiag.robot |
| python -m robot.testdoc verifyCollectDiag.robot TestDoc/verifyCollectDiag.html |
| """) |
| } catch(error) { currentBuild.result = 'FAILURE' } |
| } |
| } |
| stage('Sanity Test') { |
| timeout(10) { |
| try { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/robot/ |
| rm -r Log/ || true |
| rm -r TestDoc/ || true |
| mkdir TestDoc |
| """) |
| if (deployment_config.fabric_switches != null) { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/robot/ |
| 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 |
| python -m robot.testdoc SanityPhyPOD.robot TestDoc/SanityPhyPOD.html |
| """) |
| } |
| else { |
| // Exclude fabric related tests |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/robot/ |
| 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 |
| python -m robot.testdoc SanityPhyPOD.robot TestDoc/SanityPhyPOD.html |
| """) |
| } |
| } catch(error) { currentBuild.result = 'FAILURE' } |
| } |
| } |
| stage('XOS API Tests') { |
| timeout(10) { |
| try { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/cord-api/Properties/ |
| sed -i s/^SERVER_IP\\ =\\ .*/SERVER_IP\\ =\\ \\'localhost\\'/ RestApiProperties.py |
| sed -i s/^SERVER_PORT\\ =\\ .*/SERVER_PORT\\ =\\ \\'9101\\'/ RestApiProperties.py |
| sed -i s/^PASSWD\\ =\\ .*/PASSWD\\ =\\ \\'\\\$(cat /opt/credentials/xosadmin@opencord.org)\\'/ RestApiProperties.py |
| all_passed=true |
| cd /opt/cord/test/cord-tester/src/test/cord-api/ |
| rm -r Log/ || true |
| rm -r TestDoc/ || true |
| mkdir TestDoc || true |
| pybot -d Log -T Tests/Ch_defaultImagesCheck.txt || all_passed=false |
| pybot -d Log -T -v PROFILE:${pod_config.cord_profile} Tests/Ch_DefaultServiceCheck.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_SubscriberTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_VoltTenant.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_ServiceTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_UsersTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_DeploymentTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_NodeTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_SliceTest.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_SanityInstance.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_SanityFlavors.txt || all_passed=false |
| pybot -d Log -T Tests/Ch_SiteTest.txt || all_passed=false |
| python -m robot.testdoc Tests/Ch_*.txt TestDoc/XOSApiTests.html |
| if [ "\\\$all_passed" = true ]; then exit 0; else exit 1; fi |
| """) |
| } catch(error) { currentBuild.result = 'FAILURE' } |
| } |
| } |
| /*stage('Dataplane Test') { |
| timeout(10) { |
| try { |
| runHeadNodeCmd(""" |
| cd /opt/cord/test/cord-tester/src/test/vsg/ |
| rm -r Log/ || true |
| rm -r TestDoc/ || true |
| mkdir TestDoc || true |
| ssh-agent bash |
| ssh-add |
| pybot -L TRACE -d Log -T vsg_dataplane_test.robot |
| python -m robot.testdoc vsg_dataplane_test.robot TestDoc/vsg_dataplane_test.html |
| """) |
| } catch(error) { currentBuild.result = 'FAILURE' } |
| } |
| }*/ |
| stage('Publish') { |
| try { |
| sh """ |
| if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/Log/* ./RobotLogs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/Log/* ./RobotLogs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/Log/* ./RobotLogs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/vsg/Log/* ./RobotLogs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/TestDoc/* ./RobotLogs/TestDocs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/TestDoc/* ./RobotLogs/TestDocs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/TestDoc/* ./RobotLogs/TestDocs || true |
| scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/vsg/TestDoc/* ./RobotLogs/TestDocs || true |
| """ |
| step([$class: 'RobotPublisher', |
| disableArchiveOutput: false, |
| logFileName: 'RobotLogs/log*.html', |
| otherFiles: 'RobotLogs/TestDocs/*.html', |
| outputFileName: 'RobotLogs/output*.xml', |
| outputPath: '.', |
| passThreshold: 100, |
| reportFileName: 'RobotLogs/report*.html', |
| unstableThreshold: 0]) |
| } catch(error) {} |
| } |
| step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false]) |
| } |
| |
| /** |
| * Runs a command on the head node. |
| * |
| * @param command the command to run |
| * @param sshArgs arguments for the ssh command |
| * @return the output of the command |
| */ |
| def runHeadNodeCmd(command, sshArgs="") { |
| 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}\"") |
| } |
| |
| /** |
| * Runs an ONOS CLI command |
| * |
| * @param name the onos node name, reachable from the head node |
| * @param port the port used to login to ONOS CLI |
| * @param user the user name to login to ONOS CLI |
| * @param pass the password to login to ONOS CLI |
| * @param command the command to run in ONOS CLI |
| * @return the output of the command |
| */ |
| def runOnosCliCmd(name, port, user, pass, command) { |
| 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}\"") |
| } |