Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [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 | |
Matteo Scandolo | a156b57 | 2021-02-04 11:52:18 -0800 | [diff] [blame] | 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 | |
Matteo Scandolo | 85c26f8 | 2021-03-12 11:08:22 -0800 | [diff] [blame] | 26 | // TODO move this in a keyword so it can be shared across pipelines |
| 27 | def customImageFlags(project) { |
| 28 | def chart = "unknown" |
| 29 | def image = "unknown" |
| 30 | switch(project) { |
| 31 | case "ofagent-go": |
| 32 | chart = "voltha" |
| 33 | image = "ofagent" |
| 34 | break |
| 35 | case "voltha-go": |
| 36 | chart = "voltha" |
| 37 | image = "rw_core" |
| 38 | break |
| 39 | case "voltha-openonu-adapter-go": |
| 40 | chart = "voltha-adapter-openonu" |
| 41 | image = "adapter_open_onu_go" |
| 42 | break |
| 43 | // TODO remove after 2.7 |
| 44 | case "voltha-openonu-adapter": |
| 45 | chart = "voltha-adapter-openonu" |
| 46 | image = "adapter_open_onu" |
| 47 | break |
| 48 | // TODO end |
| 49 | case "voltha-openolt-adapter": |
| 50 | chart = "voltha-adapter-openolt" |
| 51 | image = "adapter_open_olt" |
| 52 | break |
| 53 | case "bbsim": |
| 54 | // BBSIM has a different format that voltha, return directly |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 55 | return "--set images.bbsim.tag=citest,images.bbsim.pullPolicy=Never,images.bbsim.registry='' " |
Matteo Scandolo | 85c26f8 | 2021-03-12 11:08:22 -0800 | [diff] [blame] | 56 | break |
| 57 | default: |
Matteo Scandolo | 85c26f8 | 2021-03-12 11:08:22 -0800 | [diff] [blame] | 58 | break |
| 59 | } |
| 60 | |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 61 | return "--set ${chart}.images.${image}.tag=citest,${chart}.images.${image}.pullPolicy=Never,${chart}.images.${image}.registry='' " |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | def test_workflow(name) { |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 65 | timeout(time: 10, unit: 'MINUTES') { |
| 66 | stage('Deploy - '+ name + ' workflow') { |
| 67 | def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 " |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 68 | |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 69 | if (gerritProject != "") { |
| 70 | extraHelmFlags = extraHelmFlags + customImageFlags("${gerritProject}") |
| 71 | } |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 72 | |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 73 | def localCharts = false |
| 74 | if (gerritProject == "voltha-helm-charts") { |
| 75 | localCharts = true |
| 76 | } |
| 77 | |
Matteo Scandolo | 37f168b | 2021-04-15 16:20:46 -0700 | [diff] [blame] | 78 | volthaDeploy([ |
| 79 | workflow: name, |
| 80 | extraHelmFlags:extraHelmFlags, |
| 81 | localCharts: localCharts, |
| 82 | dockerRegistry: "mirror.registry.opennetworking.org" |
| 83 | ]) |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 84 | // start logging |
| 85 | sh """ |
| 86 | mkdir -p $WORKSPACE/${name} |
| 87 | _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log & |
| 88 | """ |
| 89 | // forward ONOS and VOLTHA ports |
| 90 | sh """ |
| 91 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101& |
| 92 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181& |
| 93 | _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555& |
| 94 | """ |
| 95 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 96 | } |
| 97 | stage('Test VOLTHA - '+ name + ' workflow') { |
| 98 | sh """ |
| 99 | ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name.toUpperCase()}Workflow" |
| 100 | mkdir -p \$ROBOT_LOGS_DIR |
| 101 | export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -e PowerSwitch" |
| 102 | |
| 103 | # By default, all tests tagged 'sanity' are run. This covers basic functionality |
| 104 | # like running through the ATT workflow for a single subscriber. |
| 105 | export TARGET=sanity-kind-${name} |
| 106 | |
| 107 | # If the Gerrit comment contains a line with "functional tests" then run the full |
| 108 | # functional test suite. This covers tests tagged either 'sanity' or 'functional'. |
| 109 | # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line |
| 110 | REGEX="functional tests" |
| 111 | if [[ "\$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then |
| 112 | export TARGET=functional-single-kind-${name} |
| 113 | fi |
| 114 | |
Hardik Windlass | 6448613 | 2021-02-02 13:35:22 +0000 | [diff] [blame] | 115 | if [[ "${gerritProject}" == "bbsim" ]]; then |
| 116 | echo "Running BBSim specific Tests" |
| 117 | export TARGET=sanity-bbsim-${name} |
| 118 | fi |
| 119 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 120 | export VOLTCONFIG=$HOME/.volt/config |
| 121 | export KUBECONFIG=$HOME/.kube/config |
| 122 | |
| 123 | # Run the specified tests |
| 124 | make -C $WORKSPACE/voltha-system-tests \$TARGET || true |
| 125 | """ |
| 126 | // stop logging |
| 127 | sh """ |
| 128 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')" |
| 129 | if [ -n "\$P_IDS" ]; then |
| 130 | echo \$P_IDS |
| 131 | for P_ID in \$P_IDS; do |
| 132 | kill -9 \$P_ID |
| 133 | done |
| 134 | fi |
| 135 | """ |
| 136 | // remove port-forwarding |
| 137 | sh """ |
| 138 | # remove orphaned port-forward from different namespaces |
| 139 | ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 |
| 140 | """ |
| 141 | // collect pod details |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 142 | get_pods_info("$WORKSPACE/${name}") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 143 | helmTeardown(['infra', 'voltha']) |
| 144 | } |
| 145 | } |
| 146 | |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 147 | def get_pods_info(dest) { |
| 148 | // collect pod details, this is here in case of failure |
| 149 | sh """ |
| 150 | mkdir -p ${dest} |
Andrea Campanella | f2460e8fb | 2021-03-15 22:03:09 +0100 | [diff] [blame] | 151 | kubectl get pods --all-namespaces -o wide | tee ${dest}/pods.txt || true |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 152 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee ${dest}/pod-images.txt || true |
| 153 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee ${dest}/pod-imagesId.txt || true |
| 154 | kubectl describe pods --all-namespaces -l app.kubernetes.io/part-of=voltha > ${dest}/pods-describe.txt |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 155 | helm ls --all-namespaces | tee ${dest}/helm-charts.txt |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 156 | """ |
| 157 | } |
| 158 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 159 | pipeline { |
| 160 | |
| 161 | /* no label, executor is determined by JJB */ |
| 162 | agent { |
| 163 | label "${params.buildNode}" |
| 164 | } |
| 165 | options { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 166 | timeout(time: 35, unit: 'MINUTES') |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 167 | } |
| 168 | environment { |
| 169 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 170 | KUBECONFIG="$HOME/.kube/kind-config-${clusterName}" |
| 171 | } |
| 172 | |
| 173 | stages{ |
| 174 | stage('Download Code') { |
| 175 | steps { |
| 176 | getVolthaCode([ |
| 177 | branch: "${branch}", |
| 178 | gerritProject: "${gerritProject}", |
| 179 | gerritRefspec: "${gerritRefspec}", |
| 180 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 181 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 182 | ]) |
| 183 | } |
| 184 | } |
| 185 | stage('Build patch') { |
| 186 | steps { |
| 187 | // NOTE that the correct patch has already been checked out |
| 188 | // during the getVolthaCode step |
| 189 | buildVolthaComponent("${gerritProject}") |
| 190 | } |
| 191 | } |
| 192 | stage('Create K8s Cluster') { |
| 193 | steps { |
| 194 | createKubernetesCluster([nodes: 3]) |
| 195 | } |
| 196 | } |
| 197 | stage('Load image in kind nodes') { |
| 198 | steps { |
| 199 | loadToKind() |
| 200 | } |
| 201 | } |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 202 | stage('Replace voltctl') { |
| 203 | // if the project is voltctl override the downloaded one with the built one |
| 204 | when { |
| 205 | expression { |
| 206 | return gerritProject == "voltctl" |
| 207 | } |
| 208 | } |
| 209 | steps{ |
| 210 | sh """ |
| 211 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 212 | chmod +x $WORKSPACE/bin/voltctl |
| 213 | """ |
| 214 | } |
| 215 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 216 | stage('Run Test') { |
| 217 | steps { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 218 | timeout(time: 30, unit: 'MINUTES') { |
| 219 | test_workflow("att") |
| 220 | test_workflow("dt") |
| 221 | test_workflow("tt") |
| 222 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | post { |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 228 | aborted { |
| 229 | get_pods_info("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 230 | sh """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 231 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 232 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 233 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 234 | } |
| 235 | failure { |
| 236 | get_pods_info("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 237 | sh """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 238 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 239 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 240 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 241 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 242 | always { |
| 243 | sh ''' |
| 244 | gzip $WORKSPACE/att/onos-voltha-combined.log || true |
| 245 | gzip $WORKSPACE/dt/onos-voltha-combined.log || true |
| 246 | gzip $WORKSPACE/tt/onos-voltha-combined.log || true |
| 247 | ''' |
| 248 | step([$class: 'RobotPublisher', |
| 249 | disableArchiveOutput: false, |
| 250 | logFileName: 'RobotLogs/*/log*.html', |
| 251 | otherFiles: '', |
| 252 | outputFileName: 'RobotLogs/*/output*.xml', |
| 253 | outputPath: '.', |
| 254 | passThreshold: 100, |
| 255 | reportFileName: 'RobotLogs/*/report*.html', |
| 256 | unstableThreshold: 0]); |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 257 | archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt' |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | } |