blob: 9979cd928649cb253d4e5e554aef6cad62401cfd [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",
11 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080012 localCharts: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080013 ]
14
15 if (!config) {
16 config = [:]
17 }
18
19 def cfg = defaultConfig + config
20
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080021 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020022 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080023
24 if (cfg.localCharts) {
25 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020026 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080027
28 sh """
29 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
30 helm dep update
31 popd
32 """
33 }
34
Matteo Scandolo42f6e572021-01-25 15:11:34 -080035 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
36
37 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070038 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080039 --set global.stack_name=${cfg.stackName} \
40 --set global.voltha_infra_name=voltha-infra \
41 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070042 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 """
44
45 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070046 // NOTE we don't need to update the tag for DT
47 script {
48 sh """
49 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
50 """
51 if (cfg.workflow == "att" || cfg.workflow == "tt") {
52 def startingStag = 900
53 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml"
54 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
55 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloa6112932021-07-13 14:25:41 -070056 // remove the ONOS config that is defined in the values file
57 // it's not relevant for BBSim (it won't break anything, but it will clustter the console output)
58 bbsimCfg.remove('onos')
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070059 println "Using BBSim Service config ${bbsimCfg}"
60 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
61 } else {
62 // NOTE if it's DT just copy the file over
63 sh """
64 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
65 """
66 }
67 }
68
69 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020070 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070071 --set olt_id="${cfg.stackId}${i}" \
72 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
73 ${cfg.extraHelmFlags}
74 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080075 }
76
77 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
78
79 sh """
80 set +x
81 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
82 while [[ \$voltha != 0 ]]; do
83 sleep 5
84 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
85 done
86 """
87
88 // also make sure that the ONOS config is loaded
89 println "Wait for ONOS Config loader to complete"
90
91 sh """
92 set +x
93 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
94 while [[ \$config != 0 ]]; do
95 sleep 5
96 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
97 done
98 """
99}