Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 1 | // Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 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 | |
| 18 | pipeline { |
| 19 | |
| 20 | /* no label, executor is determined by JJB */ |
| 21 | agent { |
Zack Williams | b329208 | 2019-10-11 17:15:18 -0700 | [diff] [blame] | 22 | label "${params.buildNode}" |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 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 | |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 45 | stage('patch') { |
| 46 | steps { |
| 47 | sh ''' |
| 48 | pushd cord |
Zack Williams | de1c621 | 2020-02-24 17:00:17 -0700 | [diff] [blame] | 49 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifests/default.xml) |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 50 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
| 51 | popd |
| 52 | ''' |
| 53 | } |
| 54 | } |
| 55 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 56 | stage('minikube') { |
| 57 | steps { |
| 58 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 59 | sh ''' |
| 60 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 61 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 62 | export CHANGE_MINIKUBE_NONE_USER=true |
| 63 | export MINIKUBE_HOME=$HOME |
| 64 | mkdir -p $HOME/.kube || true |
| 65 | touch $HOME/.kube/config |
| 66 | export KUBECONFIG=$HOME/.kube/config |
| 67 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 68 | ''' |
| 69 | script { |
| 70 | timeout(3) { |
| 71 | waitUntil { |
| 72 | sleep 5 |
Daniele Moro | 6b4d379 | 2020-04-15 17:53:45 +0200 | [diff] [blame] | 73 | def kc_ret = sh script: "kubectl get pods", returnStatus: true |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 74 | return (kc_ret == 0); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | stage('helm') { |
| 82 | steps { |
| 83 | sh ''' |
| 84 | helm init |
| 85 | sleep 60 |
| 86 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
Daniele Moro | 4df7577 | 2020-02-14 15:14:48 -0800 | [diff] [blame] | 87 | helm repo add cord https://charts.opencord.org |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 88 | ''' |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | stage ('Build XOS Core and TestService') { |
| 93 | steps { |
| 94 | sh """ |
| 95 | #!/usr/bin/env bash |
| 96 | set -eu -o pipefail |
| 97 | |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 98 | export DOCKER_REPOSITORY=xosproject/ |
| 99 | export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION) |
Zack Williams | ae8b48b | 2019-04-16 15:00:37 -0700 | [diff] [blame] | 100 | export DOCKER_BUILD_ARGS=--no-cache |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 101 | |
Zack Williams | ae8b48b | 2019-04-16 15:00:37 -0700 | [diff] [blame] | 102 | cd $WORKSPACE/cord/orchestration/xos |
| 103 | make docker-build |
| 104 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 105 | cd $WORKSPACE/cord/orchestration/xos/testservice |
Zack Williams | ae8b48b | 2019-04-16 15:00:37 -0700 | [diff] [blame] | 106 | make docker-build |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 107 | """ |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | stage('Install XOS w/TestService') { |
| 112 | steps { |
| 113 | sh """ |
| 114 | #!/usr/bin/env bash |
| 115 | set -eu -o pipefail |
| 116 | |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 117 | export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION) |
| 118 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 119 | pushd cord/helm-charts |
| 120 | helm dep update xos-core |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 121 | helm install --set images.xos_core.tag=\$DOCKER_TAG,images.xos_core.pullPolicy=Never xos-core -n xos-core |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 122 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 123 | helm-repo-tools/wait_for_pods.sh |
| 124 | |
| 125 | #install testservice |
Kailash | fe84038 | 2019-03-26 21:11:09 -0700 | [diff] [blame] | 126 | cd $WORKSPACE/cord/orchestration/xos/testservice/helm-charts |
Scott Baker | 17a3cb5 | 2019-03-28 14:35:01 -0700 | [diff] [blame] | 127 | helm install --set testservice_synchronizerImage=xosproject/testservice-synchronizer:\$DOCKER_TAG \ |
| 128 | --set imagePullPolicy=Never \ |
| 129 | testservice -n testservice |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 130 | popd |
| 131 | """ |
| 132 | } |
| 133 | } |
| 134 | stage('Wait for Core') { |
| 135 | steps { |
| 136 | sh """ |
Kailash | fe84038 | 2019-03-26 21:11:09 -0700 | [diff] [blame] | 137 | #!/usr/bin/env bash |
| 138 | set -ex -o pipefail |
| 139 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 140 | #wait for xos-core and models to be loaded |
| 141 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/core/sites |jq '.items[0].name'|grep -q mysite; do echo 'Waiting for API To be up'; sleep 10; done" |
| 142 | """ |
| 143 | } |
| 144 | } |
| 145 | stage('Test Core') { |
| 146 | steps { |
| 147 | sh """ |
| 148 | #!/usr/bin/env bash |
Daniele Moro | 6b4d379 | 2020-04-15 17:53:45 +0200 | [diff] [blame] | 149 | set -ex -o pipefail |
Zack Williams | ae8b48b | 2019-04-16 15:00:37 -0700 | [diff] [blame] | 150 | |
Daniele Moro | 6b4d379 | 2020-04-15 17:53:45 +0200 | [diff] [blame] | 151 | pushd cord/test/cord-tester |
| 152 | make venv_cord |
| 153 | source venv_cord/bin/activate |
| 154 | cd src/test/cord-api/Tests/xos-test-service |
| 155 | |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 156 | robot -e notready test-service.robot || true |
| 157 | popd |
| 158 | """ |
| 159 | } |
| 160 | } |
Daniele Moro | dcf10ba | 2020-02-24 10:36:09 -0800 | [diff] [blame] | 161 | stage ('Archive Artifacts') { |
| 162 | when { expression { return params.ArchiveLogs } } |
| 163 | steps { |
| 164 | sh ''' |
| 165 | kubectl get pods --all-namespaces |
| 166 | ## get default pod logs |
| 167 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 168 | do |
| 169 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 170 | done |
| 171 | ''' |
| 172 | } |
| 173 | } |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 174 | } |
| 175 | post { |
| 176 | always { |
| 177 | sh """ |
| 178 | kubectl get pods --all-namespaces |
| 179 | |
| 180 | # copy robot logs |
| 181 | if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs |
Kailash | fe84038 | 2019-03-26 21:11:09 -0700 | [diff] [blame] | 182 | cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/xos-test-service/*ml ./RobotLogs |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 183 | echo "# removing helm deployments" |
| 184 | kubectl get pods |
| 185 | helm list |
| 186 | |
| 187 | for hchart in \$(helm list -q); |
| 188 | do |
| 189 | echo "## Purging chart: \${hchart} ##" |
| 190 | helm delete --purge "\${hchart}" |
| 191 | done |
| 192 | |
| 193 | sudo minikube delete |
| 194 | """ |
| 195 | step([$class: 'RobotPublisher', |
| 196 | disableArchiveOutput: false, |
| 197 | logFileName: 'RobotLogs/log*.html', |
| 198 | otherFiles: '', |
| 199 | outputFileName: 'RobotLogs/output*.xml', |
| 200 | outputPath: '.', |
| 201 | passThreshold: 100, |
| 202 | reportFileName: 'RobotLogs/report*.html', |
| 203 | unstableThreshold: 0]); |
Daniele Moro | dcf10ba | 2020-02-24 10:36:09 -0800 | [diff] [blame] | 204 | archiveArtifacts artifacts: '*.log' |
Joey Armstrong | ca4cb46 | 2023-01-12 17:51:05 -0500 | [diff] [blame] | 205 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "kailash@opennetworking.org, onf-bat-admin@opennetworking.org", sendToIndividuals: false]) |
Kailash | c8170bb | 2019-03-26 10:06:55 -0700 | [diff] [blame] | 206 | |
| 207 | } |
| 208 | } |
| 209 | } |