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 | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 20 | String getIam(String func) { |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 21 | // Cannot rely on a stack trace due to jenkins manipulation |
| 22 | String src = 'vars/volthaStackDeploy.groovy' |
| 23 | String iam = [src, func].join('::') |
| 24 | return iam |
| 25 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 26 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 27 | // ----------------------------------------------------------------------- |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 28 | // Intent: Log progress message |
| 29 | // ----------------------------------------------------------------------- |
| 30 | void enter(String name) { |
| 31 | // Announce ourselves for log usability |
| 32 | String iam = getIam(name) |
| 33 | println("${iam}: ENTER") |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | // ----------------------------------------------------------------------- |
| 38 | // Intent: Log progress message |
| 39 | // ----------------------------------------------------------------------- |
| 40 | void leave(String name) { |
| 41 | // Announce ourselves for log usability |
| 42 | String iam = getIam(name) |
| 43 | println("${iam}: LEAVE") |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | // ----------------------------------------------------------------------- |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 48 | // Intent: |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 49 | // ----------------------------------------------------------------------- |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 50 | void deployVolthaStack(Map cfg) { |
| 51 | enter('deployVolthaStack') |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 52 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 53 | sh(label : "Create VOLTHA Stack ${cfg.stackName}, (namespace=${cfg.volthaNamespace})", |
| 54 | script : """ |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 55 | |
| 56 | helm upgrade --install --create-namespace \ |
| 57 | -n ${cfg.volthaNamespace} ${cfg.stackName} ${cfg.volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 58 | --set global.stack_name=${cfg.stackName} \ |
| 59 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 60 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 61 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 62 | ${cfg.extraHelmFlags} |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 63 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 64 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 65 | for (int i = 0; i < cfg.bbsimReplica; i++) { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 66 | // NOTE we don't need to update the tag for DT |
| 67 | script { |
| 68 | sh(label : "Create config[$i]: bbsimCfg${cfg.stackId}${i}.yaml", |
| 69 | script : "rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", |
| 70 | ) |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 71 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 72 | if (c1fg.workflow == 'att' || cfg.workflow == 'tt') { |
| 73 | int startingStag = 900 |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 74 | def serviceConfigFile = cfg.workflow |
| 75 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 76 | serviceConfigFile = 'tt-maclearner' |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 77 | } |
| 78 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml" |
| 79 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 80 | bbsimCfg['servicesConfig']['services'][0]['s_tag'] = startingStag + i |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 81 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
| 82 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 83 | } else { |
| 84 | // NOTE if it's DT just copy the file over |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 85 | sh(label : 'DT install', |
| 86 | script : """ |
| 87 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml \ |
| 88 | $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 89 | """) |
| 90 | } // if (cfg) |
| 91 | } // script |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 92 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 93 | sh(label : "HELM: Create namespace=${cfg.volthaNamespace} bbsim${i}", |
| 94 | script : """ |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 95 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${cfg.bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 96 | --set olt_id="${cfg.stackId}${i}" \ |
| 97 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 98 | ${cfg.extraHelmFlags} |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 99 | """) |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 100 | } // for |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 101 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 102 | leave('deployVolthaStack') |
| 103 | return |
| 104 | } |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 105 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 106 | // ----------------------------------------------------------------------- |
| 107 | // Intent: Wait until the pod completed, meaning ONOS fully deployed |
| 108 | // ----------------------------------------------------------------------- |
| 109 | void launchVolthaStack(Map cfg) { |
| 110 | enter('launchVolthaStack') |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 111 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 112 | sh(label : "Wait for VOLTHA Stack ${cfg.stackName}::${cfg.volthaNamespace} to start", |
| 113 | script : """ |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 114 | |
| 115 | cat <<EOM |
| 116 | |
| 117 | ** ----------------------------------------------------------------------- |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 118 | ** Wait for VOLTHA Stack ${cfg.stackName}::${cfg.volthaNamespace} to start |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 119 | ** ----------------------------------------------------------------------- |
| 120 | EOM |
| 121 | |
| 122 | # set -euo pipefail |
Joey Armstrong | c20bd72 | 2023-09-11 15:25:12 -0400 | [diff] [blame] | 123 | set +x # # Noisy when commented (default: uncommented) |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 124 | |
| 125 | declare -i count=0 |
| 126 | vsd_log='volthaStackDeploy.tmp' |
| 127 | touch \$vsd_log |
| 128 | while true; do |
| 129 | |
| 130 | ## Exit when the server begins showing signs of life |
| 131 | if grep -q '0/' \$vsd_log; then |
| 132 | echo 'volthaStackDeploy.groovy: Detected kubectl pods =~ 0/' |
| 133 | grep '0/' \$vsd_log |
| 134 | break |
| 135 | fi |
| 136 | |
| 137 | sleep 5 |
| 138 | count=\$((\$count - 1)) |
| 139 | |
| 140 | if [[ \$count -lt 1 ]]; then # [DEBUG] Display activity every minute or so |
| 141 | count=10 |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 142 | kubectl get pods -n ${cfg.volthaNamespace} \ |
| 143 | -l app.kubernetes.io/part-of=voltha --no-headers \ |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 144 | | tee \$vsd_log |
| 145 | else |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 146 | kubectl get pods -n ${cfg.volthaNamespace} \ |
| 147 | -l app.kubernetes.io/part-of=voltha --no-headers \ |
| 148 | > \$vsd_log |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 149 | fi |
| 150 | |
| 151 | done |
| 152 | rm -f \$vsd_log |
| 153 | """) |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 154 | |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 155 | leave('launchVolthaStack') |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | // ----------------------------------------------------------------------- |
| 160 | // ----------------------------------------------------------------------- |
| 161 | def process(Map config) { |
| 162 | enter('process') |
| 163 | |
| 164 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 165 | Map defaultConfig = [ |
| 166 | bbsimReplica: 1, |
| 167 | infraNamespace: 'infra', |
| 168 | volthaNamespace: 'voltha', |
| 169 | stackName: 'voltha', |
| 170 | stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks |
| 171 | workflow: 'att', |
| 172 | withMacLearning: false, |
| 173 | withFttb: false, |
| 174 | extraHelmFlags: '', |
| 175 | localCharts: false, |
| 176 | onosReplica: 1, |
| 177 | adaptersToWait: 2, |
| 178 | ] |
| 179 | |
| 180 | Map cfg = defaultConfig + config |
| 181 | |
| 182 | // Augment config map |
| 183 | cfg.volthaStackChart = 'onf/voltha-stack' |
| 184 | cfg.bbsimChart = 'onf/bbsim' |
| 185 | |
| 186 | if (cfg.localCharts) { |
| 187 | cfg.volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
| 188 | cfg.bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
| 189 | |
| 190 | sh(label : 'HELM: Update voltha-stack deps', |
| 191 | script : """ |
| 192 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 193 | helm dep update |
| 194 | popd |
| 195 | """) |
| 196 | } |
| 197 | |
| 198 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 199 | deployVolthaStack(cfg) |
| 200 | launchVolthaStack(cfg) |
| 201 | waitForAdapters(cfg) |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 202 | leave('process') |
Joey Armstrong | e93c3fa | 2023-09-11 09:34:24 -0400 | [diff] [blame] | 203 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 204 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 205 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 206 | |
| 207 | // ----------------------------------------------------------------------- |
| 208 | // ----------------------------------------------------------------------- |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 209 | def call(Map config=[:]) { |
| 210 | try { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 211 | enter('main') |
| 212 | process(config) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 213 | } |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 214 | catch (Exception err) { // groovylint-disable-line CatchException |
| 215 | ans = false |
| 216 | println("** volthaStackDeploy.groovy: EXCEPTION ${err}") |
| 217 | throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 218 | } |
Joey Armstrong | cd3f075 | 2023-09-11 18:10:12 -0400 | [diff] [blame^] | 219 | finally { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 220 | leave('main') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 221 | } |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | // [EOF] |