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 |
Zack Williams | a318503 | 2018-07-03 17:38:33 -0700 | [diff] [blame] | 118 | mkdir ib_logs |
Zack Williams | 7fea572 | 2018-07-03 21:17:47 -0700 | [diff] [blame] | 119 | ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 120 | popd |
| 121 | ''' |
Zack Williams | a318503 | 2018-07-03 17:38:33 -0700 | [diff] [blame] | 122 | archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | stage('minikube') { |
| 127 | steps { |
| 128 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 129 | sh ''' |
| 130 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 131 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 132 | export CHANGE_MINIKUBE_NONE_USER=true |
| 133 | export MINIKUBE_HOME=$HOME |
| 134 | mkdir -p $HOME/.kube || true |
| 135 | touch $HOME/.kube/config |
| 136 | export KUBECONFIG=$HOME/.kube/config |
| 137 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 138 | ''' |
| 139 | script { |
| 140 | timeout(3) { |
| 141 | waitUntil { |
| 142 | sleep 5 |
| 143 | def kc_ret = sh script: "kubectl get po", returnStatus: true |
| 144 | return (kc_ret == 0); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | stage('helm') { |
| 153 | steps { |
| 154 | sh ''' |
| 155 | helm init |
| 156 | sleep 60 |
| 157 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 158 | ''' |
| 159 | } |
| 160 | } |
| 161 | stage('Build') { |
| 162 | steps { |
| 163 | sh """ |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 164 | #!/usr/bin/env bash |
| 165 | set -eu -o pipefail |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 166 | |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 167 | helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml' |
| 168 | basesleep=300 |
| 169 | extrasleep=60 |
| 170 | |
| 171 | pushd cord/helm-charts |
| 172 | |
| 173 | helm dep up xos-core |
| 174 | helm install \${helm_install_args} xos-core -n xos-core |
| 175 | |
| 176 | # Pick which chart(s) to load depending on the project being tested |
| 177 | # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded! |
| 178 | |
| 179 | if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then |
| 180 | helm dep update xos-profiles/rcord-lite |
| 181 | helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite |
| 182 | extrasleep=300 |
| 183 | |
| 184 | elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then |
Zack Williams | ee86e66 | 2018-07-06 10:18:28 -0700 | [diff] [blame] | 185 | helm dep update xos-profiles/base-openstack |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 186 | helm dep update xos-profiles/mcord |
Zack Williams | ee86e66 | 2018-07-06 10:18:28 -0700 | [diff] [blame] | 187 | helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack |
| 188 | helm install \${helm_install_args} xos-profiles/mcord -n mcord |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 189 | extrasleep=900 |
| 190 | |
| 191 | elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then |
| 192 | # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart |
| 193 | |
| 194 | helm dep update xos-profiles/base-openstack |
| 195 | helm dep update xos-profiles/demo-exampleservice |
| 196 | helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack |
| 197 | helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice |
| 198 | |
| 199 | elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then |
| 200 | helm dep update xos-profiles/base-kubernetes |
| 201 | helm dep update xos-profiles/demo-simpleexampleservice |
| 202 | helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes |
| 203 | helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice |
| 204 | |
| 205 | elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then |
| 206 | helm dep update xos-services/hippie-oss |
| 207 | helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss |
| 208 | |
Zack Williams | bafed36 | 2018-07-05 16:32:27 -0700 | [diff] [blame] | 209 | elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then |
| 210 | echo "No additional charts to install for testing $GERRIT_PROJECT" |
| 211 | |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 212 | else |
| 213 | echo "Couldn't find a chart to test project: $GERRIT_PROJECT!" |
| 214 | exit 1 |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 215 | fi |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 216 | |
| 217 | # sleep to wait for services to load |
| 218 | sleep "\$basesleep" |
| 219 | sleep "\$extrasleep" |
| 220 | |
| 221 | echo "# Checking helm deployments" |
Kailash Khalasi | 12b2e22 | 2018-06-13 09:45:25 -0700 | [diff] [blame] | 222 | kubectl get pods |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 223 | helm list |
| 224 | |
| 225 | for hchart in \$(helm list -q); |
| 226 | do |
| 227 | echo "## 'helm status' for chart: \${hchart} ##" |
| 228 | helm status "\${hchart}" |
| 229 | done |
| 230 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 231 | popd |
| 232 | """ |
| 233 | } |
| 234 | } |
| 235 | stage('Setup') { |
| 236 | steps { |
| 237 | sh """ |
| 238 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 239 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 240 | 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 |
| 241 | 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 |
| 242 | 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 |
| 243 | 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 |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 244 | |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 245 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 246 | |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 247 | export testname=_service_api.robot |
| 248 | export library=_library.robot |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 249 | |
| 250 | # do addtional tests if additional services are loaded |
Zack Williams | bafed36 | 2018-07-05 16:32:27 -0700 | [diff] [blame] | 251 | if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 252 | 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 |
| 253 | 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 |
Kailash Khalasi | a1f3a8d | 2018-05-30 12:36:29 -0700 | [diff] [blame] | 254 | fi |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 255 | """ |
| 256 | } |
| 257 | } |
| 258 | stage('Test') { |
| 259 | steps { |
| 260 | sh """ |
| 261 | pushd cord/test/cord-tester/src/test/cord-api/Tests |
| 262 | CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}') |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 263 | CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}') |
| 264 | 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] | 265 | export testname=_service_api.robot |
| 266 | export library=_library.robot |
| 267 | SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}') |
| 268 | echo \$SERVICES |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 269 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/ |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 270 | sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 271 | sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 272 | sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py |
| 273 | sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
| 274 | sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 275 | cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests |
| 276 | 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] | 277 | if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 278 | for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true |
| 279 | fi |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 280 | popd |
| 281 | """ |
| 282 | } |
| 283 | } |
| 284 | stage('Publish') { |
| 285 | steps { |
| 286 | sh """ |
| 287 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
| 288 | cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs |
| 289 | """ |
| 290 | step([$class: 'RobotPublisher', |
| 291 | disableArchiveOutput: false, |
| 292 | logFileName: 'RobotLogs/log*.html', |
| 293 | otherFiles: '', |
| 294 | outputFileName: 'RobotLogs/output*.xml', |
| 295 | outputPath: '.', |
Kailash Khalasi | a4cad35 | 2018-07-02 10:58:07 -0700 | [diff] [blame] | 296 | passThreshold: 95, |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 297 | reportFileName: 'RobotLogs/report*.html', |
| 298 | unstableThreshold: 0]); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | post { |
| 303 | always { |
| 304 | sh ''' |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 305 | kubectl get pods --all-namespaces |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 306 | |
| 307 | echo "# removing helm deployments" |
| 308 | kubectl get pods |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 309 | helm list |
Zack Williams | c8cfb22 | 2018-07-05 13:29:28 -0700 | [diff] [blame] | 310 | |
| 311 | for hchart in \$(helm list -q); |
| 312 | do |
| 313 | echo "## Purging chart: \${hchart} ##" |
| 314 | helm delete --purge "\${hchart}" |
| 315 | done |
| 316 | |
Zack Williams | a834c34 | 2018-05-31 11:30:15 -0700 | [diff] [blame] | 317 | minikube delete |
Kailash Khalasi | 5417081 | 2018-05-24 12:50:22 -0700 | [diff] [blame] | 318 | ''' |
Kailash Khalasi | 934d39b | 2018-05-30 10:59:49 -0700 | [diff] [blame] | 319 | 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] | 320 | } |
| 321 | } |
| 322 | } |