Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ----------------------------------------------------------------------- |
| 17 | |
| 18 | // ----------------------------------------------------------------------- |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 19 | // ----------------------------------------------------------------------- |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 20 | String getIam(String func) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 21 | { |
| 22 | // Cannot rely on a stack trace due to jenkins manipulation |
| 23 | String src = 'vars/volthaStackDeploy.groovy' |
| 24 | String iam = [src, func].join('::') |
| 25 | return iam |
| 26 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 27 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 28 | // ----------------------------------------------------------------------- |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 29 | // Intent: Log progress message |
| 30 | // ----------------------------------------------------------------------- |
| 31 | void enter(String name) { |
| 32 | // Announce ourselves for log usability |
| 33 | String iam = getIam(name) |
| 34 | println("${iam}: ENTER") |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | // ----------------------------------------------------------------------- |
| 39 | // Intent: Log progress message |
| 40 | // ----------------------------------------------------------------------- |
| 41 | void leave(String name) { |
| 42 | // Announce ourselves for log usability |
| 43 | String iam = getIam(name) |
| 44 | println("${iam}: LEAVE") |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | // ----------------------------------------------------------------------- |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 49 | // ----------------------------------------------------------------------- |
| 50 | def process(Map config) |
| 51 | { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 52 | enter('process') |
| 53 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 54 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 55 | def defaultConfig = [ |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 56 | bbsimReplica: 1, |
| 57 | infraNamespace: "infra", |
| 58 | volthaNamespace: "voltha", |
| 59 | stackName: "voltha", |
| 60 | stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks |
| 61 | workflow: "att", |
| 62 | withMacLearning: false, |
| 63 | withFttb: false, |
| 64 | extraHelmFlags: "", |
| 65 | localCharts: false, |
| 66 | onosReplica: 1, |
| 67 | adaptersToWait: 2, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 68 | ] |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 69 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 70 | def cfg = defaultConfig + config |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 71 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 72 | def volthaStackChart = "onf/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 73 | def bbsimChart = "onf/bbsim" |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 74 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 75 | if (cfg.localCharts) { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 76 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
| 77 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 78 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 79 | sh """ |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 80 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 81 | helm dep update |
| 82 | popd |
| 83 | """ |
| 84 | } |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 85 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 86 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 87 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 88 | sh(label : "Create VOLTHA Stack ${cfg.stackName}, (namespace=${cfg.volthaNamespace})", |
| 89 | script : """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 90 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 91 | --set global.stack_name=${cfg.stackName} \ |
| 92 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 93 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 94 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 95 | ${cfg.extraHelmFlags} |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 96 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 97 | |
| 98 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 99 | // NOTE we don't need to update the tag for DT |
| 100 | script { |
| 101 | sh(label : "Create config[$i]: bbsimCfg${cfg.stackId}${i}.yaml", |
| 102 | script : "rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", |
| 103 | ) |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 104 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 105 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 106 | def startingStag = 900 |
| 107 | def serviceConfigFile = cfg.workflow |
| 108 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 109 | serviceConfigFile = "tt-maclearner" |
| 110 | } |
| 111 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml" |
| 112 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 113 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
| 114 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
| 115 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 116 | } else { |
| 117 | // NOTE if it's DT just copy the file over |
| 118 | sh """ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 119 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 120 | """ |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 121 | } |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 122 | } |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 123 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 124 | sh(label : "HELM: Create namespace=${cfg.volthaNamespace} bbsim${i}", |
| 125 | script : """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 126 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 127 | --set olt_id="${cfg.stackId}${i}" \ |
| 128 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 129 | ${cfg.extraHelmFlags} |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 130 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 131 | } |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 132 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 133 | sh(label : "Wait for VOLTHA Stack ${cfg.stackName} to start", |
| 134 | script : """ |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 135 | # set +x # Noisy when uncommented |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 136 | |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 137 | cat << EOM |
| 138 | |
| 139 | ** ----------------------------------------------------------------------- |
| 140 | ** Wait for VOLTHA Stack ${cfg.stackName} to start |
| 141 | ** Display kubectl get pods prior to looping |
| 142 | ** ----------------------------------------------------------------------- |
| 143 | EOM |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 144 | # [joey]: debug |
| 145 | kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers |
| 146 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 147 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 148 | while [[ \$voltha != 0 ]]; do |
| 149 | sleep 5 |
| 150 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 151 | done |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 152 | """) |
| 153 | |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 154 | waitForAdapters(cfg) |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 155 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 156 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 157 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 158 | println "Wait for ONOS Config loader to complete" |
| 159 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 160 | // Wait until the pod completed, meaning ONOS fully deployed |
| 161 | sh(label : '"Wait for ONOS Config loader to fully deploy', |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 162 | script : """#!/bin/bash |
| 163 | |
| 164 | cat <<EOM |
| 165 | |
| 166 | ** ----------------------------------------------------------------------- |
| 167 | ** Wait for ONOS Config loader to fully deploy |
| 168 | ** IAM: vars/volthaStackDeploy.groovy |
| 169 | ** DBG: Polling loop initial kubectl get pods call |
| 170 | ** ----------------------------------------------------------------------- |
| 171 | ** 17:06:07 Cancelling nested steps due to timeout |
| 172 | ** 17:06:07 Sending interrupt signal to process |
| 173 | ** 17:06:09 /w/workspace/verify_voltha-openolt-adapter_sanity-test-voltha-2.12@tmp/durable-18af2649/script.sh: line 7: 29716 Terminated sleep 5 |
| 174 | ** 17:06:09 script returned exit code 143 |
| 175 | ** ----------------------------------------------------------------------- |
| 176 | EOM |
| 177 | |
| 178 | # set -euo pipefail |
Joey Armstrong | c20bd72 | 2023-09-11 15:25:12 -0400 | [diff] [blame^] | 179 | set +x # # Noisy when commented (default: uncommented) |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 180 | |
| 181 | declare -i count=0 |
| 182 | vsd_log='volthaStackDeploy.tmp' |
| 183 | touch \$vsd_log |
| 184 | while true; do |
| 185 | |
| 186 | ## Exit when the server begins showing signs of life |
| 187 | if grep -q '0/' \$vsd_log; then |
| 188 | echo 'volthaStackDeploy.groovy: Detected kubectl pods =~ 0/' |
| 189 | grep '0/' \$vsd_log |
| 190 | break |
| 191 | fi |
| 192 | |
| 193 | sleep 5 |
| 194 | count=\$((\$count - 1)) |
| 195 | |
| 196 | if [[ \$count -lt 1 ]]; then # [DEBUG] Display activity every minute or so |
| 197 | count=10 |
| 198 | kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running \ |
| 199 | | tee \$vsd_log |
| 200 | else |
| 201 | kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running> \$vsd_log |
| 202 | fi |
| 203 | |
| 204 | done |
| 205 | rm -f \$vsd_log |
| 206 | """) |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 207 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 208 | leave('process') |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 209 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 210 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 211 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 212 | |
| 213 | // ----------------------------------------------------------------------- |
| 214 | // ----------------------------------------------------------------------- |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 215 | def call(Map config=[:]) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 216 | { |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 217 | try |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 218 | { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 219 | enter('main') |
| 220 | process(config) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 221 | } |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 222 | catch (Exception err) { // groovylint-disable-line CatchException |
| 223 | ans = false |
| 224 | println("** volthaStackDeploy.groovy: EXCEPTION ${err}") |
| 225 | throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 226 | } |
| 227 | finally |
| 228 | { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 229 | leave('main') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 230 | } |
| 231 | return |
| 232 | } |
| 233 | |
| 234 | // [EOF] |