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 | 5947099 | 2021-04-20 11:30:57 -0700 | [diff] [blame^] | 58 | return "" |
Matteo Scandolo | 85c26f8 | 2021-03-12 11:08:22 -0800 | [diff] [blame] | 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 | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 142 | getPodsInfo("$WORKSPACE/${name}") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 143 | helmTeardown(['infra', 'voltha']) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | pipeline { |
| 148 | |
| 149 | /* no label, executor is determined by JJB */ |
| 150 | agent { |
| 151 | label "${params.buildNode}" |
| 152 | } |
| 153 | options { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 154 | timeout(time: 35, unit: 'MINUTES') |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 155 | } |
| 156 | environment { |
| 157 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 158 | KUBECONFIG="$HOME/.kube/kind-config-${clusterName}" |
| 159 | } |
| 160 | |
| 161 | stages{ |
| 162 | stage('Download Code') { |
| 163 | steps { |
| 164 | getVolthaCode([ |
| 165 | branch: "${branch}", |
| 166 | gerritProject: "${gerritProject}", |
| 167 | gerritRefspec: "${gerritRefspec}", |
| 168 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 169 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 170 | ]) |
| 171 | } |
| 172 | } |
| 173 | stage('Build patch') { |
| 174 | steps { |
| 175 | // NOTE that the correct patch has already been checked out |
| 176 | // during the getVolthaCode step |
| 177 | buildVolthaComponent("${gerritProject}") |
| 178 | } |
| 179 | } |
| 180 | stage('Create K8s Cluster') { |
| 181 | steps { |
| 182 | createKubernetesCluster([nodes: 3]) |
| 183 | } |
| 184 | } |
| 185 | stage('Load image in kind nodes') { |
| 186 | steps { |
| 187 | loadToKind() |
| 188 | } |
| 189 | } |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 190 | stage('Replace voltctl') { |
| 191 | // if the project is voltctl override the downloaded one with the built one |
| 192 | when { |
| 193 | expression { |
| 194 | return gerritProject == "voltctl" |
| 195 | } |
| 196 | } |
| 197 | steps{ |
| 198 | sh """ |
| 199 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 200 | chmod +x $WORKSPACE/bin/voltctl |
| 201 | """ |
| 202 | } |
| 203 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 204 | stage('Run Test') { |
| 205 | steps { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 206 | timeout(time: 30, unit: 'MINUTES') { |
| 207 | test_workflow("att") |
| 208 | test_workflow("dt") |
| 209 | test_workflow("tt") |
| 210 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | post { |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 216 | aborted { |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 217 | getPodsInfo("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 218 | sh """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 219 | 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] | 220 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 221 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 222 | } |
| 223 | failure { |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 224 | getPodsInfo("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 225 | sh """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 226 | 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] | 227 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 228 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 229 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 230 | always { |
| 231 | sh ''' |
| 232 | gzip $WORKSPACE/att/onos-voltha-combined.log || true |
| 233 | gzip $WORKSPACE/dt/onos-voltha-combined.log || true |
| 234 | gzip $WORKSPACE/tt/onos-voltha-combined.log || true |
| 235 | ''' |
| 236 | step([$class: 'RobotPublisher', |
| 237 | disableArchiveOutput: false, |
| 238 | logFileName: 'RobotLogs/*/log*.html', |
| 239 | otherFiles: '', |
| 240 | outputFileName: 'RobotLogs/*/output*.xml', |
| 241 | outputPath: '.', |
| 242 | passThreshold: 100, |
| 243 | reportFileName: 'RobotLogs/*/report*.html', |
| 244 | unstableThreshold: 0]); |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 245 | archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt' |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |