blob: dce59486391a122f7d15d4f370686c03c4239b11 [file] [log] [blame]
You Wang4eefdc82017-11-17 13:58:55 -08001// 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
15pod_config = null
16deployment_config = null
17
18node ('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
27node ("${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 }
You Wang9d616dd2018-01-22 14:10:28 -080034 stage('Configure Fabric for E2E testing') {
35 //FIXME: this only works for PODs with 2 leaf switches
36 fabricIpPrefix = pod_config.fabric_ip.split(/\.\d+\.\d+\/24/)[0]
37 runHeadNodeCmd("sudo ip route add ${fabricIpPrefix}.2.0/24 via ${fabricIpPrefix}.1.254 || echo route already exists")
38 runHeadNodeCmd("sudo route add -net 10.7.1.0/24 gw 10.6.1.254 || echo route already exists")
39 runHeadNodeCmd("sudo route add -net 10.8.1.0/24 gw 10.6.1.254 || echo route already exists")
40 runHeadNodeCmd("ping -c 1 ${fabricIpPrefix}.1.254", "-qftn")
41 runOnosCliCmd("onos-fabric", "8101", "onos", "rocks", "route-add 0.0.0.0/0 ${fabricIpPrefix}.1.1")
42 // Verify ONOS has recognized the hosts
43 timeout(time: 5) {
44 waitUntil {
45 try {
46 num = runHeadNodeCmd("\"sshpass -p rocks ssh -q -oStrictHostKeyChecking=no -l onos -p 8101 onos-fabric hosts | grep id= | wc -l\"").trim()
47 return num.toInteger() == deployment_config.compute_nodes.size() + 1
48 } catch (exception) {
49 return false
50 }
51 }
52 }
53 // Generate network configuration
54 runHeadNodeCmd("""
55 cd /opt/cord_profile/
56 cp fabric-network-cfg.json fabric-network-cfg.json.\$(date +%Y%m%d-%H%M%S)
57 cord generate > fabric-network-cfg.json
58 """)
59 // Delete old ONOS netcfg
60 runHeadNodeCmd("http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/network/configuration/")
61 // Load new configuration
62 runHeadNodeCmd("http -a onos:rocks POST http://onos-fabric:8181/onos/v1/network/configuration/ < /opt/cord_profile/fabric-network-cfg.json")
63 // Restart ONOS apps
64 runHeadNodeCmd("""
65 http -a onos:rocks DELETE http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
66 http -a onos:rocks POST http://onos-fabric:8181/onos/v1/applications/org.onosproject.segmentrouting/active; sleep 5
67 """)
68 }
You Wang4eefdc82017-11-17 13:58:55 -080069 stage('Verify Collect Diag') {
70 timeout(10) {
71 try {
72 runHeadNodeCmd("""
73 rm -rf ~/diag-*
74 cd /opt/cord/build; make collect-diag
75 cd /opt/cord/test/cord-tester/src/test/diag/
76 rm -r Log/ || true
77 pybot -v CORD_PROFILE:${pod_config.cord_profile} -d Log -T verifyCollectDiag.robot
78 """)
79 } catch(error) { currentBuild.result = 'FAILURE' }
80 }
81 }
82 stage('Sanity Test') {
83 timeout(10) {
84 try {
85 runHeadNodeCmd("""
86 cd /opt/cord/test/cord-tester/src/test/robot/
87 rm -r Log/ || true
88 """)
89 if (deployment_config.fabric_switches != null) {
90 runHeadNodeCmd("""
91 cd /opt/cord/test/cord-tester/src/test/robot/
92 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
93 """)
94 }
95 else {
96 // Exclude fabric related tests
97 runHeadNodeCmd("""
98 cd /opt/cord/test/cord-tester/src/test/robot/
99 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
100 """)
101 }
102 } catch(error) { currentBuild.result = 'FAILURE' }
103 }
104 }
105 stage('XOS API Tests') {
106 timeout(10) {
107 try {
108 runHeadNodeCmd("""
109 cd /opt/cord/test/cord-tester/src/test/cord-api/Properties/
110 sed -i s/^SERVER_IP\\ =\\ .*/SERVER_IP\\ =\\ \\'localhost\\'/ RestApiProperties.py
111 sed -i s/^SERVER_PORT\\ =\\ .*/SERVER_PORT\\ =\\ \\'9101\\'/ RestApiProperties.py
112 sed -i s/^PASSWD\\ =\\ .*/PASSWD\\ =\\ \\'\\\$(cat /opt/credentials/xosadmin@opencord.org)\\'/ RestApiProperties.py
113 all_passed=true
114 cd /opt/cord/test/cord-tester/src/test/cord-api/
115 rm -r Log/ || true
116 pybot -d Log -T Tests/Ch_defaultImagesCheck.txt || all_passed=false
117 pybot -d Log -T -v PROFILE:${pod_config.cord_profile} Tests/Ch_DefaultServiceCheck.txt || all_passed=false
118 pybot -d Log -T Tests/Ch_SubscriberTest.txt || all_passed=false
119 pybot -d Log -T Tests/Ch_VoltTenant.txt || all_passed=false
120 pybot -d Log -T Tests/Ch_ServiceTest.txt || all_passed=false
121 pybot -d Log -T Tests/Ch_UsersTest.txt || all_passed=false
122 pybot -d Log -T Tests/Ch_DeploymentTest.txt || all_passed=false
123 pybot -d Log -T Tests/Ch_NodeTest.txt || all_passed=false
124 pybot -d Log -T Tests/Ch_SliceTest.txt || all_passed=false
125 pybot -d Log -T Tests/Ch_SanityInstance.txt || all_passed=false
126 pybot -d Log -T Tests/Ch_SanityFlavors.txt || all_passed=false
127 pybot -d Log -T Tests/Ch_SiteTest.txt || all_passed=false
128 if [ "\\\$all_passed" = true ]; then exit 0; else exit 1; fi
129 """)
130 } catch(error) { currentBuild.result = 'FAILURE' }
131 }
132 }
133 stage('Publish') {
134 try {
135 sh """
136 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
137 scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/cord-api/Log/* ./RobotLogs || true
138 scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/robot/Log/* ./RobotLogs || true
139 scp -r ${deployment_config.head.user}@${deployment_config.head.ip}:/opt/cord/test/cord-tester/src/test/diag/Log/* ./RobotLogs || true
140 """
141 step([$class: 'RobotPublisher',
142 disableArchiveOutput: false,
143 logFileName: 'RobotLogs/log*.html',
144 otherFiles: '',
145 outputFileName: 'RobotLogs/output*.xml',
146 outputPath: '.',
147 passThreshold: 100,
148 reportFileName: 'RobotLogs/report*.html',
149 unstableThreshold: 0])
150 } catch(error) {}
151 }
152 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
153}
154
155/**
156 * Runs a command on the head node.
157 *
158 * @param command the command to run
159 * @param sshArgs arguments for the ssh command
160 * @return the output of the command
161 */
162def runHeadNodeCmd(command, sshArgs="") {
163 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}\"")
164}
You Wang9d616dd2018-01-22 14:10:28 -0800165
166/**
167 * Runs an ONOS CLI command
168 *
169 * @param name the onos node name, reachable from the head node
170 * @param port the port used to login to ONOS CLI
171 * @param user the user name to login to ONOS CLI
172 * @param pass the password to login to ONOS CLI
173 * @param command the command to run in ONOS CLI
174 * @return the output of the command
175 */
176def runOnosCliCmd(name, port, user, pass, command) {
177 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}\"")
178}