Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [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 | // chart-api-test-helm.groovy |
| 16 | // Checks functionality of the helm-chart, without overriding the version/tag used |
| 17 | |
| 18 | pipeline { |
| 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('minikube') { |
| 57 | steps { |
| 58 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 59 | sh ''' |
| 60 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 61 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 62 | export CHANGE_MINIKUBE_NONE_USER=true |
| 63 | export MINIKUBE_HOME=$HOME |
| 64 | mkdir -p $HOME/.kube || true |
| 65 | touch $HOME/.kube/config |
| 66 | export KUBECONFIG=$HOME/.kube/config |
| 67 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 68 | ''' |
| 69 | script { |
| 70 | timeout(3) { |
| 71 | waitUntil { |
| 72 | sleep 5 |
| 73 | def kc_ret = sh script: "kubectl get po", returnStatus: true |
| 74 | return (kc_ret == 0); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | stage('helm') { |
| 82 | steps { |
| 83 | sh ''' |
| 84 | helm init |
| 85 | sleep 60 |
| 86 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 87 | ''' |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | stage('Install XOS w/Service') { |
| 92 | steps { |
| 93 | sh """ |
| 94 | #!/usr/bin/env bash |
| 95 | set -eu -o pipefail |
| 96 | |
| 97 | pushd cord/helm-charts |
| 98 | helm dep update xos-core |
| 99 | helm install xos-core -n xos-core |
| 100 | |
| 101 | git clone https://gerrit.opencord.org/helm-repo-tools |
| 102 | helm-repo-tools/wait_for_pods.sh |
| 103 | |
| 104 | #install service |
| 105 | helm dep update xos-services/${gerritProject} |
| 106 | helm install xos-services/${gerritProject} -n ${gerritProject} |
| 107 | popd |
| 108 | """ |
| 109 | } |
| 110 | } |
| 111 | stage('Verify') { |
| 112 | steps { |
| 113 | sh """ |
| 114 | #!/usr/bin/env bash |
| 115 | set -ex -o pipefail |
| 116 | export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION) |
| 117 | |
| 118 | #wait for xos-core and models to be loaded |
| 119 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 120 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 121 | |
| 122 | ## get pod logs |
| 123 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 124 | do |
| 125 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 126 | done |
| 127 | """ |
| 128 | } |
| 129 | } |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 130 | stage('Generate Model API Tests') { |
| 131 | steps { |
| 132 | sh """ |
| 133 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 134 | cd $WORKSPACE/cord/test/cord-tester |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 135 | docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosserviceupgradetest.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosserviceupgradetest.xtarget |
| 136 | docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosstaticlibrary.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosstaticlibrary.xtarget |
| 137 | |
| 138 | export testname=_service_api.robot |
| 139 | export library=_library.robot |
| 140 | |
| 141 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 142 | echo \$SERVICES |
| 143 | |
| 144 | for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosserviceupgradetest.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 |
| 145 | |
| 146 | for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosstaticlibrary.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 |
| 147 | ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/ |
| 148 | """ |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | stage('Test Pre-Upgrade') { |
| 153 | steps { |
| 154 | sh """ |
| 155 | pushd cord/test/cord-tester/src/test/cord-api/Tests |
| 156 | |
| 157 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 158 | CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}') |
| 159 | XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172) |
| 160 | |
| 161 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/ |
| 162 | sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py |
| 163 | sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py |
| 164 | sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py |
| 165 | sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 166 | sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 167 | |
| 168 | export testname=_service_api.robot |
| 169 | export library=_library.robot |
| 170 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 171 | echo \$SERVICES |
| 172 | |
| 173 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
| 174 | for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i create -d Log -T -v TESTLIBRARY:${gerritProject}_library.robot \$i\$testname"; sleep 2; done || true |
| 175 | |
| 176 | popd |
| 177 | """ |
| 178 | } |
| 179 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 180 | |
| 181 | stage('Build/Install New Service') { |
| 182 | steps { |
| 183 | sh """ |
| 184 | #!/usr/bin/env bash |
| 185 | set -eu -o pipefail |
| 186 | pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject} |
| 187 | export DOCKER_TAG=\$(cat VERSION)-test |
| 188 | export DOCKER_REPOSITORY=xosproject/ |
| 189 | export DOCKER_BUILD_ARGS=--no-cache |
| 190 | cd $WORKSPACE/cord/orchestration/xos-services/${gerritProject} |
| 191 | echo "\$(cat VERSION)-test" > VERSION |
| 192 | make docker-build |
| 193 | |
| 194 | #install newservice |
| 195 | cd $WORKSPACE/cord/helm-charts |
| 196 | helm upgrade --set image.tag=\$DOCKER_TAG \ |
| 197 | --set image.pullPolicy=Never \ |
| 198 | --recreate-pods ${gerritProject} xos-services/${gerritProject} |
| 199 | popd |
| 200 | """ |
| 201 | } |
| 202 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 203 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 204 | stage('Verify Service Upgrade') { |
| 205 | steps { |
| 206 | sh """ |
| 207 | #!/usr/bin/env bash |
| 208 | set -ex -o pipefail |
| 209 | DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION) |
| 210 | |
| 211 | #wait for xos-core and models to be loaded |
| 212 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 213 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for New Service to be loaded'; sleep 5; done" |
| 214 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").version'| grep -q \$DOCKER_TAG; do echo 'Waiting for New Service Version Check'; sleep 5; done" |
Kailash | 4590ca1 | 2019-04-30 14:49:22 -0700 | [diff] [blame] | 215 | sleep 120 |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 216 | """ |
| 217 | } |
| 218 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 219 | |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 220 | stage('Test Post-Upgrade') { |
| 221 | steps { |
| 222 | sh """ |
| 223 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 224 | |
| 225 | export testname=_service_api.robot |
| 226 | export library=_library.robot |
| 227 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 228 | echo \$SERVICES |
| 229 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
| 230 | for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i get -d Log -T -v TESTLIBRARY:${gerritProject}_library.robot \$i\$testname"; sleep 2; done || true |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 231 | |
| 232 | ## get pod logs |
| 233 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 234 | do |
| 235 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 236 | done || true |
| 237 | """ |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | stage('Downgrade Service') { |
| 242 | steps { |
| 243 | sh """ |
| 244 | #!/usr/bin/env bash |
| 245 | set -eu -o pipefail |
| 246 | |
| 247 | pushd cord/helm-charts |
| 248 | #delete service |
| 249 | helm delete --purge ${gerritProject} |
| 250 | |
| 251 | #re-install service with previous version |
| 252 | helm dep update xos-services/${gerritProject} |
| 253 | helm install xos-services/${gerritProject} -n ${gerritProject} |
| 254 | |
| 255 | #wait for xos-core and models to be loaded |
| 256 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 257 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for Service to be loaded'; sleep 5; done" |
Kailash | 4590ca1 | 2019-04-30 14:49:22 -0700 | [diff] [blame] | 258 | sleep 120 |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 259 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
| 260 | |
| 261 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 262 | |
| 263 | export testname=_service_api.robot |
| 264 | export library=_library.robot |
| 265 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 266 | echo \$SERVICES |
| 267 | for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i get -d Log -T -v TESTLIBRARY:${gerritProject}_library.robot \$i\$testname"; sleep 2; done || true |
| 268 | |
| 269 | ## get pod logs |
| 270 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 271 | do |
| 272 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 273 | done || true |
| 274 | |
| 275 | popd |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 276 | """ |
| 277 | } |
| 278 | } |
| 279 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 280 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 281 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 282 | post { |
| 283 | always { |
| 284 | sh """ |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 285 | # copy robot logs |
| 286 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
| 287 | cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 288 | kubectl get pods --all-namespaces |
| 289 | kubectl describe pods |
| 290 | http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status |
| 291 | echo "# removing helm deployments" |
| 292 | kubectl get pods |
| 293 | helm list |
| 294 | |
| 295 | for hchart in \$(helm list -q); |
| 296 | do |
| 297 | echo "## Purging chart: \${hchart} ##" |
| 298 | helm delete --purge "\${hchart}" |
| 299 | done |
| 300 | |
| 301 | sudo minikube delete |
| 302 | """ |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 303 | step([$class: 'RobotPublisher', |
| 304 | disableArchiveOutput: false, |
| 305 | logFileName: 'RobotLogs/log*.html', |
| 306 | otherFiles: '', |
| 307 | outputFileName: 'RobotLogs/output*.xml', |
| 308 | outputPath: '.', |
| 309 | passThreshold: 100, |
| 310 | reportFileName: 'RobotLogs/report*.html', |
| 311 | unstableThreshold: 0]); |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 312 | archiveArtifacts artifacts: '*.log' |
| 313 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "kailash@opennetworking.org, scottb@opennetworking.org", sendToIndividuals: false]) |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |