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 |
| 67 | volthaDeploy([ |
| 68 | infraNamespace: infraNamespace, |
| 69 | volthaNamespace: volthaNamespace, |
| 70 | workflow: workflow.toLowerCase(), |
| 71 | extraHelmFlags: localHelmFlags, |
| 72 | localCharts: localCharts, |
| 73 | bbsimReplica: olts.toInteger(), |
| 74 | dockerRegistry: registry, |
| 75 | ]) |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 76 | } |
Matteo Scandolo | 0d04af8 | 2021-05-06 08:36:34 -0700 | [diff] [blame] | 77 | |
| 78 | // stop logging |
| 79 | sh """ |
| 80 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')" |
| 81 | if [ -n "\$P_IDS" ]; then |
| 82 | echo \$P_IDS |
| 83 | for P_ID in \$P_IDS; do |
| 84 | kill -9 \$P_ID |
| 85 | done |
| 86 | fi |
| 87 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 88 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 89 | sh """ |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 90 | 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"& |
| 91 | 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"& |
| 92 | 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"& |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 93 | ps aux | grep port-forward |
| 94 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') { |
Matteo Scandolo | 0d04af8 | 2021-05-06 08:36:34 -0700 | [diff] [blame] | 98 | // start logging |
| 99 | sh """ |
| 100 | mkdir -p $WORKSPACE/${testTarget}-components |
| 101 | _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log & |
| 102 | """ |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 103 | sh """ |
Matteo Scandolo | ee626e0 | 2021-05-05 08:13:16 -0700 | [diff] [blame] | 104 | mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot |
| 105 | export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot " |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 106 | 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] | 107 | export KVSTOREPREFIX=voltha/voltha_voltha |
| 108 | |
| 109 | make -C $WORKSPACE/voltha-system-tests ${testTarget} || true |
| 110 | """ |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 111 | // stop logging |
| 112 | sh """ |
| 113 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')" |
| 114 | if [ -n "\$P_IDS" ]; then |
| 115 | echo \$P_IDS |
| 116 | for P_ID in \$P_IDS; do |
| 117 | kill -9 \$P_ID |
| 118 | done |
| 119 | fi |
| 120 | """ |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 121 | getPodsInfo("$WORKSPACE/${testTarget}-components") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 125 | def collectArtifacts(exitStatus) { |
| 126 | getPodsInfo("$WORKSPACE/${exitStatus}") |
| 127 | sh """ |
Matteo Scandolo | 0da6053 | 2021-05-06 08:59:42 -0700 | [diff] [blame] | 128 | 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] | 129 | """ |
| 130 | archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html' |
| 131 | sh ''' |
| 132 | sync |
| 133 | pkill kail || true |
| 134 | which voltctl |
| 135 | md5sum $(which voltctl) |
| 136 | ''' |
| 137 | step([$class: 'RobotPublisher', |
| 138 | disableArchiveOutput: false, |
| 139 | logFileName: "RobotLogs/*/log*.html", |
| 140 | otherFiles: '', |
| 141 | outputFileName: "RobotLogs/*/output*.xml", |
| 142 | outputPath: '.', |
| 143 | passThreshold: 100, |
| 144 | reportFileName: "RobotLogs/*/report*.html", |
| 145 | unstableThreshold: 0]); |
| 146 | } |
| 147 | |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 148 | pipeline { |
| 149 | |
| 150 | /* no label, executor is determined by JJB */ |
| 151 | agent { |
| 152 | label "${params.buildNode}" |
| 153 | } |
| 154 | options { |
| 155 | timeout(time: 130, unit: 'MINUTES') |
| 156 | } |
| 157 | environment { |
| 158 | KUBECONFIG="$HOME/.kube/kind-${clusterName}" |
| 159 | VOLTCONFIG="$HOME/.volt/config" |
| 160 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" |
| 161 | ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}" |
| 162 | DIAGS_PROFILE="VOLTHA_PROFILE" |
| 163 | } |
| 164 | stages { |
| 165 | stage('Download Code') { |
| 166 | steps { |
| 167 | getVolthaCode([ |
| 168 | branch: "${branch}", |
| 169 | gerritProject: "${gerritProject}", |
| 170 | gerritRefspec: "${gerritRefspec}", |
| 171 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 172 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 173 | ]) |
| 174 | } |
| 175 | } |
| 176 | stage('Create K8s Cluster') { |
| 177 | steps { |
| 178 | script { |
| 179 | def clusterExists = sh returnStdout: true, script: """ |
| 180 | kind get clusters | grep ${clusterName} | wc -l |
| 181 | """ |
| 182 | if (clusterExists.trim() == "0") { |
| 183 | createKubernetesCluster([nodes: 3, name: clusterName]) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 188 | stage('Parse and execute tests') { |
| 189 | steps { |
| 190 | script { |
| 191 | def tests = readYaml text: testTargets |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 192 | |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 193 | for(int i = 0;i<tests.size();i++) { |
| 194 | def test = tests[i] |
| 195 | def target = test["target"] |
| 196 | def workflow = test["workflow"] |
| 197 | def flags = test["flags"] |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 198 | def teardown = test["teardown"].toBoolean() |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 199 | println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}" |
Matteo Scandolo | a57b097 | 2021-05-03 14:04:58 -0700 | [diff] [blame] | 200 | execute_test(target, workflow, teardown, flags) |
Matteo Scandolo | 886cb8e | 2021-05-03 13:37:41 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 203 | } |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | post { |
| 207 | aborted { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 208 | collectArtifacts("aborted") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 209 | } |
| 210 | failure { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 211 | collectArtifacts("failed") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 212 | } |
| 213 | always { |
Matteo Scandolo | 2cc5b39 | 2021-05-03 09:33:18 -0700 | [diff] [blame] | 214 | collectArtifacts("always") |
Matteo Scandolo | 075740f | 2021-04-22 14:52:29 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |