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