Hardik Windlass | 0f9621d | 2021-02-24 21:23:19 +0530 | [diff] [blame] | 1 | // Copyright 2021-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 | |
| 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 | |
| 26 | def test_software_upgrade(name) { |
| 27 | stage('Deploy Voltha - '+ name) { |
| 28 | def extraHelmFlags = "${extraHelmFlags} --set global.log_level=DEBUG,onu=1,pon=1 " |
| 29 | |
Hardik Windlass | a67cdbe | 2021-03-05 15:29:03 +0530 | [diff] [blame] | 30 | // TODO: ONOS custom image handling |
| 31 | // if [ '${onosImg.trim()}' != '' ] && [ '\$GERRIT_PROJECT' != 'voltha-onos' ]; then |
| 32 | // IFS=: read -r onosRepo onosTag <<< '${onosImg.trim()}' |
| 33 | // extraHelmFlags = extraHelmFlags + "--set onos-classic.images.onos.repository=\$onosRepo,onos-classic.images.onos.tag=\$onosTag " |
| 34 | // fi |
Hardik Windlass | 0f9621d | 2021-02-24 21:23:19 +0530 | [diff] [blame] | 35 | |
| 36 | def localCharts = false |
| 37 | if (gerritProject == "voltha-helm-charts") { |
| 38 | localCharts = true |
| 39 | } |
| 40 | |
| 41 | // Currently only testing with ATT workflow |
| 42 | // TODO: Support for other workflows |
| 43 | volthaDeploy([workflow: "att", extraHelmFlags: extraHelmFlags, localCharts: localCharts]) |
| 44 | // start logging |
| 45 | sh """ |
| 46 | mkdir -p $WORKSPACE/${name} |
| 47 | _TAG=kail-${name} kail -n infra -n voltha > $WORKSPACE/${name}/onos-voltha-combined.log & |
| 48 | """ |
| 49 | // forward ONOS and VOLTHA ports |
| 50 | sh """ |
| 51 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8101:8101& |
| 52 | _TAG=onos-port-forward kubectl port-forward --address 0.0.0.0 -n infra svc/voltha-infra-onos-classic-hs 8181:8181& |
| 53 | _TAG=voltha-port-forward kubectl port-forward --address 0.0.0.0 -n voltha svc/voltha-voltha-api 55555:55555& |
| 54 | """ |
| 55 | } |
| 56 | stage('Test - '+ name) { |
| 57 | sh """ |
| 58 | ROBOT_LOGS_DIR="$WORKSPACE/RobotLogs/${name}" |
| 59 | mkdir -p \$ROBOT_LOGS_DIR |
| 60 | |
| 61 | if ('${name}' == 'onos-app-upgrade') { |
| 62 | def onosAppsUnderTest = "" |
| 63 | |
| 64 | def testAaa = false |
| 65 | if ('${aaaVer.trim()}' != '' && '${aaaOarUrl.trim()}' != '') { |
| 66 | testAaa = true |
| 67 | onosAppsUnderTest = onosAppsUnderTest + "org.opencord.aaa," + ${aaaVer.trim()} + "," + ${aaaOarUrl.trim()} |
| 68 | } |
| 69 | |
| 70 | // TODO: Add other ONOS Apps |
| 71 | |
| 72 | export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v onos_apps_under_test:${onosAppsUnderTest} -e PowerSwitch" |
| 73 | |
| 74 | export TARGET=onos-app-upgrade-test |
| 75 | } else { |
| 76 | def volthaCompsUnderTest = "" |
| 77 | |
| 78 | def testAdapterOpenOlt = false |
| 79 | if ('${adapterOpenOltImage.trim()}' != '') { |
| 80 | testAdapterOpenOlt = true |
| 81 | volthaCompsUnderTest = volthaCompsUnderTest + "adapter-open-olt,adapter-open-olt," + ${adapterOpenOltImage.trim()} |
| 82 | } |
| 83 | |
| 84 | // TODO: Add other Voltha Components |
| 85 | |
| 86 | export ROBOT_MISC_ARGS="-d \$ROBOT_LOGS_DIR -v voltha_comps_under_test:${volthaCompsUnderTest} -e PowerSwitch" |
| 87 | |
| 88 | export TARGET=voltha-comp-upgrade-test |
| 89 | } |
| 90 | |
| 91 | export VOLTCONFIG=$HOME/.volt/config |
| 92 | export KUBECONFIG=$HOME/.kube/config |
| 93 | |
| 94 | # Run the specified tests |
| 95 | make -C $WORKSPACE/voltha-system-tests \$TARGET |
| 96 | |
| 97 | """ |
| 98 | // stop logging |
| 99 | sh """ |
| 100 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${name}" | grep -v grep | awk '{print \$1}')" |
| 101 | if [ -n "\$P_IDS" ]; then |
| 102 | echo \$P_IDS |
| 103 | for P_ID in \$P_IDS; do |
| 104 | kill -9 \$P_ID |
| 105 | done |
| 106 | fi |
| 107 | """ |
| 108 | // remove port-forwarding |
| 109 | sh """ |
| 110 | # remove orphaned port-forward from different namespaces |
| 111 | ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 |
| 112 | """ |
| 113 | // collect pod details |
| 114 | sh """ |
| 115 | kubectl get pods --all-namespaces -o wide > \$WORKSPACE/${name}/pods.txt || true |
| 116 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq | tee \$WORKSPACE/${name}/pod-images.txt || true |
| 117 | kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq | tee \$WORKSPACE/${name}/pod-imagesId.txt || true |
| 118 | """ |
| 119 | helmTeardown(['infra', 'voltha']) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | pipeline { |
| 124 | |
| 125 | /* no label, executor is determined by JJB */ |
| 126 | agent { |
| 127 | label "${params.buildNode}" |
| 128 | } |
| 129 | options { |
| 130 | timeout(time: 30, unit: 'MINUTES') |
| 131 | } |
| 132 | environment { |
| 133 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" |
| 134 | KUBECONFIG="$HOME/.kube/kind-config-${clusterName}" |
| 135 | } |
| 136 | |
| 137 | stages{ |
| 138 | stage('Download Code') { |
| 139 | steps { |
| 140 | getVolthaCode([ |
| 141 | branch: "${branch}", |
| 142 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 143 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 144 | ]) |
| 145 | } |
| 146 | } |
| 147 | stage('Create K8s Cluster') { |
| 148 | steps { |
| 149 | createKubernetesCluster([nodes: 3]) |
| 150 | } |
| 151 | } |
| 152 | stage('Run Test') { |
| 153 | steps { |
| 154 | test_software_upgrade("onos-app-upgrade") |
| 155 | test_software_upgrade("voltha-component-upgrade") |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | post { |
| 161 | always { |
| 162 | sh ''' |
| 163 | gzip $WORKSPACE/onos-app-upgrade/onos-voltha-combined.log || true |
| 164 | gzip $WORKSPACE/voltha-component-upgrade/onos-voltha-combined.log || true |
| 165 | ''' |
| 166 | step([$class: 'RobotPublisher', |
| 167 | disableArchiveOutput: false, |
| 168 | logFileName: 'RobotLogs/*/log*.html', |
| 169 | otherFiles: '', |
| 170 | outputFileName: 'RobotLogs/*/output*.xml', |
| 171 | outputPath: '.', |
| 172 | passThreshold: 100, |
| 173 | reportFileName: 'RobotLogs/*/report*.html', |
| 174 | unstableThreshold: 0]); |
| 175 | archiveArtifacts artifacts: '*.log,**/*.log,**/*.gz,*.gz' |
| 176 | } |
| 177 | } |
| 178 | } |