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