Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -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 | PROFILE="null" |
| 16 | CORE_CONTAINER="null" |
| 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 """ |
Zack Williams | 0efdd26 | 2018-06-28 14:17:29 -0700 | [diff] [blame] | 48 | #!/usr/bin/env bash |
| 49 | set -eu -o pipefail |
| 50 | |
| 51 | VERSIONFILE="" # file path to file containing version number |
| 52 | NEW_VERSION="" # version number found in VERSIONFILE |
Zack Williams | 2d0ac6b | 2018-06-29 09:17:41 -0700 | [diff] [blame] | 53 | releaseversion=0 |
Zack Williams | 0efdd26 | 2018-06-28 14:17:29 -0700 | [diff] [blame] | 54 | |
| 55 | function read_version { |
| 56 | if [ -f "VERSION" ] |
| 57 | then |
| 58 | NEW_VERSION=\$(head -n1 "VERSION") |
| 59 | VERSIONFILE="VERSION" |
| 60 | elif [ -f "package.json" ] |
| 61 | then |
| 62 | NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json) |
| 63 | VERSIONFILE="package.json" |
| 64 | else |
| 65 | echo "ERROR: No versioning file found!" |
| 66 | exit 1 |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # check if the version is a released version |
| 71 | function check_if_releaseversion { |
| 72 | if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]] |
| 73 | then |
| 74 | echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!" |
| 75 | releaseversion=1 |
| 76 | else |
| 77 | echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping." |
| 78 | fi |
| 79 | } |
| 80 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 81 | pushd cord |
| 82 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml) |
| 83 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
Zack Williams | 0efdd26 | 2018-06-28 14:17:29 -0700 | [diff] [blame] | 84 | |
| 85 | pushd \$PROJECT_PATH |
| 86 | echo "Existing git tags:" |
| 87 | git tag -n |
| 88 | |
| 89 | read_version |
| 90 | check_if_releaseversion |
| 91 | |
| 92 | # perform checks if a released version |
| 93 | if [ "\$releaseversion" -eq "1" ] |
| 94 | then |
| 95 | git config --global user.email "apitest@opencord.org" |
| 96 | git config --global user.name "API Test" |
| 97 | |
| 98 | git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}" |
| 99 | |
| 100 | echo "Tags including new tag:" |
| 101 | git tag -n |
| 102 | |
| 103 | fi |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 104 | popd |
Zack Williams | 0efdd26 | 2018-06-28 14:17:29 -0700 | [diff] [blame] | 105 | popd |
| 106 | """ |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Zack Williams | 0efdd26 | 2018-06-28 14:17:29 -0700 | [diff] [blame] | 110 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 111 | stage('prep') { |
| 112 | parallel { |
| 113 | |
| 114 | stage('images') { |
| 115 | steps { |
| 116 | sh ''' |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 117 | pushd cord/automation-tools/developer |
| 118 | ./imagebuilder.py -f ../../helm-charts/examples/api-test-images.yaml |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 119 | popd |
| 120 | ''' |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | stage('minikube') { |
| 125 | steps { |
| 126 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 127 | sh ''' |
| 128 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 129 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 130 | export CHANGE_MINIKUBE_NONE_USER=true |
| 131 | export MINIKUBE_HOME=$HOME |
| 132 | mkdir -p $HOME/.kube || true |
| 133 | touch $HOME/.kube/config |
| 134 | export KUBECONFIG=$HOME/.kube/config |
| 135 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 136 | ''' |
| 137 | script { |
| 138 | timeout(3) { |
| 139 | waitUntil { |
| 140 | sleep 5 |
| 141 | def kc_ret = sh script: "kubectl get po", returnStatus: true |
| 142 | return (kc_ret == 0); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | stage('helm') { |
| 151 | steps { |
| 152 | sh ''' |
| 153 | helm init |
| 154 | sleep 60 |
| 155 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 156 | ''' |
| 157 | } |
| 158 | } |
| 159 | stage('Build') { |
| 160 | steps { |
| 161 | sh """ |
| 162 | pushd cord/helm-charts |
| 163 | helm dep up xos-core |
Kailash Khalasi | 118d55a | 2018-07-03 13:41:34 -0700 | [diff] [blame] | 164 | helm install -f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml xos-core -n xos-core |
Kailash Khalasi | fe81733 | 2018-06-06 10:15:58 -0700 | [diff] [blame] | 165 | sleep 300 |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 166 | helm status xos-core |
Zack Williams | e82f12d | 2018-07-02 10:08:10 -0700 | [diff] [blame] | 167 | if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn-service|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service|hippie-oss|vsg-hw)\$ ]]; then |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 168 | helm dep update xos-profiles/rcord-lite |
Kailash Khalasi | 118d55a | 2018-07-03 13:41:34 -0700 | [diff] [blame] | 169 | helm install -f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml xos-profiles/rcord-lite -n rcord-lite |
Kailash Khalasi | b024e5a | 2018-06-01 21:12:55 -0700 | [diff] [blame] | 170 | sleep 360 |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 171 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 172 | fi |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 173 | if [[ "$GERRIT_PROJECT" =~ ^(mcord|vspgwu|venb|vspgwc|vEPC|vMME|vHSS|hss_db|epc-service|internetemulator|sdn-controller)\$ ]]; then |
| 174 | helm dep update xos-profiles/mcord |
Kailash Khalasi | 118d55a | 2018-07-03 13:41:34 -0700 | [diff] [blame] | 175 | helm install -f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml xos-profiles/mcord -n mcord |
Kailash Khalasi | f23fbc3 | 2018-06-15 11:35:01 -0700 | [diff] [blame] | 176 | sleep 900 |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 177 | fi |
| 178 | helm status xos-core |
| 179 | kubectl get pods |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 180 | helm ls |
| 181 | popd |
| 182 | """ |
| 183 | } |
| 184 | } |
| 185 | stage('Setup') { |
| 186 | steps { |
| 187 | sh """ |
| 188 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
| 189 | 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 |
| 190 | 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 |
| 191 | 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 |
| 192 | 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 Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 193 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 194 | export testname=_service_api.robot |
| 195 | export library=_library.robot |
Kailash Khalasi | eaea605 | 2018-06-15 17:51:19 -0700 | [diff] [blame] | 196 | if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then |
Kailash Khalasi | a1f3a8d | 2018-05-30 12:36:29 -0700 | [diff] [blame] | 197 | 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 |
| 198 | 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 |
| 199 | fi |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 200 | """ |
| 201 | } |
| 202 | } |
| 203 | stage('Test') { |
| 204 | steps { |
| 205 | sh """ |
| 206 | pushd cord/test/cord-tester/src/test/cord-api/Tests |
| 207 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 208 | CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}') |
| 209 | XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172) |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 210 | export testname=_service_api.robot |
| 211 | export library=_library.robot |
| 212 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 213 | echo \$SERVICES |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 214 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/ |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 215 | sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 216 | sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 217 | sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py |
| 218 | sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 219 | sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 220 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
| 221 | pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true |
Kailash Khalasi | eaea605 | 2018-06-15 17:51:19 -0700 | [diff] [blame] | 222 | if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 223 | for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true |
| 224 | fi |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 225 | popd |
| 226 | """ |
| 227 | } |
| 228 | } |
| 229 | stage('Publish') { |
| 230 | steps { |
| 231 | sh """ |
| 232 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
| 233 | cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs |
| 234 | """ |
| 235 | step([$class: 'RobotPublisher', |
| 236 | disableArchiveOutput: false, |
| 237 | logFileName: 'RobotLogs/log*.html', |
| 238 | otherFiles: '', |
| 239 | outputFileName: 'RobotLogs/output*.xml', |
| 240 | outputPath: '.', |
Kailash Khalasi | a4cad35 | 2018-07-02 10:58:07 -0700 | [diff] [blame] | 241 | passThreshold: 95, |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 242 | reportFileName: 'RobotLogs/report*.html', |
| 243 | unstableThreshold: 0]); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | post { |
| 248 | always { |
| 249 | sh ''' |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 250 | kubectl get pods --all-namespaces |
| 251 | helm list |
| 252 | helm delete --purge xos-core |
Kailash Khalasi | b94ae86 | 2018-06-20 06:26:58 -0700 | [diff] [blame] | 253 | if [[ "$GERRIT_PROJECT" =~ ^(rcord|vrouter|vsg|vtn|vtr|fabric|openstack|chameleon|exampleservice|simpleexampleservice|onos-service|olt-service|kubernetes-service|hippie-oss|vsg-hw)\$ ]]; then |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 254 | helm delete --purge rcord-lite |
| 255 | fi |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 256 | if [[ "$GERRIT_PROJECT" =~ ^(mcord|vspgwu|venb|vspgwc|vEPC|vMME|vHSS|hss_db|epc-service|internetemulator|sdn-controller)\$ ]]; then |
| 257 | helm delete --purge mcord |
| 258 | fi |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 259 | minikube delete |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 260 | ''' |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 261 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false]) |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | } |