blob: ae8533c780331d31b9f32669bbb57c68eb1419b8 [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 Scandolo529e8822021-07-21 10:20:18 -070013 onosReplica: 1,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080014 ]
15
16 if (!config) {
17 config = [:]
18 }
19
20 def cfg = defaultConfig + config
21
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080022 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020023 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080024
25 if (cfg.localCharts) {
26 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020027 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080028
29 sh """
30 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
31 helm dep update
32 popd
33 """
34 }
35
Matteo Scandolo42f6e572021-01-25 15:11:34 -080036 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
37
38 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070039 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080040 --set global.stack_name=${cfg.stackName} \
41 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070042 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080043 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070044 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080045 """
46
47 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070048 // NOTE we don't need to update the tag for DT
49 script {
50 sh """
51 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
52 """
53 if (cfg.workflow == "att" || cfg.workflow == "tt") {
54 def startingStag = 900
55 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml"
56 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
57 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070058 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070059 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
60 } else {
61 // NOTE if it's DT just copy the file over
62 sh """
63 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
64 """
65 }
66 }
67
68 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020069 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070070 --set olt_id="${cfg.stackId}${i}" \
71 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
72 ${cfg.extraHelmFlags}
73 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080074 }
75
76 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
77
78 sh """
79 set +x
80 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
81 while [[ \$voltha != 0 ]]; do
82 sleep 5
83 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
84 done
85 """
86
87 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +020088 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -080089 println "Wait for ONOS Config loader to complete"
90
Andrea Campanella04b393a2021-07-22 10:48:33 +020091 // NOTE that this is only required for VOLTHA-2.8,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080092 sh """
93 set +x
94 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
95 while [[ \$config != 0 ]]; do
96 sleep 5
97 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
98 done
99 """
Andrea Campanella04b393a2021-07-22 10:48:33 +0200100 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
101 //meaning ONOS fully deployed
102 sh """
103 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200104 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 +0200105 while [[ \$config != 0 ]]; do
106 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200107 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 +0200108 done
109 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800110}