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