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 | // ----------------------------------------------------------------------- |
| 20 | def getIam(String func) |
| 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 | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 69 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 70 | def cfg = defaultConfig + config |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -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 | 74ec08c | 2023-08-31 11:25:57 -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" |
| 78 | |
| 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 | 74ec08c | 2023-08-31 11:25:57 -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 | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 87 | |
| 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 | ) |
| 104 | |
| 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 | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 123 | |
| 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 | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 132 | |
| 133 | sh(label : "Wait for VOLTHA Stack ${cfg.stackName} to start", |
| 134 | script : """ |
| 135 | # set +x |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 136 | |
| 137 | # [joey]: debug |
| 138 | kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers |
| 139 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 140 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 141 | while [[ \$voltha != 0 ]]; do |
| 142 | sleep 5 |
| 143 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 144 | done |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 145 | """) |
| 146 | |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 147 | waitForAdapters(cfg) |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 148 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 149 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 150 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 151 | println "Wait for ONOS Config loader to complete" |
| 152 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 153 | // Wait until the pod completed, meaning ONOS fully deployed |
| 154 | sh(label : '"Wait for ONOS Config loader to fully deploy', |
| 155 | script : """ |
| 156 | # set +x |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 157 | config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l) |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 158 | while [[ \$config != 0 ]]; do |
| 159 | sleep 5 |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 160 | config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l) |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 161 | done |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 162 | """) |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 163 | |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 164 | leave('process') |
| 165 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 166 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 167 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 168 | |
| 169 | // ----------------------------------------------------------------------- |
| 170 | // ----------------------------------------------------------------------- |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 171 | def call(Map config=[:]) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 172 | { |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 173 | try |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 174 | { |
| 175 | enter('main') |
| 176 | process(config) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 177 | } |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 178 | catch (Exception err) { // groovylint-disable-line CatchException |
| 179 | ans = false |
| 180 | println("** volthaStackDeploy.groovy: EXCEPTION ${err}") |
| 181 | throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 182 | } |
| 183 | finally |
| 184 | { |
Joey Armstrong | 74ec08c | 2023-08-31 11:25:57 -0400 | [diff] [blame] | 185 | leave('main') |
| 186 | println("** ${iam}: LEAVE") |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 187 | } |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | // [EOF] |