blob: fc7bbcd50732b82aca3f1bddf459ce0fd7d3e173 [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrong7987c112022-12-05 12:42:43 -05002// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// 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 Armstrong7987c112022-12-05 12:42:43 -050019// -----------------------------------------------------------------------
20def 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 Scandolo42f6e572021-01-25 15:11:34 -080027
Joey Armstrong7987c112022-12-05 12:42:43 -050028// -----------------------------------------------------------------------
Joey Armstrong74ec08c2023-08-31 11:25:57 -040029// Intent: Log progress message
30// -----------------------------------------------------------------------
31void 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// -----------------------------------------------------------------------
41void leave(String name) {
42 // Announce ourselves for log usability
43 String iam = getIam(name)
44 println("${iam}: LEAVE")
45 return
46}
47
48// -----------------------------------------------------------------------
Joey Armstrong7987c112022-12-05 12:42:43 -050049// -----------------------------------------------------------------------
50def process(Map config)
51{
Joey Armstrong74ec08c2023-08-31 11:25:57 -040052 enter('process')
53
Matteo Scandolo42f6e572021-01-25 15:11:34 -080054 // note that I can't define this outside the function as there's no global scope in Groovy
55 def defaultConfig = [
Joey Armstrong74ec08c2023-08-31 11:25:57 -040056 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 Scandolo42f6e572021-01-25 15:11:34 -080068 ]
Joey Armstrong74ec08c2023-08-31 11:25:57 -040069
Matteo Scandolo42f6e572021-01-25 15:11:34 -080070 def cfg = defaultConfig + config
Joey Armstrong74ec08c2023-08-31 11:25:57 -040071
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080072 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020073 def bbsimChart = "onf/bbsim"
Joey Armstrong74ec08c2023-08-31 11:25:57 -040074
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080075 if (cfg.localCharts) {
Joey Armstrong74ec08c2023-08-31 11:25:57 -040076 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
77 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
78
79 sh """
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080080 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
81 helm dep update
82 popd
83 """
84 }
Joey Armstrong74ec08c2023-08-31 11:25:57 -040085
Matteo Scandolo42f6e572021-01-25 15:11:34 -080086 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
Joey Armstrong74ec08c2023-08-31 11:25:57 -040087
88 sh(label : "Create VOLTHA Stack ${cfg.stackName}, (namespace=${cfg.volthaNamespace})",
89 script : """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070090 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080091 --set global.stack_name=${cfg.stackName} \
92 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070093 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080094 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070095 ${cfg.extraHelmFlags}
Joey Armstrong74ec08c2023-08-31 11:25:57 -040096 """)
Matteo Scandolo42f6e572021-01-25 15:11:34 -080097
98 for(int i = 0;i<cfg.bbsimReplica;i++) {
Joey Armstrong74ec08c2023-08-31 11:25:57 -040099 // 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 Scandolo0ce69f12021-05-04 08:44:53 -0700119 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
120 """
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400121 }
Matteo Scandolo0ce69f12021-05-04 08:44:53 -0700122 }
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400123
124 sh(label : "HELM: Create namespace=${cfg.volthaNamespace} bbsim${i}",
125 script : """
Matteo Scandoloba4b6542021-06-24 12:06:07 +0200126 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -0700127 --set olt_id="${cfg.stackId}${i}" \
128 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
129 ${cfg.extraHelmFlags}
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400130 """)
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800131 }
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400132
133 sh(label : "Wait for VOLTHA Stack ${cfg.stackName} to start",
134 script : """
135# set +x
Joey Armstrong96158a92022-11-25 10:36:06 -0500136
137 # [joey]: debug
138 kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers
139
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800140 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 Armstrong74ec08c2023-08-31 11:25:57 -0400145 """)
146
Andrea Campanella365ea1e2021-09-28 10:50:01 +0200147 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -0700148
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800149 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +0200150 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800151 println "Wait for ONOS Config loader to complete"
152
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400153 // 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 Campanella11832512021-07-23 10:53:19 +0200157 config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l)
Andrea Campanella04b393a2021-07-22 10:48:33 +0200158 while [[ \$config != 0 ]]; do
159 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200160 config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l)
Andrea Campanella04b393a2021-07-22 10:48:33 +0200161 done
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400162 """)
Joey Armstrong96158a92022-11-25 10:36:06 -0500163
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400164 leave('process')
165
Joey Armstrong7987c112022-12-05 12:42:43 -0500166 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800167}
Joey Armstrong7987c112022-12-05 12:42:43 -0500168
169// -----------------------------------------------------------------------
170// -----------------------------------------------------------------------
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400171def call(Map config=[:])
Joey Armstrong7987c112022-12-05 12:42:43 -0500172{
Joey Armstrong7987c112022-12-05 12:42:43 -0500173 try
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400174 {
175 enter('main')
176 process(config)
Joey Armstrong7987c112022-12-05 12:42:43 -0500177 }
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400178 catch (Exception err) { // groovylint-disable-line CatchException
179 ans = false
180 println("** volthaStackDeploy.groovy: EXCEPTION ${err}")
181 throw err
Joey Armstrong7987c112022-12-05 12:42:43 -0500182 }
183 finally
184 {
Joey Armstrong74ec08c2023-08-31 11:25:57 -0400185 leave('main')
186 println("** ${iam}: LEAVE")
Joey Armstrong7987c112022-12-05 12:42:43 -0500187 }
188 return
189}
190
191// [EOF]