blob: bea044b888ce67e2965bb8db7021e746a9fd2ed0 [file] [log] [blame]
Matteo Scandolo42f6e572021-01-25 15:11:34 -08001
2def call(Map config) {
3 // note that I can't define this outside the function as there's no global scope in Groovy
4 def defaultConfig = [
Matteo Scandolo42f6e572021-01-25 15:11:34 -08005 bbsimReplica: 1,
6 infraNamespace: "infra",
7 volthaNamespace: "voltha",
8 stackName: "voltha",
Matteo Scandolo2bc660a2021-02-12 10:52:25 -08009 stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks
Matteo Scandolo42f6e572021-01-25 15:11:34 -080010 workflow: "att",
Hardik Windlass2b164342022-02-28 03:50:48 +000011 withMacLearning: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080012 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080013 localCharts: false,
Matteo Scandolo529e8822021-07-21 10:20:18 -070014 onosReplica: 1,
Andrea Campanella365ea1e2021-09-28 10:50:01 +020015 adaptersToWait: 2,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016 ]
17
18 if (!config) {
19 config = [:]
20 }
21
22 def cfg = defaultConfig + config
23
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080024 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020025 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080026
27 if (cfg.localCharts) {
28 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020029 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080030
31 sh """
32 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
33 helm dep update
34 popd
35 """
36 }
37
Matteo Scandolo42f6e572021-01-25 15:11:34 -080038 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
39
40 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070041 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080042 --set global.stack_name=${cfg.stackName} \
43 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070044 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080045 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070046 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080047 """
48
49 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070050 // NOTE we don't need to update the tag for DT
51 script {
52 sh """
53 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
54 """
55 if (cfg.workflow == "att" || cfg.workflow == "tt") {
56 def startingStag = 900
Hardik Windlass810b6cf2022-02-24 09:21:18 +000057 def serviceConfigFile = cfg.workflow
58 if (cfg.withMacLearning && cfg.workflow == 'tt') {
59 serviceConfigFile = "tt-maclearner"
60 }
61 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070062 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
63 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070064 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070065 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
66 } else {
67 // NOTE if it's DT just copy the file over
68 sh """
69 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
70 """
71 }
72 }
73
74 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020075 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070076 --set olt_id="${cfg.stackId}${i}" \
77 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
78 ${cfg.extraHelmFlags}
79 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080080 }
81
82 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
83
84 sh """
85 set +x
86 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
87 while [[ \$voltha != 0 ]]; do
88 sleep 5
89 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
90 done
91 """
92
Andrea Campanella365ea1e2021-09-28 10:50:01 +020093 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -070094
Matteo Scandolo42f6e572021-01-25 15:11:34 -080095 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +020096 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -080097 println "Wait for ONOS Config loader to complete"
98
Andrea Campanella04b393a2021-07-22 10:48:33 +020099 // NOTE that this is only required for VOLTHA-2.8,
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800100 sh """
101 set +x
102 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
103 while [[ \$config != 0 ]]; do
104 sleep 5
105 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
106 done
107 """
Andrea Campanella04b393a2021-07-22 10:48:33 +0200108 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
Matteo Scandolo937f4792021-09-24 11:05:52 -0700109 // meaning ONOS fully deployed
Andrea Campanella04b393a2021-07-22 10:48:33 +0200110 sh """
111 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200112 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 +0200113 while [[ \$config != 0 ]]; do
114 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200115 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 +0200116 done
117 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800118}