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