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