blob: 9b050a838484886329034907a4c5666202de36a5 [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrong7987c112022-12-05 12:42:43 -05002// -----------------------------------------------------------------------
3// -----------------------------------------------------------------------
4def getIam(String func)
5{
6 // Cannot rely on a stack trace due to jenkins manipulation
7 String src = 'vars/volthaStackDeploy.groovy'
8 String iam = [src, func].join('::')
9 return iam
10}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080011
Joey Armstrong7987c112022-12-05 12:42:43 -050012// -----------------------------------------------------------------------
13// -----------------------------------------------------------------------
14def process(Map config)
15{
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016 // note that I can't define this outside the function as there's no global scope in Groovy
17 def defaultConfig = [
Matteo Scandolo42f6e572021-01-25 15:11:34 -080018 bbsimReplica: 1,
19 infraNamespace: "infra",
20 volthaNamespace: "voltha",
21 stackName: "voltha",
Matteo Scandolo2bc660a2021-02-12 10:52:25 -080022 stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks
Matteo Scandolo42f6e572021-01-25 15:11:34 -080023 workflow: "att",
Hardik Windlass2b164342022-02-28 03:50:48 +000024 withMacLearning: false,
Hardik Windlassc97ceae2022-05-13 10:12:55 +053025 withFttb: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080026 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080027 localCharts: false,
Matteo Scandolo529e8822021-07-21 10:20:18 -070028 onosReplica: 1,
Andrea Campanella365ea1e2021-09-28 10:50:01 +020029 adaptersToWait: 2,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080030 ]
31
Matteo Scandolo42f6e572021-01-25 15:11:34 -080032 def cfg = defaultConfig + config
33
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080034 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020035 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080036
37 if (cfg.localCharts) {
38 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020039 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080040
41 sh """
42 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
43 helm dep update
44 popd
45 """
46 }
47
Matteo Scandolo42f6e572021-01-25 15:11:34 -080048 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
49
50 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070051 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080052 --set global.stack_name=${cfg.stackName} \
53 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070054 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080055 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070056 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080057 """
58
59 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070060 // NOTE we don't need to update the tag for DT
61 script {
62 sh """
63 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
64 """
65 if (cfg.workflow == "att" || cfg.workflow == "tt") {
66 def startingStag = 900
Hardik Windlass810b6cf2022-02-24 09:21:18 +000067 def serviceConfigFile = cfg.workflow
68 if (cfg.withMacLearning && cfg.workflow == 'tt') {
69 serviceConfigFile = "tt-maclearner"
70 }
71 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070072 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
73 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070074 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070075 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
76 } else {
77 // NOTE if it's DT just copy the file over
78 sh """
79 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
80 """
81 }
82 }
83
84 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020085 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070086 --set olt_id="${cfg.stackId}${i}" \
87 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
88 ${cfg.extraHelmFlags}
89 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080090 }
91
92 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
93
94 sh """
95 set +x
Joey Armstrong96158a92022-11-25 10:36:06 -050096
97 # [joey]: debug
98 kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers
99
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800100 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
101 while [[ \$voltha != 0 ]]; do
102 sleep 5
103 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
104 done
105 """
106
Andrea Campanella365ea1e2021-09-28 10:50:01 +0200107 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -0700108
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800109 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +0200110 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800111 println "Wait for ONOS Config loader to complete"
112
Andrea Campanella04b393a2021-07-22 10:48:33 +0200113 // NOTE that this is only required for VOLTHA-2.8,
Joey Armstrong7adbfb02023-01-24 17:02:37 -0500114 // [TODO]: Release cleanup
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800115 sh """
116 set +x
117 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
118 while [[ \$config != 0 ]]; do
119 sleep 5
120 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
121 done
122 """
Joey Armstrong7adbfb02023-01-24 17:02:37 -0500123
Andrea Campanella04b393a2021-07-22 10:48:33 +0200124 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
Matteo Scandolo937f4792021-09-24 11:05:52 -0700125 // meaning ONOS fully deployed
Andrea Campanella04b393a2021-07-22 10:48:33 +0200126 sh """
127 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200128 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 +0200129 while [[ \$config != 0 ]]; do
130 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200131 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 +0200132 done
133 """
Joey Armstrong96158a92022-11-25 10:36:06 -0500134
Joey Armstrong7987c112022-12-05 12:42:43 -0500135 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800136}
Joey Armstrong7987c112022-12-05 12:42:43 -0500137
138// -----------------------------------------------------------------------
139// -----------------------------------------------------------------------
140def call(Map config)
141{
142 String iam = getIam('main')
143 println("** ${iam}: ENTER")
144
145 if (!config) {
146 config = [:]
147 }
148
149 try
150 {
151 process(config)
152 }
153 catch (Exception err)
154 {
155 println("** ${iam}: EXCEPTION ${err}")
Joey Armstrong8a3c13b2022-12-06 09:27:44 -0500156 // Cannot re-throw ATM: too many potential shell errors.
157 // throw err
Joey Armstrong7987c112022-12-05 12:42:43 -0500158 }
159 finally
160 {
161 println("** ${iam}: LEAVE")
162 }
163 return
164}
165
166// [EOF]