Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 1 | // Copyright 2021-present Open Networking Foundation |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 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 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 15 | // voltha-2.x e2e tests for openonu-go |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 16 | // uses bbsim to simulate OLT/ONUs |
| 17 | |
Matteo Scandolo | a156b57 | 2021-02-04 11:52:18 -0800 | [diff] [blame] | 18 | library identifier: 'cord-jenkins-libraries@master', |
| 19 | retriever: modernSCM([ |
| 20 | $class: 'GitSCMSource', |
| 21 | remote: 'https://gerrit.opencord.org/ci-management.git' |
| 22 | ]) |
| 23 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 24 | def clusterName = "kind-ci" |
| 25 | |
| 26 | def execute_test(testTarget, workflow, teardown, testSpecificHelmFlags = "") { |
| 27 | def infraNamespace = "default" |
| 28 | def volthaNamespace = "voltha" |
| 29 | def robotLogsDir = "RobotLogs" |
| 30 | stage('Cleanup') { |
| 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 |
| 39 | ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true |
| 40 | ''' |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | stage('Deploy Voltha') { |
| 46 | if (teardown) { |
| 47 | timeout(20) { |
| 48 | script { |
| 49 | |
| 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 | |
| 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 |
| 62 | def localHelmFlags = extraHelmFlags + " --set global.log_level=${logLevel.toUpperCase()} " + |
Matteo Scandolo | 9114c89 | 2021-05-20 11:41:55 -0700 | [diff] [blame] | 63 | " --set onos-classic.onosSshPort=30115 " + |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 64 | " --set onos-classic.onosApiPort=30120 " + |
| 65 | " --set onos-classic.onosOfPort=31653 " + |
| 66 | " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 67 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 68 | if (gerritProject != "") { |
| 69 | localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}") |
| 70 | } |
| 71 | |
| 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 | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 81 | } |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 82 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 83 | // stop logging |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 84 | sh """ |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 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 | cd $WORKSPACE/${testTarget}-components/ |
| 93 | gzip -k onos-voltha-startup-combined.log |
| 94 | rm onos-voltha-startup-combined.log |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 95 | """ |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 96 | } |
| 97 | sh """ |
| 98 | 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"& |
| 99 | 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"& |
| 100 | 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"& |
| 101 | bbsimDmiPortFwd=50075 |
| 102 | for i in {0..${olts.toInteger() - 1}}; do |
| 103 | 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} \${bbsimDmiPortFwd}:50075; done"& |
| 104 | ((bbsimDmiPortFwd++)) |
| 105 | done |
| 106 | ps aux | grep port-forward |
| 107 | """ |
Matteo Scandolo | d17de3a | 2021-04-09 15:47:52 -0700 | [diff] [blame] | 108 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 109 | } |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 110 | stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') { |
| 111 | // start logging |
| 112 | sh """ |
| 113 | mkdir -p $WORKSPACE/${testTarget}-components |
| 114 | _TAG=kail-${workflow} kail -n infra -n voltha > $WORKSPACE/${testTarget}-components/onos-voltha-combined.log & |
| 115 | """ |
| 116 | sh """ |
| 117 | mkdir -p $WORKSPACE/${robotLogsDir}/${testTarget}-robot |
| 118 | export ROBOT_MISC_ARGS="-d $WORKSPACE/${robotLogsDir}/${testTarget}-robot " |
| 119 | ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace}" |
| 120 | export KVSTOREPREFIX=voltha/voltha_voltha |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 121 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 122 | make -C $WORKSPACE/voltha-system-tests ${testTarget} || true |
| 123 | """ |
| 124 | // stop logging |
| 125 | sh """ |
| 126 | P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')" |
| 127 | if [ -n "\$P_IDS" ]; then |
| 128 | echo \$P_IDS |
| 129 | for P_ID in \$P_IDS; do |
| 130 | kill -9 \$P_ID |
| 131 | done |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 132 | fi |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 133 | cd $WORKSPACE/${testTarget}-components/ |
| 134 | gzip -k onos-voltha-combined.log |
| 135 | rm onos-voltha-combined.log |
| 136 | """ |
| 137 | getPodsInfo("$WORKSPACE/${testTarget}-components") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 141 | def collectArtifacts(exitStatus) { |
| 142 | getPodsInfo("$WORKSPACE/${exitStatus}") |
| 143 | sh """ |
| 144 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true |
| 145 | """ |
| 146 | archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html' |
| 147 | sh ''' |
| 148 | sync |
| 149 | pkill kail || true |
| 150 | which voltctl |
| 151 | md5sum $(which voltctl) |
| 152 | ''' |
| 153 | step([$class: 'RobotPublisher', |
| 154 | disableArchiveOutput: false, |
| 155 | logFileName: "RobotLogs/*/log*.html", |
| 156 | otherFiles: '', |
| 157 | outputFileName: "RobotLogs/*/output*.xml", |
| 158 | outputPath: '.', |
| 159 | passThreshold: 100, |
| 160 | reportFileName: "RobotLogs/*/report*.html", |
| 161 | unstableThreshold: 0]); |
| 162 | } |
| 163 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 164 | pipeline { |
| 165 | |
| 166 | /* no label, executor is determined by JJB */ |
| 167 | agent { |
| 168 | label "${params.buildNode}" |
| 169 | } |
| 170 | options { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 171 | timeout(time: "${timeout}", unit: 'MINUTES') |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 172 | } |
| 173 | environment { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 174 | KUBECONFIG="$HOME/.kube/kind-${clusterName}" |
| 175 | VOLTCONFIG="$HOME/.volt/config" |
| 176 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" |
| 177 | ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}" |
| 178 | DIAGS_PROFILE="VOLTHA_PROFILE" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 179 | } |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 180 | stages { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 181 | stage('Download Code') { |
| 182 | steps { |
| 183 | getVolthaCode([ |
| 184 | branch: "${branch}", |
| 185 | gerritProject: "${gerritProject}", |
| 186 | gerritRefspec: "${gerritRefspec}", |
| 187 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 188 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 189 | ]) |
| 190 | } |
| 191 | } |
| 192 | stage('Build patch') { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 193 | // build the patch only if gerritProject is specified |
| 194 | when { |
| 195 | expression { |
| 196 | return !gerritProject.isEmpty() |
| 197 | } |
| 198 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 199 | steps { |
| 200 | // NOTE that the correct patch has already been checked out |
| 201 | // during the getVolthaCode step |
| 202 | buildVolthaComponent("${gerritProject}") |
| 203 | } |
| 204 | } |
| 205 | stage('Create K8s Cluster') { |
| 206 | steps { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 207 | script { |
| 208 | def clusterExists = sh returnStdout: true, script: """ |
| 209 | kind get clusters | grep ${clusterName} | wc -l |
| 210 | """ |
| 211 | if (clusterExists.trim() == "0") { |
| 212 | createKubernetesCluster([nodes: 3, name: clusterName]) |
| 213 | } |
| 214 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 215 | } |
| 216 | } |
Hardik Windlass | c6ba23e | 2021-06-08 08:19:52 +0000 | [diff] [blame] | 217 | stage('Replace voltctl') { |
| 218 | // if the project is voltctl override the downloaded one with the built one |
| 219 | when { |
| 220 | expression { |
| 221 | return gerritProject == "voltctl" |
| 222 | } |
| 223 | } |
| 224 | steps{ |
| 225 | sh """ |
| 226 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 227 | chmod +x $WORKSPACE/bin/voltctl |
| 228 | """ |
| 229 | } |
| 230 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 231 | stage('Load image in kind nodes') { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 232 | when { |
| 233 | expression { |
| 234 | return !gerritProject.isEmpty() |
| 235 | } |
| 236 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 237 | steps { |
| 238 | loadToKind() |
| 239 | } |
| 240 | } |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 241 | stage('Parse and execute tests') { |
| 242 | steps { |
| 243 | script { |
| 244 | def tests = readYaml text: testTargets |
| 245 | |
| 246 | for(int i = 0;i<tests.size();i++) { |
| 247 | def test = tests[i] |
| 248 | def target = test["target"] |
| 249 | def workflow = test["workflow"] |
| 250 | def flags = test["flags"] |
| 251 | def teardown = test["teardown"].toBoolean() |
| 252 | println "Executing test ${target} on workflow ${workflow} with extra flags ${flags}" |
| 253 | execute_test(target, workflow, teardown, flags) |
| 254 | } |
| 255 | } |
Matteo Scandolo | 29597f0 | 2021-02-12 10:53:57 -0800 | [diff] [blame] | 256 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 259 | post { |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 260 | aborted { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 261 | collectArtifacts("aborted") |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 262 | } |
| 263 | failure { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 264 | collectArtifacts("failed") |
Matteo Scandolo | e543c4c | 2021-03-09 07:34:29 -0800 | [diff] [blame] | 265 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 266 | always { |
Hardik Windlass | ec9341b | 2021-06-07 11:58:29 +0000 | [diff] [blame] | 267 | collectArtifacts("always") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |