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 | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 26 | def test_workflow(name) { |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 27 | timeout(time: 10, unit: 'MINUTES') { |
| 28 | stage('Deploy - '+ name + ' workflow') { |
| 29 | def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 " |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 30 | |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 31 | if (gerritProject != "") { |
Matteo Scandolo | 9b644ba | 2021-04-19 11:21:07 -0700 | [diff] [blame] | 32 | extraHelmFlags = extraHelmFlags + getVolthaImageFlags("${gerritProject}") |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 33 | } |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 34 | |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 35 | def localCharts = false |
| 36 | if (gerritProject == "voltha-helm-charts") { |
| 37 | localCharts = true |
| 38 | } |
| 39 | |
Matteo Scandolo | 37f168b | 2021-04-15 16:20:46 -0700 | [diff] [blame] | 40 | volthaDeploy([ |
| 41 | workflow: name, |
| 42 | extraHelmFlags:extraHelmFlags, |
| 43 | localCharts: localCharts, |
| 44 | dockerRegistry: "mirror.registry.opennetworking.org" |
| 45 | ]) |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [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 | """ |
| 57 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [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 | |
Hardik Windlass | 6448613 | 2021-02-02 13:35:22 +0000 | [diff] [blame] | 77 | if [[ "${gerritProject}" == "bbsim" ]]; then |
| 78 | echo "Running BBSim specific Tests" |
| 79 | export TARGET=sanity-bbsim-${name} |
| 80 | fi |
| 81 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 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 |
| 101 | ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 |
| 102 | """ |
| 103 | // collect pod details |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 104 | getPodsInfo("$WORKSPACE/${name}") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 105 | helmTeardown(['infra', 'voltha']) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | pipeline { |
| 110 | |
| 111 | /* no label, executor is determined by JJB */ |
| 112 | agent { |
| 113 | label "${params.buildNode}" |
| 114 | } |
| 115 | options { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 116 | timeout(time: 35, unit: 'MINUTES') |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 117 | } |
| 118 | environment { |
| 119 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 120 | KUBECONFIG="$HOME/.kube/kind-config-${clusterName}" |
| 121 | } |
| 122 | |
| 123 | stages{ |
| 124 | stage('Download Code') { |
| 125 | steps { |
| 126 | getVolthaCode([ |
| 127 | branch: "${branch}", |
| 128 | gerritProject: "${gerritProject}", |
| 129 | gerritRefspec: "${gerritRefspec}", |
| 130 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 131 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 132 | ]) |
| 133 | } |
| 134 | } |
| 135 | stage('Build patch') { |
| 136 | steps { |
| 137 | // NOTE that the correct patch has already been checked out |
| 138 | // during the getVolthaCode step |
| 139 | buildVolthaComponent("${gerritProject}") |
| 140 | } |
| 141 | } |
| 142 | stage('Create K8s Cluster') { |
| 143 | steps { |
| 144 | createKubernetesCluster([nodes: 3]) |
| 145 | } |
| 146 | } |
| 147 | stage('Load image in kind nodes') { |
| 148 | steps { |
| 149 | loadToKind() |
| 150 | } |
| 151 | } |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 152 | stage('Replace voltctl') { |
| 153 | // if the project is voltctl override the downloaded one with the built one |
| 154 | when { |
| 155 | expression { |
| 156 | return gerritProject == "voltctl" |
| 157 | } |
| 158 | } |
| 159 | steps{ |
| 160 | sh """ |
| 161 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 162 | chmod +x $WORKSPACE/bin/voltctl |
| 163 | """ |
| 164 | } |
| 165 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 166 | stage('Run Test') { |
| 167 | steps { |
Matteo Scandolo | 5dcde38 | 2021-03-11 15:52:54 -0800 | [diff] [blame] | 168 | timeout(time: 30, unit: 'MINUTES') { |
| 169 | test_workflow("att") |
| 170 | test_workflow("dt") |
| 171 | test_workflow("tt") |
| 172 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | post { |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 178 | aborted { |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 179 | getPodsInfo("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 180 | sh """ |
Matteo Scandolo | 0da6053 | 2021-05-06 08:59:42 -0700 | [diff] [blame] | 181 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log || true |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 182 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 183 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 184 | } |
| 185 | failure { |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 186 | getPodsInfo("$WORKSPACE/failed") |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 187 | sh """ |
Matteo Scandolo | 0da6053 | 2021-05-06 08:59:42 -0700 | [diff] [blame] | 188 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.logs || true |
Matteo Scandolo | a599067 | 2021-03-15 10:41:06 -0700 | [diff] [blame] | 189 | """ |
Matteo Scandolo | 2411a3c | 2021-03-15 16:00:20 -0700 | [diff] [blame] | 190 | archiveArtifacts artifacts: '**/*.log,**/*.txt' |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 191 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 192 | always { |
| 193 | sh ''' |
| 194 | gzip $WORKSPACE/att/onos-voltha-combined.log || true |
| 195 | gzip $WORKSPACE/dt/onos-voltha-combined.log || true |
| 196 | gzip $WORKSPACE/tt/onos-voltha-combined.log || true |
| 197 | ''' |
| 198 | step([$class: 'RobotPublisher', |
| 199 | disableArchiveOutput: false, |
| 200 | logFileName: 'RobotLogs/*/log*.html', |
| 201 | otherFiles: '', |
| 202 | outputFileName: 'RobotLogs/*/output*.xml', |
| 203 | outputPath: '.', |
| 204 | passThreshold: 100, |
| 205 | reportFileName: 'RobotLogs/*/report*.html', |
| 206 | unstableThreshold: 0]); |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 207 | archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz,*.txt,**/*.txt' |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | } |