Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [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 for openonu-go |
| 16 | // uses bbsim to simulate OLT/ONUs |
| 17 | |
| 18 | library identifier: 'cord-jenkins-libraries@master', |
| 19 | retriever: modernSCM([ |
| 20 | $class: 'GitSCMSource', |
| 21 | remote: 'https://gerrit.opencord.org/ci-management.git' |
| 22 | ]) |
| 23 | |
| 24 | def clusterName = "kind-ci" |
| 25 | |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 26 | def execute_test(testTarget, workflow, teardown, testSpecificHelmFlags = "") { |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 27 | def infraNamespace = "default" |
| 28 | def volthaNamespace = "voltha" |
| 29 | def robotLogsDir = "RobotLogs" |
| 30 | stage('Cleanup') { |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 31 | if (teardown) { |
| 32 | timeout(15) { |
| 33 | script { |
| 34 | helmTeardown(["default", infraNamespace, volthaNamespace]) |
| 35 | } |
| 36 | timeout(1) { |
| 37 | sh returnStdout: false, script: ''' |
| 38 | # remove orphaned port-forward from different namespaces |
Andrea Campanella | 4c8af94 | 2021-05-12 10:12:13 +0200 | [diff] [blame] | 39 | ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 40 | ''' |
| 41 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 42 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | stage('Deploy Voltha') { |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 46 | if (teardown) { |
| 47 | timeout(20) { |
| 48 | script { |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 49 | |
Matteo Scandolo | 0d04af8 | 2021-05-06 08:36:34 -0700 | [diff] [blame] | 50 | sh """ |
| 51 | mkdir -p $WORKSPACE/${testTarget}-components |
| 52 | _TAG=kail-startup kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-startup-combined.log & |
| 53 | """ |
| 54 | |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 55 | // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts |
| 56 | def localCharts = false |
| 57 | if (volthaHelmChartsChange != "") { |
| 58 | localCharts = true |
| 59 | } |
| 60 | |
| 61 | // NOTE temporary workaround expose ONOS node ports |
Hardik Windlass | 696002d | 2021-05-07 11:38:28 +0000 | [diff] [blame] | 62 | def localHelmFlags = extraHelmFlags + " --set global.log_level=${logLevel.toUpperCase()} " + |
| 63 | " --set onos-classic.onosSshPort=30115 " + |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 64 | " --set onos-classic.onosApiPort=30120 " + |
| 65 | " --set onos-classic.onosOfPort=31653 " + |
| 66 | " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags |
Matteo Scandolo | 7ebfdfc | 2021-05-07 10:15:51 -0700 | [diff] [blame] | 67 | |
| 68 | if (gerritProject != "") { |
| 69 | localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}") |
| 70 | } |
| 71 | |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 72 | volthaDeploy([ |
| 73 | infraNamespace: infraNamespace, |
| 74 | volthaNamespace: volthaNamespace, |
| 75 | workflow: workflow.toLowerCase(), |
| 76 | extraHelmFlags: localHelmFlags, |
| 77 | localCharts: localCharts, |
| 78 | bbsimReplica: olts.toInteger(), |
| 79 | dockerRegistry: registry, |
| 80 | ]) |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 81 | } |
Matteo Scandolo | 0d04af8 | 2021-05-06 08:36:34 -0700 | [diff] [blame] | 82 | |
| 83 | // stop logging |
| 84 | sh """ |
| 85 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')" |
| 86 | if [ -n "\$P_IDS" ]; then |
| 87 | echo \$P_IDS |
| 88 | for P_ID in \$P_IDS; do |
| 89 | kill -9 \$P_ID |
| 90 | done |
| 91 | fi |
| 92 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 93 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 94 | sh """ |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 95 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"& |
| 96 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-etcd" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd 2379:2379; done"& |
| 97 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-kafka" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"& |
Hardik Windlass | 26742bb | 2021-05-10 09:29:32 +0000 | [diff] [blame] | 98 | bbsimDmiPortFwd=50075 |
| 99 | for i in {0..${olts.toInteger() - 1}}; do |
| 100 | JENKINS_NODE_COOKIE="dontKillMe" _TAG="bbsim\${i}" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/bbsim\${i} 50075:\${bbsimDmiPortFwd}; done"& |
| 101 | ((bbsimDmiPortFwd++)) |
| 102 | done |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 103 | ps aux | grep port-forward |
| 104 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') { |
Matteo Scandolo | 0d04af8 | 2021-05-06 08:36:34 -0700 | [diff] [blame] | 108 | // start logging |
| 109 | sh """ |
| 110 | mkdir -p $WORKSPACE/${testTarget}-components |
| 111 | _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log & |
| 112 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 113 | sh """ |
Matteo Scandolo | ee626e0 | 2021-05-05 08:13:16 -0700 | [diff] [blame] | 114 | mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot |
| 115 | export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot " |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 116 | ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace}" |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 117 | export KVSTOREPREFIX=voltha/voltha_voltha |
| 118 | |
| 119 | make -C $WORKSPACE/voltha-system-tests ${testTarget} || true |
| 120 | """ |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 121 | // stop logging |
| 122 | sh """ |
| 123 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')" |
| 124 | if [ -n "\$P_IDS" ]; then |
| 125 | echo \$P_IDS |
| 126 | for P_ID in \$P_IDS; do |
| 127 | kill -9 \$P_ID |
| 128 | done |
| 129 | fi |
| 130 | """ |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 131 | getPodsInfo("$WORKSPACE/${testTarget}-components") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 135 | def collectArtifacts(exitStatus) { |
| 136 | getPodsInfo("$WORKSPACE/${exitStatus}") |
| 137 | sh """ |
Matteo Scandolo | 0da6053 | 2021-05-06 08:59:42 -0700 | [diff] [blame] | 138 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 139 | """ |
| 140 | archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html' |
| 141 | sh ''' |
| 142 | sync |
| 143 | pkill kail || true |
| 144 | which voltctl |
| 145 | md5sum $(which voltctl) |
| 146 | ''' |
| 147 | step([$class: 'RobotPublisher', |
| 148 | disableArchiveOutput: false, |
| 149 | logFileName: "RobotLogs/*/log*.html", |
| 150 | otherFiles: '', |
| 151 | outputFileName: "RobotLogs/*/output*.xml", |
| 152 | outputPath: '.', |
| 153 | passThreshold: 100, |
| 154 | reportFileName: "RobotLogs/*/report*.html", |
| 155 | unstableThreshold: 0]); |
| 156 | } |
| 157 | |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 158 | pipeline { |
| 159 | |
| 160 | /* no label, executor is determined by JJB */ |
| 161 | agent { |
| 162 | label "${params.buildNode}" |
| 163 | } |
| 164 | options { |
TorstenThieme | 869ba32 | 2021-05-05 12:11:42 +0000 | [diff] [blame] | 165 | timeout(time: "${timeout}", unit: 'MINUTES') |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 166 | } |
| 167 | environment { |
| 168 | KUBECONFIG="$HOME/.kube/kind-${clusterName}" |
| 169 | VOLTCONFIG="$HOME/.volt/config" |
| 170 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" |
| 171 | ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}" |
| 172 | DIAGS_PROFILE="VOLTHA_PROFILE" |
| 173 | } |
| 174 | stages { |
| 175 | stage('Download Code') { |
| 176 | steps { |
| 177 | getVolthaCode([ |
| 178 | branch: "${branch}", |
| 179 | gerritProject: "${gerritProject}", |
| 180 | gerritRefspec: "${gerritRefspec}", |
| 181 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 182 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 183 | ]) |
| 184 | } |
| 185 | } |
Matteo Scandolo | 7ebfdfc | 2021-05-07 10:15:51 -0700 | [diff] [blame] | 186 | stage('Build patch') { |
| 187 | // build the patch only if gerritProject is specified |
| 188 | when { |
| 189 | expression { |
| 190 | return !gerritProject.isEmpty() |
| 191 | } |
| 192 | } |
| 193 | steps { |
| 194 | // NOTE that the correct patch has already been checked out |
| 195 | // during the getVolthaCode step |
| 196 | buildVolthaComponent("${gerritProject}") |
| 197 | } |
| 198 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 199 | stage('Create K8s Cluster') { |
| 200 | steps { |
| 201 | script { |
| 202 | def clusterExists = sh returnStdout: true, script: """ |
| 203 | kind get clusters | grep ${clusterName} | wc -l |
| 204 | """ |
| 205 | if (clusterExists.trim() == "0") { |
| 206 | createKubernetesCluster([nodes: 3, name: clusterName]) |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
Matteo Scandolo | 7ebfdfc | 2021-05-07 10:15:51 -0700 | [diff] [blame] | 211 | stage('Load image in kind nodes') { |
| 212 | when { |
| 213 | expression { |
| 214 | return !gerritProject.isEmpty() |
| 215 | } |
| 216 | } |
| 217 | steps { |
| 218 | loadToKind() |
| 219 | } |
| 220 | } |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 221 | stage('Parse and execute tests') { |
| 222 | steps { |
| 223 | script { |
| 224 | def tests = readYaml text: testTargets |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 225 | |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 226 | for(int i = 0;i<tests.size();i++) { |
| 227 | def test = tests[i] |
| 228 | def target = test["target"] |
| 229 | def workflow = test["workflow"] |
| 230 | def flags = test["flags"] |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 231 | def teardown = test["teardown"].toBoolean() |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 232 | println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}" |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 233 | execute_test(target, workflow, teardown, flags) |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 236 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | post { |
| 240 | aborted { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 241 | collectArtifacts("aborted") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 242 | } |
| 243 | failure { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 244 | collectArtifacts("failed") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 245 | } |
| 246 | always { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 247 | collectArtifacts("always") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | } |