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}" |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 19 | def doTest = true |
Matteo Scandolo | 5c6a480 | 2019-05-14 10:44:21 -0700 | [diff] [blame] | 20 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 21 | pipeline { |
| 22 | |
| 23 | /* no label, executor is determined by JJB */ |
| 24 | agent { |
Zack Williams | b329208 | 2019-10-11 17:15:18 -0700 | [diff] [blame] | 25 | label "${params.buildNode}" |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | stages { |
| 29 | |
| 30 | stage('repo') { |
| 31 | steps { |
| 32 | checkout(changelog: false, \ |
| 33 | poll: false, |
| 34 | scm: [$class: 'RepoScm', \ |
| 35 | manifestRepositoryUrl: "${params.manifestUrl}", \ |
| 36 | manifestBranch: "${params.manifestBranch}", \ |
| 37 | currentBranch: true, \ |
| 38 | destinationDir: 'cord', \ |
| 39 | forceSync: true, |
| 40 | resetFirst: true, \ |
| 41 | quiet: true, \ |
| 42 | jobs: 4, \ |
| 43 | showAllChanges: true] \ |
| 44 | ) |
| 45 | } |
| 46 | } |
| 47 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 48 | stage('minikube') { |
| 49 | steps { |
| 50 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 51 | sh ''' |
| 52 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 53 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 54 | export CHANGE_MINIKUBE_NONE_USER=true |
| 55 | export MINIKUBE_HOME=$HOME |
| 56 | mkdir -p $HOME/.kube || true |
| 57 | touch $HOME/.kube/config |
| 58 | export KUBECONFIG=$HOME/.kube/config |
| 59 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 60 | ''' |
| 61 | script { |
| 62 | timeout(3) { |
| 63 | waitUntil { |
| 64 | sleep 5 |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 65 | def kc_ret = sh script: "kubectl get pods", returnStatus: true |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 66 | return (kc_ret == 0); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | stage('helm') { |
| 74 | steps { |
| 75 | sh ''' |
| 76 | helm init |
| 77 | sleep 60 |
| 78 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
Carmelo Cascone | 319b34c | 2020-01-14 16:48:07 -0800 | [diff] [blame] | 79 | helm repo add cord https://charts.opencord.org |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 80 | ''' |
| 81 | } |
| 82 | } |
| 83 | |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 84 | stage('Verify xos-core version requirements') { |
| 85 | steps { |
| 86 | script { |
| 87 | if (serviceName == "olt-service") { |
| 88 | serviceName = "volt" |
| 89 | } |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 90 | else if (serviceName == "kubernetes-service") { |
| 91 | serviceName = "kubernetes" |
| 92 | } |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 93 | def result = sh returnStdout: true, script: """ |
| 94 | #!/usr/bin/env bash |
| 95 | set -eu -o pipefail |
| 96 | |
| 97 | # Obtain git tag of the service corresponding to the the docker image |
| 98 | # used in the latest released version of the helm chart (i.e., HEAD |
| 99 | # of cord/helm-charts master branch, which should be already checked |
| 100 | # out by repo). |
| 101 | pushd cord/helm-charts |
| 102 | export RELEASED_GIT_TAG=\$(echo -e "import yaml\\nwith open('xos-services/${serviceName}/Chart.yaml', 'r') as f: print yaml.safe_load(f)['appVersion']" | python) |
| 103 | popd |
| 104 | |
| 105 | # Obtain the xos-core version requirement from the config.yaml of the |
| 106 | # released service. |
| 107 | pushd cord |
| 108 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifests/default.xml) |
| 109 | pushd \${PROJECT_PATH} |
| 110 | git fetch --all --tags |
| 111 | git checkout tags/\${RELEASED_GIT_TAG} -b foobar |
| 112 | export RELEASED_CORE_VER_REQ=\$(echo -e "import yaml\\nwith open('xos/synchronizer/config.yaml', 'r') as f: print yaml.safe_load(f)['core_version']" | python) |
| 113 | popd |
| 114 | popd |
| 115 | |
| 116 | # Do the same for the patchset we want to verify. |
| 117 | pushd cord |
| 118 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
| 119 | pushd \${PROJECT_PATH} |
| 120 | export PATCHSET_CORE_VER_REQ=\$(echo -e "import yaml\\nwith open('xos/synchronizer/config.yaml', 'r') as f: print yaml.safe_load(f)['core_version']" | python) |
| 121 | popd |
| 122 | popd |
| 123 | |
| 124 | # We need to produce at least one log file so the archiveArtifacts |
| 125 | # step later won't complain. |
| 126 | echo "RELEASED_CORE_VER_REQ: \${RELEASED_CORE_VER_REQ}" >> $WORKSPACE/version_requirements.log |
| 127 | echo "PATCHSET_CORE_VER_REQ: \${PATCHSET_CORE_VER_REQ}" >> $WORKSPACE/version_requirements.log |
| 128 | |
| 129 | if [ "\${PATCHSET_CORE_VER_REQ}" == "\${RELEASED_CORE_VER_REQ}" ]; then |
| 130 | echo 0 |
| 131 | else |
| 132 | # versionMismatch is true |
| 133 | echo 1 |
| 134 | fi |
| 135 | """ |
| 136 | def versionMismatch = result.readLines().last().toBoolean() |
| 137 | if (versionMismatch) { |
| 138 | echo "Detected xos-core version requirements mismatch. Will skip the rest of the pipeline and return SUCCESS" |
| 139 | } |
| 140 | doTest = !versionMismatch |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 141 | } |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 145 | // The patchset should be already checked out, but for consistency with |
| 146 | // other pipeline jobs, we re-do the same here. |
| 147 | stage('patch') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 148 | when { |
| 149 | expression { doTest } |
| 150 | } |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 151 | steps { |
| 152 | sh ''' |
| 153 | pushd cord |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 154 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifests/default.xml) |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 155 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
| 156 | popd |
| 157 | ''' |
| 158 | } |
| 159 | } |
| 160 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 161 | stage('Install XOS w/Service') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 162 | when { |
| 163 | expression { doTest } |
| 164 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 165 | steps { |
Carmelo Cascone | 43086e1 | 2020-03-23 19:29:04 -0700 | [diff] [blame] | 166 | script { |
Kailash | 5f300b9 | 2019-05-21 14:04:19 -0700 | [diff] [blame] | 167 | if (serviceName == "olt-service") { |
| 168 | serviceName = "volt" |
| 169 | } |
Kailash | 5f300b9 | 2019-05-21 14:04:19 -0700 | [diff] [blame] | 170 | else if (serviceName == "kubernetes-service") { |
| 171 | serviceName = "kubernetes" |
| 172 | } |
| 173 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 174 | sh """ |
| 175 | #!/usr/bin/env bash |
| 176 | set -eu -o pipefail |
| 177 | |
| 178 | pushd cord/helm-charts |
| 179 | helm dep update xos-core |
| 180 | helm install xos-core -n xos-core |
| 181 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 182 | helm-repo-tools/wait_for_pods.sh |
| 183 | |
| 184 | #install service |
Kailash | 5f300b9 | 2019-05-21 14:04:19 -0700 | [diff] [blame] | 185 | helm dep update xos-services/${serviceName} |
| 186 | helm install xos-services/${serviceName} -n ${serviceName} |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 187 | popd |
| 188 | """ |
| 189 | } |
| 190 | } |
| 191 | stage('Verify') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 192 | when { |
| 193 | expression { doTest } |
| 194 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 195 | steps { |
Matteo Scandolo | 5c6a480 | 2019-05-14 10:44:21 -0700 | [diff] [blame] | 196 | echo "serviceName: ${serviceName}" |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 197 | sh """ |
| 198 | #!/usr/bin/env bash |
| 199 | set -ex -o pipefail |
| 200 | export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION) |
| 201 | |
| 202 | #wait for xos-core and models to be loaded |
| 203 | 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] | 204 | 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] | 205 | |
| 206 | ## get pod logs |
| 207 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 208 | do |
Daniele Moro | a5f0078 | 2020-02-24 11:23:46 -0800 | [diff] [blame] | 209 | kubectl logs \${pod} > $WORKSPACE/\${pod}_pre.log; |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 210 | done |
| 211 | """ |
| 212 | } |
| 213 | } |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 214 | stage('Generate Model API Tests') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 215 | when { |
| 216 | expression { doTest } |
| 217 | } |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 218 | steps { |
| 219 | sh """ |
| 220 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 221 | cd $WORKSPACE/cord/test/cord-tester |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 222 | 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 |
| 223 | 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 |
| 224 | |
| 225 | export testname=_service_api.robot |
| 226 | export library=_library.robot |
| 227 | |
| 228 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 229 | echo \$SERVICES |
| 230 | |
| 231 | 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 |
| 232 | |
| 233 | 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 |
| 234 | ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/ |
| 235 | """ |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | stage('Test Pre-Upgrade') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 240 | when { |
| 241 | expression { doTest } |
| 242 | } |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 243 | steps { |
| 244 | sh """ |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 245 | #!/usr/bin/env bash |
| 246 | set -ex -o pipefail |
| 247 | |
| 248 | pushd cord/test/cord-tester |
| 249 | make venv_cord |
| 250 | source venv_cord/bin/activate |
| 251 | cd src/test/cord-api/Tests |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 252 | |
| 253 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 254 | CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}') |
| 255 | XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172) |
| 256 | |
| 257 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/ |
| 258 | sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py |
| 259 | sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py |
| 260 | sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py |
| 261 | sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 262 | sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 263 | |
| 264 | export testname=_service_api.robot |
| 265 | export library=_library.robot |
| 266 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 267 | echo \$SERVICES |
| 268 | |
| 269 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
Matteo Scandolo | 5c6a480 | 2019-05-14 10:44:21 -0700 | [diff] [blame] | 270 | 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] | 271 | |
| 272 | popd |
| 273 | """ |
| 274 | } |
| 275 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 276 | |
| 277 | stage('Build/Install New Service') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 278 | when { |
| 279 | expression { doTest } |
| 280 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 281 | steps { |
| 282 | sh """ |
| 283 | #!/usr/bin/env bash |
| 284 | set -eu -o pipefail |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 285 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 286 | pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject} |
| 287 | export DOCKER_TAG=\$(cat VERSION)-test |
| 288 | export DOCKER_REPOSITORY=xosproject/ |
| 289 | export DOCKER_BUILD_ARGS=--no-cache |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 290 | echo "\$(cat VERSION)-test" > VERSION |
| 291 | make docker-build |
| 292 | |
| 293 | #install newservice |
| 294 | cd $WORKSPACE/cord/helm-charts |
| 295 | helm upgrade --set image.tag=\$DOCKER_TAG \ |
| 296 | --set image.pullPolicy=Never \ |
Kailash | 5f300b9 | 2019-05-21 14:04:19 -0700 | [diff] [blame] | 297 | --recreate-pods ${serviceName} xos-services/${serviceName} |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 298 | popd |
| 299 | """ |
| 300 | } |
| 301 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 302 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 303 | stage('Verify Service Upgrade') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 304 | when { |
| 305 | expression { doTest } |
| 306 | } |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 307 | steps { |
| 308 | sh """ |
| 309 | #!/usr/bin/env bash |
| 310 | set -ex -o pipefail |
| 311 | DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION) |
| 312 | |
| 313 | #wait for xos-core and models to be loaded |
| 314 | 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] | 315 | 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" |
| 316 | 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] | 317 | sleep 120 |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 318 | """ |
| 319 | } |
| 320 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 321 | |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 322 | stage('Test Post-Upgrade') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 323 | when { |
| 324 | expression { doTest } |
| 325 | } |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 326 | steps { |
| 327 | sh """ |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 328 | #!/usr/bin/env bash |
| 329 | set -ex -o pipefail |
| 330 | |
| 331 | cd cord/test/cord-tester |
| 332 | make venv_cord |
| 333 | source venv_cord/bin/activate |
| 334 | cd src/test/cord-api/Tests |
| 335 | |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 336 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 337 | |
| 338 | export testname=_service_api.robot |
| 339 | export library=_library.robot |
| 340 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 341 | echo \$SERVICES |
Matteo Scandolo | 5c6a480 | 2019-05-14 10:44:21 -0700 | [diff] [blame] | 342 | 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] | 343 | """ |
| 344 | } |
| 345 | } |
| 346 | |
Andy Bavier | e053ad3 | 2019-05-09 13:58:34 -0700 | [diff] [blame] | 347 | /* Disable the downgrade step because the core doesn't support reverse migrations |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 348 | stage('Downgrade Service') { |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 349 | when { |
| 350 | expression { doTest } |
| 351 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 352 | steps { |
| 353 | sh """ |
| 354 | #!/usr/bin/env bash |
| 355 | set -eu -o pipefail |
| 356 | |
| 357 | pushd cord/helm-charts |
| 358 | #delete service |
| 359 | helm delete --purge ${gerritProject} |
| 360 | |
| 361 | #re-install service with previous version |
| 362 | helm dep update xos-services/${gerritProject} |
| 363 | helm install xos-services/${gerritProject} -n ${gerritProject} |
| 364 | |
| 365 | #wait for xos-core and models to be loaded |
| 366 | 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" |
| 367 | 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] | 368 | sleep 120 |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 369 | |
| 370 | cd $WORKSPACE/cord/test/cord-tester |
| 371 | make venv_cord |
| 372 | source venv_cord/bin/activate |
| 373 | cd src/test/cord-api/Tests |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 374 | |
| 375 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 376 | |
| 377 | export testname=_service_api.robot |
| 378 | export library=_library.robot |
| 379 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 380 | |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 381 | echo \$SERVICES |
| 382 | 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 |
| 383 | |
| 384 | ## get pod logs |
| 385 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 386 | do |
| 387 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 388 | done || true |
| 389 | |
| 390 | popd |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 391 | """ |
| 392 | } |
| 393 | } |
Andy Bavier | e053ad3 | 2019-05-09 13:58:34 -0700 | [diff] [blame] | 394 | */ |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 395 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 396 | } |
Kailash | 44fd62c | 2019-04-30 10:26:31 -0700 | [diff] [blame] | 397 | |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 398 | post { |
| 399 | always { |
| 400 | sh """ |
Daniele Moro | a5f0078 | 2020-02-24 11:23:46 -0800 | [diff] [blame] | 401 | ## get pod logs |
| 402 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 403 | do |
| 404 | kubectl logs \${pod} > $WORKSPACE/\${pod}_post.log; |
| 405 | done |
| 406 | |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 407 | # copy robot logs |
| 408 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 409 | cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs || true |
| 410 | # Workaorund for when doTest is false and there's no Robot output to |
| 411 | # process. Without this file, RobotPublisher below will fail marking |
| 412 | # the build as FAILED. |
| 413 | if [ ! -f RobotLogs/output.xml ]; then echo '<xml></xml>' > RobotLogs/output.xml; fi; |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 414 | kubectl get pods --all-namespaces |
| 415 | kubectl describe pods |
Carmelo Cascone | 2c57fc3 | 2020-03-24 17:41:32 -0700 | [diff] [blame] | 416 | http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status || true |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 417 | echo "# removing helm deployments" |
| 418 | kubectl get pods |
| 419 | helm list |
| 420 | |
| 421 | for hchart in \$(helm list -q); |
| 422 | do |
| 423 | echo "## Purging chart: \${hchart} ##" |
| 424 | helm delete --purge "\${hchart}" |
| 425 | done |
| 426 | |
| 427 | sudo minikube delete |
| 428 | """ |
Kailash | f5c3f2b | 2019-04-30 08:58:49 -0700 | [diff] [blame] | 429 | step([$class: 'RobotPublisher', |
| 430 | disableArchiveOutput: false, |
| 431 | logFileName: 'RobotLogs/log*.html', |
| 432 | otherFiles: '', |
| 433 | outputFileName: 'RobotLogs/output*.xml', |
| 434 | outputPath: '.', |
| 435 | passThreshold: 100, |
| 436 | reportFileName: 'RobotLogs/report*.html', |
| 437 | unstableThreshold: 0]); |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 438 | archiveArtifacts artifacts: '*.log' |
Zack Williams | d7af207 | 2020-03-06 13:11:26 -0700 | [diff] [blame] | 439 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "scottb@opennetworking.org", sendToIndividuals: false]) |
Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |