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 | // ----------------------------------------------------------------------- |
| 29 | // ----------------------------------------------------------------------- |
| 30 | def process(Map config) |
| 31 | { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 32 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 33 | def defaultConfig = [ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 34 | bbsimReplica: 1, |
| 35 | infraNamespace: "infra", |
| 36 | volthaNamespace: "voltha", |
| 37 | stackName: "voltha", |
Matteo Scandolo | 2bc660a | 2021-02-12 10:52:25 -0800 | [diff] [blame] | 38 | stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 39 | workflow: "att", |
Hardik Windlass | 2b16434 | 2022-02-28 03:50:48 +0000 | [diff] [blame] | 40 | withMacLearning: false, |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 41 | withFttb: false, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 42 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 43 | localCharts: false, |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 44 | onosReplica: 1, |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 45 | adaptersToWait: 2, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 46 | ] |
| 47 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 48 | def cfg = defaultConfig + config |
| 49 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 50 | def volthaStackChart = "onf/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 51 | def bbsimChart = "onf/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 52 | |
| 53 | if (cfg.localCharts) { |
| 54 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 55 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 56 | |
| 57 | sh """ |
| 58 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 59 | helm dep update |
| 60 | popd |
| 61 | """ |
| 62 | } |
| 63 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 64 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 65 | |
| 66 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 67 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 68 | --set global.stack_name=${cfg.stackName} \ |
| 69 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 70 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 71 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 72 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 73 | """ |
| 74 | |
| 75 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 76 | // NOTE we don't need to update the tag for DT |
| 77 | script { |
| 78 | sh """ |
| 79 | rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 80 | """ |
| 81 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 82 | def startingStag = 900 |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 83 | def serviceConfigFile = cfg.workflow |
| 84 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 85 | serviceConfigFile = "tt-maclearner" |
| 86 | } |
| 87 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 88 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 89 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
Matteo Scandolo | e765ee3 | 2021-07-20 16:47:19 -0700 | [diff] [blame] | 90 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 91 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 92 | } else { |
| 93 | // NOTE if it's DT just copy the file over |
| 94 | sh """ |
| 95 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 96 | """ |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | sh """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 101 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 102 | --set olt_id="${cfg.stackId}${i}" \ |
| 103 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 104 | ${cfg.extraHelmFlags} |
| 105 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 109 | |
| 110 | sh """ |
| 111 | set +x |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 112 | |
| 113 | # [joey]: debug |
| 114 | kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers |
| 115 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 116 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 117 | while [[ \$voltha != 0 ]]; do |
| 118 | sleep 5 |
| 119 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 120 | done |
| 121 | """ |
| 122 | |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 123 | waitForAdapters(cfg) |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 124 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 125 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 126 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 127 | println "Wait for ONOS Config loader to complete" |
| 128 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 129 | // NOTE that this is only required for VOLTHA-2.8, |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 130 | // [TODO]: Release cleanup |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 131 | sh """ |
| 132 | set +x |
| 133 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 134 | while [[ \$config != 0 ]]; do |
| 135 | sleep 5 |
| 136 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 137 | done |
| 138 | """ |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 139 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 140 | // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed, |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 141 | // meaning ONOS fully deployed |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 142 | sh """ |
| 143 | set +x |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 144 | 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] | 145 | while [[ \$config != 0 ]]; do |
| 146 | sleep 5 |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 147 | 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] | 148 | done |
| 149 | """ |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 150 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 151 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 152 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 153 | |
| 154 | // ----------------------------------------------------------------------- |
| 155 | // ----------------------------------------------------------------------- |
| 156 | def call(Map config) |
| 157 | { |
| 158 | String iam = getIam('main') |
| 159 | println("** ${iam}: ENTER") |
| 160 | |
| 161 | if (!config) { |
| 162 | config = [:] |
| 163 | } |
| 164 | |
| 165 | try |
| 166 | { |
| 167 | process(config) |
| 168 | } |
| 169 | catch (Exception err) |
| 170 | { |
| 171 | println("** ${iam}: EXCEPTION ${err}") |
Joey Armstrong | 8a3c13b | 2022-12-06 09:27:44 -0500 | [diff] [blame] | 172 | // Cannot re-throw ATM: too many potential shell errors. |
| 173 | // throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 174 | } |
| 175 | finally |
| 176 | { |
| 177 | println("** ${iam}: LEAVE") |
| 178 | } |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | // [EOF] |