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