blob: 1aa5a423efc0fcb89b01f8964e34042b9992821c [file] [log] [blame]
Kailash Khalasi54170812018-05-24 12:50:22 -07001// 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
15PROFILE="null"
16CORE_CONTAINER="null"
17
18pipeline {
19
20 /* no label, executor is determined by JJB */
21 agent {
22 label "${params.executorNode}"
23 }
24
25 stages {
26
27 stage('repo') {
28 steps {
29 checkout(changelog: false, \
30 poll: false,
31 scm: [$class: 'RepoScm', \
32 manifestRepositoryUrl: "${params.manifestUrl}", \
33 manifestBranch: "${params.manifestBranch}", \
34 currentBranch: true, \
35 destinationDir: 'cord', \
36 forceSync: true,
37 resetFirst: true, \
38 quiet: true, \
39 jobs: 4, \
40 showAllChanges: true] \
41 )
42 }
43 }
44
45 stage('patch') {
46 steps {
47 sh """
48 pushd cord
49 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
50 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
51 popd
52 """
53 }
54 }
55
56 stage('prep') {
57 parallel {
58
59 stage('images') {
60 steps {
61 sh '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -070062 pushd cord/automation-tools/developer
63 ./imagebuilder.py -f ../../helm-charts/examples/api-test-images.yaml
Kailash Khalasi54170812018-05-24 12:50:22 -070064 popd
65 '''
66 }
67 }
68
69 stage('minikube') {
70 steps {
71 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
72 sh '''
73 export MINIKUBE_WANTUPDATENOTIFICATION=false
74 export MINIKUBE_WANTREPORTERRORPROMPT=false
75 export CHANGE_MINIKUBE_NONE_USER=true
76 export MINIKUBE_HOME=$HOME
77 mkdir -p $HOME/.kube || true
78 touch $HOME/.kube/config
79 export KUBECONFIG=$HOME/.kube/config
80 sudo -E /usr/bin/minikube start --vm-driver=none
81 '''
82 script {
83 timeout(3) {
84 waitUntil {
85 sleep 5
86 def kc_ret = sh script: "kubectl get po", returnStatus: true
87 return (kc_ret == 0);
88 }
89 }
90 }
91 }
92 }
93 }
94 }
95 stage('helm') {
96 steps {
97 sh '''
98 helm init
99 sleep 60
100 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
101 '''
102 }
103 }
104 stage('Build') {
105 steps {
106 sh """
107 pushd cord/helm-charts
108 helm dep up xos-core
109 helm install -f examples/api-test-values.yaml xos-core -n xos-core
Kailash Khalasife817332018-06-06 10:15:58 -0700110 sleep 300
Kailash Khalasi54170812018-05-24 12:50:22 -0700111 helm status xos-core
112 if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service)\$ ]]; then
113 helm dep update xos-profiles/rcord-lite
114 helm install xos-profiles/rcord-lite -n rcord-lite
Kailash Khalasib024e5a2018-06-01 21:12:55 -0700115 sleep 360
Kailash Khalasi54170812018-05-24 12:50:22 -0700116 helm status xos-core
117 kubectl get pods
118 fi
119 helm ls
120 popd
121 """
122 }
123 }
124 stage('Setup') {
125 steps {
126 sh """
127 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
128 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosapitests.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosapitests.xtarget
129 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosserviceapitests.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosserviceapitests.xtarget
130 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xoslibrary.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xoslibrary.xtarget
131 docker exec -i \$CORE_CONTAINER /bin/bash -c "xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosapitests.xtarget /opt/xos/core/models/core.xproto" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/XOSCoreAPITests.robot
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700132 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
Kailash Khalasi54170812018-05-24 12:50:22 -0700133 export testname=_service_api.robot
134 export library=_library.robot
Kailash Khalasia1f3a8d2018-05-30 12:36:29 -0700135 if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service)\$ ]]; then
136 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosserviceapitests.xtarget /opt/xos/dynamic_services/\$i/\$i.xproto /opt/xos/core/models/core.xproto'" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/\$i\$testname; done
137 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xoslibrary.xtarget /opt/xos/dynamic_services/\$i/\$i.xproto /opt/xos/core/models/core.xproto'" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/\$i\$library; done
138 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700139 """
140 }
141 }
142 stage('Test') {
143 steps {
144 sh """
145 pushd cord/test/cord-tester/src/test/cord-api/Tests
146 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700147 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
148 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
Kailash Khalasi54170812018-05-24 12:50:22 -0700149 export testname=_service_api.robot
150 export library=_library.robot
151 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
152 echo \$SERVICES
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700153 export SERVER_IP=\$XOS_CHAMELEON
Kailash Khalasi54170812018-05-24 12:50:22 -0700154 export SERVER_PORT=9101
Kailash Khalasib0e29992018-05-30 13:38:09 -0700155 export XOS_USER=admin@opencord.org
Kailash Khalasi54170812018-05-24 12:50:22 -0700156 export XOS_PASSWD=\$(cat $WORKSPACE/cord/build/platform-install/credentials/xosadmin@opencord.org)
157 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700158 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700159 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700160 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
161 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
162 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700163 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
164 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700165 if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service)\$ ]]; then
166 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
167 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700168 popd
169 """
170 }
171 }
172 stage('Publish') {
173 steps {
174 sh """
175 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
176 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
177 """
178 step([$class: 'RobotPublisher',
179 disableArchiveOutput: false,
180 logFileName: 'RobotLogs/log*.html',
181 otherFiles: '',
182 outputFileName: 'RobotLogs/output*.xml',
183 outputPath: '.',
184 passThreshold: 95,
185 reportFileName: 'RobotLogs/report*.html',
186 unstableThreshold: 0]);
187 }
188 }
189 }
190 post {
191 always {
192 sh '''
Zack Williamsa834c342018-05-31 11:30:15 -0700193 kubectl get pods --all-namespaces
194 helm list
195 helm delete --purge xos-core
196 if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service)\$ ]]; then
197 helm delete --purge rcord-lite
198 fi
199 minikube delete
Kailash Khalasi54170812018-05-24 12:50:22 -0700200 '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700201 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
Kailash Khalasi54170812018-05-24 12:50:22 -0700202 }
203 }
204}