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