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 | } |
| 34 | stage('Verify Collect Diag') { |
| 35 | timeout(10) { |
| 36 | try { |
| 37 | runHeadNodeCmd(""" |
| 38 | rm -rf ~/diag-* |
| 39 | cd /opt/cord/build; make collect-diag |
| 40 | cd /opt/cord/test/cord-tester/src/test/diag/ |
| 41 | rm -r Log/ || true |
| 42 | pybot -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T verifyCollectDiag.robot |
| 43 | """) |
| 44 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 45 | } |
| 46 | } |
| 47 | stage('Sanity Test') { |
| 48 | timeout(10) { |
| 49 | try { |
| 50 | runHeadNodeCmd(""" |
| 51 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 52 | rm -r Log/ || true |
| 53 | """) |
| 54 | if (deployment_config.fabric_switches != null) { |
| 55 | runHeadNodeCmd(""" |
| 56 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 57 | 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 |
| 58 | """) |
| 59 | } |
| 60 | else { |
| 61 | // Exclude fabric related tests |
| 62 | runHeadNodeCmd(""" |
| 63 | cd /opt/cord/test/cord-tester/src/test/robot/ |
| 64 | 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 |
| 65 | """) |
| 66 | } |
| 67 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 68 | } |
| 69 | } |
| 70 | stage('XOS API Tests') { |
| 71 | timeout(10) { |
| 72 | try { |
| 73 | runHeadNodeCmd(""" |
| 74 | cd /opt/cord/test/cord-tester/src/test/cord-api/Properties/ |
| 75 | sed -i s/^SERVER_IP\\ =\\ .*/SERVER_IP\\ =\\ \\'localhost\\'/ RestApiProperties.py |
| 76 | sed -i s/^SERVER_PORT\\ =\\ .*/SERVER_PORT\\ =\\ \\'9101\\'/ RestApiProperties.py |
| 77 | sed -i s/^PASSWD\\ =\\ .*/PASSWD\\ =\\ \\'\\\$(cat /opt/credentials/xosadmin@opencord.org)\\'/ RestApiProperties.py |
| 78 | """) |
| 79 | } catch(error) { currentBuild.result = 'FAILURE' } |
| 80 | } |
| 81 | } |
| 82 | stage('Publish') { |
| 83 | try { |
| 84 | sh """ |
| 85 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
| 86 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/Log/* ./RobotLogs || true |
| 87 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/Log/* ./RobotLogs || true |
| 88 | scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/Log/* ./RobotLogs || true |
| 89 | """ |
| 90 | step([$class: 'RobotPublisher', |
| 91 | disableArchiveOutput: false, |
| 92 | logFileName: 'RobotLogs/log*.html', |
| 93 | otherFiles: '', |
| 94 | outputFileName: 'RobotLogs/output*.xml', |
| 95 | outputPath: '.', |
| 96 | passThreshold: 100, |
| 97 | reportFileName: 'RobotLogs/report*.html', |
| 98 | unstableThreshold: 0]) |
| 99 | } catch(error) {} |
| 100 | } |
| 101 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false]) |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Runs a command on the head node. |
| 106 | * |
| 107 | * @param command the command to run |
| 108 | * @param sshArgs arguments for the ssh command |
| 109 | * @return the output of the command |
| 110 | */ |
| 111 | def runHeadNodeCmd(command, sshArgs="") { |
| 112 | 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}\"") |
| 113 | } |