Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [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 | |
Hardik Windlass | 60fc0da | 2021-10-14 07:02:40 +0000 | [diff] [blame] | 26 | def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "") { |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 27 | def infraNamespace = "default" |
| 28 | def volthaNamespace = "voltha" |
Matteo Scandolo | 9c230bb | 2021-10-22 12:48:39 -0700 | [diff] [blame] | 29 | def logsDir = "$WORKSPACE/${testTarget}" |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 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(10) { |
| 48 | script { |
| 49 | |
| 50 | sh """ |
Matteo Scandolo | 9c230bb | 2021-10-22 12:48:39 -0700 | [diff] [blame] | 51 | mkdir -p ${logsDir} |
| 52 | _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log & |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 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 (gerritProject == "voltha-helm-charts" || branch != "master") { |
| 58 | localCharts = true |
| 59 | } |
| 60 | |
| 61 | // NOTE temporary workaround expose ONOS node ports |
Andrea Campanella | 9e41a60 | 2021-09-14 14:45:11 +0200 | [diff] [blame] | 62 | def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " + |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 63 | " --set onos-classic.onosSshPort=30115 " + |
| 64 | " --set onos-classic.onosApiPort=30120 " + |
| 65 | " --set onos-classic.onosOfPort=31653 " + |
| 66 | " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags |
| 67 | |
| 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 | ]) |
| 81 | } |
| 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 |
Matteo Scandolo | 9c230bb | 2021-10-22 12:48:39 -0700 | [diff] [blame] | 92 | cd ${logsDir} |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 93 | gzip -k onos-voltha-startup-combined.log |
| 94 | rm onos-voltha-startup-combined.log |
| 95 | """ |
| 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 | """ |
| 108 | } |
| 109 | } |
| 110 | stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') { |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 111 | sh """ |
Hardik Windlass | 476c2f0 | 2021-11-01 06:49:41 +0000 | [diff] [blame] | 112 | mkdir -p ${logsDir} |
| 113 | export ROBOT_MISC_ARGS="-d ${logsDir} " |
| 114 | ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:${logsDir} -v logging:${testLogging}" |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 115 | export KVSTOREPREFIX=voltha/voltha_voltha |
| 116 | |
| 117 | make -C $WORKSPACE/voltha-system-tests ${testTarget} || true |
| 118 | """ |
Hardik Windlass | 476c2f0 | 2021-11-01 06:49:41 +0000 | [diff] [blame] | 119 | getPodsInfo("${logsDir}") |
Hardik Windlass | dad8e5c | 2021-11-11 05:19:47 +0000 | [diff] [blame] | 120 | sh """ |
| 121 | set +e |
| 122 | # collect logs collected in the Robot Framework StartLogging keyword |
| 123 | cd ${logsDir} |
| 124 | gzip *-combined.log || true |
| 125 | rm *-combined.log || true |
| 126 | """ |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | def collectArtifacts(exitStatus) { |
| 131 | getPodsInfo("$WORKSPACE/${exitStatus}") |
| 132 | sh """ |
| 133 | kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true |
| 134 | """ |
| 135 | archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html' |
| 136 | sh ''' |
| 137 | sync |
| 138 | pkill kail || true |
| 139 | which voltctl |
| 140 | md5sum $(which voltctl) |
| 141 | ''' |
| 142 | step([$class: 'RobotPublisher', |
| 143 | disableArchiveOutput: false, |
Hardik Windlass | 476c2f0 | 2021-11-01 06:49:41 +0000 | [diff] [blame] | 144 | logFileName: "**/*/log*.html", |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 145 | otherFiles: '', |
Hardik Windlass | 476c2f0 | 2021-11-01 06:49:41 +0000 | [diff] [blame] | 146 | outputFileName: "**/*/output*.xml", |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 147 | outputPath: '.', |
| 148 | passThreshold: 100, |
Hardik Windlass | 476c2f0 | 2021-11-01 06:49:41 +0000 | [diff] [blame] | 149 | reportFileName: "**/*/report*.html", |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 150 | unstableThreshold: 0, |
| 151 | onlyCritical: true]); |
| 152 | } |
| 153 | |
| 154 | pipeline { |
| 155 | |
| 156 | /* no label, executor is determined by JJB */ |
| 157 | agent { |
| 158 | label "${params.buildNode}" |
| 159 | } |
| 160 | options { |
| 161 | timeout(time: "${timeout}", unit: 'MINUTES') |
| 162 | } |
| 163 | environment { |
| 164 | KUBECONFIG="$HOME/.kube/kind-${clusterName}" |
| 165 | VOLTCONFIG="$HOME/.volt/config" |
| 166 | PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" |
| 167 | ROBOT_MISC_ARGS="-e PowerSwitch ${params.extraRobotArgs}" |
| 168 | DIAGS_PROFILE="VOLTHA_PROFILE" |
| 169 | } |
| 170 | stages { |
| 171 | stage('Download Code') { |
| 172 | steps { |
| 173 | getVolthaCode([ |
| 174 | branch: "${branch}", |
| 175 | gerritProject: "${gerritProject}", |
| 176 | gerritRefspec: "${gerritRefspec}", |
| 177 | volthaSystemTestsChange: "${volthaSystemTestsChange}", |
| 178 | volthaHelmChartsChange: "${volthaHelmChartsChange}", |
| 179 | ]) |
| 180 | } |
| 181 | } |
| 182 | stage('Build patch') { |
| 183 | // build the patch only if gerritProject is specified |
| 184 | when { |
| 185 | expression { |
| 186 | return !gerritProject.isEmpty() |
| 187 | } |
| 188 | } |
| 189 | steps { |
| 190 | // NOTE that the correct patch has already been checked out |
| 191 | // during the getVolthaCode step |
| 192 | buildVolthaComponent("${gerritProject}") |
| 193 | } |
| 194 | } |
| 195 | stage('Create K8s Cluster') { |
| 196 | steps { |
| 197 | script { |
| 198 | def clusterExists = sh returnStdout: true, script: """ |
| 199 | kind get clusters | grep ${clusterName} | wc -l |
| 200 | """ |
| 201 | if (clusterExists.trim() == "0") { |
Hardik Windlass | 6f854a1 | 2021-07-12 13:20:21 +0000 | [diff] [blame] | 202 | createKubernetesCluster([branch: "${branch}", nodes: 3, name: clusterName]) |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | stage('Replace voltctl') { |
| 208 | // if the project is voltctl override the downloaded one with the built one |
| 209 | when { |
| 210 | expression { |
| 211 | return gerritProject == "voltctl" |
| 212 | } |
| 213 | } |
| 214 | steps{ |
| 215 | sh """ |
| 216 | mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl |
| 217 | chmod +x $WORKSPACE/bin/voltctl |
| 218 | """ |
| 219 | } |
| 220 | } |
| 221 | stage('Load image in kind nodes') { |
| 222 | when { |
| 223 | expression { |
| 224 | return !gerritProject.isEmpty() |
| 225 | } |
| 226 | } |
| 227 | steps { |
| 228 | loadToKind() |
| 229 | } |
| 230 | } |
| 231 | stage('Parse and execute tests') { |
| 232 | steps { |
| 233 | script { |
| 234 | def tests = readYaml text: testTargets |
| 235 | |
| 236 | for(int i = 0;i<tests.size();i++) { |
| 237 | def test = tests[i] |
| 238 | def target = test["target"] |
| 239 | def workflow = test["workflow"] |
| 240 | def flags = test["flags"] |
| 241 | def teardown = test["teardown"].toBoolean() |
Hardik Windlass | 24e275f | 2021-10-19 08:19:06 +0000 | [diff] [blame] | 242 | def logging = test["logging"].toBoolean() |
| 243 | def testLogging = 'False' |
| 244 | if (logging) { |
| 245 | testLogging = 'True' |
| 246 | } |
| 247 | println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}" |
| 248 | execute_test(target, workflow, testLogging, teardown, flags) |
Hardik Windlass | 6d9a82e | 2021-07-08 16:23:21 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | post { |
| 255 | aborted { |
| 256 | collectArtifacts("aborted") |
| 257 | } |
| 258 | failure { |
| 259 | collectArtifacts("failed") |
| 260 | } |
| 261 | always { |
| 262 | collectArtifacts("always") |
| 263 | } |
| 264 | } |
| 265 | } |