blob: c63850b26d01429c74d4ceac95181565d0b9ca7b [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,
Hardik Windlassc97ceae2022-05-13 10:12:55 +053012 withFttb: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080013 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080014 localCharts: false,
Matteo Scandolo529e8822021-07-21 10:20:18 -070015 onosReplica: 1,
Andrea Campanella365ea1e2021-09-28 10:50:01 +020016 adaptersToWait: 2,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080017 ]
18
19 if (!config) {
20 config = [:]
21 }
22
23 def cfg = defaultConfig + config
24
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080025 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020026 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080027
28 if (cfg.localCharts) {
29 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020030 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080031
32 sh """
33 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
34 helm dep update
35 popd
36 """
37 }
38
Matteo Scandolo42f6e572021-01-25 15:11:34 -080039 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
40
41 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070042 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 --set global.stack_name=${cfg.stackName} \
44 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070045 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080046 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070047 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080048 """
49
50 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070051 // NOTE we don't need to update the tag for DT
52 script {
53 sh """
54 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
55 """
56 if (cfg.workflow == "att" || cfg.workflow == "tt") {
57 def startingStag = 900
Hardik Windlass810b6cf2022-02-24 09:21:18 +000058 def serviceConfigFile = cfg.workflow
59 if (cfg.withMacLearning && cfg.workflow == 'tt') {
60 serviceConfigFile = "tt-maclearner"
61 }
62 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070063 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
64 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070065 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070066 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
67 } else {
68 // NOTE if it's DT just copy the file over
69 sh """
70 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
71 """
72 }
73 }
74
75 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020076 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070077 --set olt_id="${cfg.stackId}${i}" \
78 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
79 ${cfg.extraHelmFlags}
80 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080081 }
82
83 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
84
85 sh """
86 set +x
87 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
88 while [[ \$voltha != 0 ]]; do
89 sleep 5
90 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
91 done
92 """
93
Andrea Campanella365ea1e2021-09-28 10:50:01 +020094 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -070095
Matteo Scandolo42f6e572021-01-25 15:11:34 -080096 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +020097 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -080098 println "Wait for ONOS Config loader to complete"
99
Andrea Campanella04b393a2021-07-22 10:48:33 +0200100 // NOTE that this is only required for VOLTHA-2.8,
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800101 sh """
102 set +x
103 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
104 while [[ \$config != 0 ]]; do
105 sleep 5
106 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
107 done
108 """
Andrea Campanella04b393a2021-07-22 10:48:33 +0200109 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
Matteo Scandolo937f4792021-09-24 11:05:52 -0700110 // meaning ONOS fully deployed
Andrea Campanella04b393a2021-07-22 10:48:33 +0200111 sh """
112 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200113 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 +0200114 while [[ \$config != 0 ]]; do
115 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200116 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 +0200117 done
118 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800119}