Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [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 | // voltha-2.x e2e tests |
| 16 | // uses bbsim to simulate OLT/ONUs |
| 17 | |
| 18 | // NOTE we are importing the library even if it's global so that it's |
| 19 | // easier to change the keywords during a replay |
| 20 | library identifier: 'cord-jenkins-libraries@master', |
| 21 | retriever: modernSCM([ |
| 22 | $class: 'GitSCMSource', |
| 23 | remote: 'https://gerrit.opencord.org/ci-management.git' |
| 24 | ]) |
| 25 | |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 26 | def test_workflow(name) { |
Matteo Scandolo | e72a493 | 2021-05-19 18:52:08 -0700 | [diff] [blame] | 27 | timeout(time: 10, unit: 'MINUTES') { |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 28 | stage('Deploy - '+ name + ' workflow') { |
| 29 | def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 " |
| 30 | |
| 31 | if (gerritProject != "") { |
Matteo Scandolo | e72a493 | 2021-05-19 18:52:08 -0700 | [diff] [blame] | 32 | extraHelmFlags = extraHelmFlags + getVolthaImageFlags("${gerritProject}") |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | def localCharts = false |
Matteo Scandolo | fe9e87d | 2021-05-19 15:55:16 -0700 | [diff] [blame] | 36 | if (gerritProject == "voltha-helm-charts" || branch != "master") { |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 37 | localCharts = true |
| 38 | } |
| 39 | |
Matteo Scandolo | fe9e87d | 2021-05-19 15:55:16 -0700 | [diff] [blame] | 40 | volthaDeploy([ |
| 41 | workflow: name, |
| 42 | extraHelmFlags: extraHelmFlags, |
| 43 | localCharts: localCharts, |
| 44 | dockerRegistry: "mirror.registry.opennetworking.org" |
| 45 | ]) |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 46 | // start logging |
| 47 | sh """ |
| 48 | mkdir -p $WORKSPACE/${name} |
| 49 | _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log & |
| 50 | """ |
| 51 | // forward ONOS and VOLTHA ports |
| 52 | sh """ |
| 53 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101& |
| 54 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181& |
| 55 | _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555& |
| 56 | """ |
Matteo Scandolo | e72a493 | 2021-05-19 18:52:08 -0700 | [diff] [blame] | 57 | } |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 58 | } |
| 59 | stage('Test VOLTHA - '+ name + ' workflow') { |
| 60 | sh """ |
| 61 | ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow" |
| 62 | mkdir -p \$ROBOT_LOGS_DIR |
| 63 | export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch" |
| 64 | |
| 65 | # By default, all tests tagged 'sanity' are run. This covers basic functionality |
| 66 | # like running through the ATT workflow for a single subscriber. |
| 67 | export TARGET=sanity-kind-${name} |
| 68 | |
| 69 | # If the Gerrit comment contains a line with "functional tests" then run the full |
| 70 | # functional test suite. This covers tests tagged either 'sanity' or 'functional'. |
| 71 | # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line |
| 72 | REGEX="functional tests" |
| 73 | if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then |
| 74 | export TARGET=functional-single-kind-${name} |
| 75 | fi |
| 76 | |
| 77 | if [[ "${gerritProject}" == "bbsim" ]]; then |
| 78 | echo "Running BBSim specific Tests" |
| 79 | export TARGET=sanity-bbsim-${name} |
| 80 | fi |
| 81 | |
| 82 | export VOLTCONFIG=$HOME/.volt/config |
| 83 | export KUBECONFIG=$HOME/.kube/config |
| 84 | |
| 85 | # Run the specified tests |
| 86 | make -C $WORKSPACE/voltha-system-tests \$TARGET || true |
| 87 | """ |
| 88 | // stop logging |
| 89 | sh """ |
| 90 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')" |
| 91 | if [ -n "\$P_IDS" ]; then |
| 92 | echo \$P_IDS |
| 93 | for P_ID in \$P_IDS; do |
| 94 | kill -9 \$P_ID |
| 95 | done |
| 96 | fi |
| 97 | """ |
| 98 | // remove port-forwarding |
| 99 | sh """ |
| 100 | # remove orphaned port-forward from different namespaces |
Andrea Campanella | 4c8af94 | 2021-05-12 10:12:13 +0200 | [diff] [blame] | 101 | ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true |
Andrea Campanella | db8eac2 | 2021-03-30 14:27:16 +0200 | [diff] [blame] | 102 | """ |
| 103 | // collect pod details |
| 104 | get_pods_info("$WORKSPACE/${name}") |
| 105 | helmTeardown(['infra', 'voltha']) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | def get_pods_info(dest) { |
| 110 | // collect pod details, this is here in case of failure |
| 111 | sh """ |
| 112 | mkdir -p ${dest} |
| 113 | kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true |
| 114 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true |
| 115 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true |
| 116 | kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt |
| 117 | helm ls --all-namespaces | tee ${dest}/helm-charts.txt |
| 118 | """ |
| 119 | } |
| 120 | |
| 121 | pipeline { |
| 122 | |
| 123 | /* no label, executor is determined by JJB */ |
| 124 | agent { |
| 125 | label "${params.buildNode}" |
| 126 | } |
| 127 | options { |
| 128 | timeout(time: 35, unit: 'MINUTES') |
| 129 | } |
| 130 | environment { |
| 131 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 132 | KUBECONFIG="$HOME/.kube/kind-config-${clusterName}" |
| 133 | } |
| 134 | |
| 135 | stages{ |
| 136 | stage('Download Code') { |
| 137 | steps { |
| 138 | getVolthaCode([ |
| 139 | branch: "${branch}", |
| 140 | gerritProject: "${gerritProject}", |
| 141 | gerritRefspec: "${gerritRefspec}", |
| 142 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 143 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 144 | ]) |
| 145 | } |
| 146 | } |
| 147 | stage('Build patch') { |
| 148 | steps { |
| 149 | // NOTE that the correct patch has already been checked out |
| 150 | // during the getVolthaCode step |
| 151 | buildVolthaComponent("${gerritProject}") |
| 152 | } |
| 153 | } |
| 154 | stage('Create K8s Cluster') { |
| 155 | steps { |
| 156 | createKubernetesCluster([nodes: 3]) |
| 157 | } |
| 158 | } |
| 159 | stage('Load image in kind nodes') { |
| 160 | steps { |
| 161 | loadToKind() |
| 162 | } |
| 163 | } |
| 164 | stage('Replace voltctl') { |
| 165 | // if the project is voltctl override the downloaded one with the built one |
| 166 | when { |
| 167 | expression { |
| 168 | return gerritProject == "voltctl" |
| 169 | } |
| 170 | } |
| 171 | steps{ |
| 172 | sh """ |
| 173 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 174 | chmod +x $WORKSPACE/bin/voltctl |
| 175 | """ |
| 176 | } |
| 177 | } |
| 178 | stage('Run Test') { |
| 179 | steps { |
| 180 | timeout(time: 30, unit: 'MINUTES') { |
| 181 | test_workflow("att") |
| 182 | test_workflow("dt") |
| 183 | test_workflow("tt") |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | post { |
| 190 | aborted { |
| 191 | get_pods_info("$WORKSPACE/failed") |
| 192 | sh """ |
| 193 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log |
| 194 | """ |
| 195 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
| 196 | } |
| 197 | failure { |
| 198 | get_pods_info("$WORKSPACE/failed") |
| 199 | sh """ |
| 200 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs |
| 201 | """ |
| 202 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
| 203 | } |
| 204 | always { |
| 205 | sh ''' |
| 206 | gzip $WORKSPACE/att/onos-voltha-combined.log || true |
| 207 | gzip $WORKSPACE/dt/onos-voltha-combined.log || true |
| 208 | gzip $WORKSPACE/tt/onos-voltha-combined.log || true |
| 209 | ''' |
| 210 | step([$class: 'RobotPublisher', |
| 211 | disableArchiveOutput: false, |
| 212 | logFileName: 'RobotLogs/*/log*.html', |
| 213 | otherFiles: '', |
| 214 | outputFileName: 'RobotLogs/*/output*.xml', |
| 215 | outputPath: '.', |
| 216 | passThreshold: 100, |
| 217 | reportFileName: 'RobotLogs/*/report*.html', |
| 218 | unstableThreshold: 0]); |
| 219 | archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt' |
| 220 | } |
| 221 | } |
| 222 | } |