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